Wayland: Implemented glfwRequestWindowAttention via xdg-activation-v1 protocol

This commit is contained in:
GamesTrap 2023-03-01 19:56:11 +01:00
parent 8f470597d6
commit abc1db8505
No known key found for this signature in database
GPG Key ID: 31DFD452434ECDA3
6 changed files with 60 additions and 3 deletions

View File

@ -202,6 +202,7 @@ video tutorials.
- Riku Salminen - Riku Salminen
- Brandon Schaefer - Brandon Schaefer
- Sebastian Schuberth - Sebastian Schuberth
- Jan Schuerkamp
- Christian Sdunek - Christian Sdunek
- Matt Sealey - Matt Sealey
- Steve Sexton - Steve Sexton

View File

@ -141,6 +141,12 @@ This protocol is part of wayland-protocols 1.4, and mandatory at build time.
If the running compositor does not support this protocol either, no decorations If the running compositor does not support this protocol either, no decorations
will be drawn around windows. will be drawn around windows.
GLFW uses the [xdg-activation
protocol](https://cgit.freedesktop.org/wayland/wayland-protocols/tree/staging/xdg-activation/xdg-activation-v1.xml)
to enable attention requests. This protocol is part of
wayland-protocols staging, and mandatory at build time. If the running compositor
does not support this protocol, the attention requests do nothing.
@section compat_glx GLX extensions @section compat_glx GLX extensions

View File

@ -113,6 +113,9 @@ if (GLFW_BUILD_WAYLAND)
wayland_generate( wayland_generate(
"${WAYLAND_PROTOCOLS_BASE}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml" "${WAYLAND_PROTOCOLS_BASE}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml"
"${GLFW_BINARY_DIR}/src/wayland-idle-inhibit-unstable-v1-client-protocol") "${GLFW_BINARY_DIR}/src/wayland-idle-inhibit-unstable-v1-client-protocol")
wayland_generate(
"${WAYLAND_PROTOCOLS_BASE}/staging/xdg-activation/xdg-activation-v1.xml"
"${GLFW_BINARY_DIR}/src/wayland-xdg-activation-v1-client-protocol")
endif() endif()
if (WIN32 AND GLFW_BUILD_SHARED_LIBRARY) if (WIN32 AND GLFW_BUILD_SHARED_LIBRARY)

View File

@ -48,6 +48,7 @@
#include "wayland-relative-pointer-unstable-v1-client-protocol.h" #include "wayland-relative-pointer-unstable-v1-client-protocol.h"
#include "wayland-pointer-constraints-unstable-v1-client-protocol.h" #include "wayland-pointer-constraints-unstable-v1-client-protocol.h"
#include "wayland-idle-inhibit-unstable-v1-client-protocol.h" #include "wayland-idle-inhibit-unstable-v1-client-protocol.h"
#include "wayland-xdg-activation-v1-client-protocol.h"
// NOTE: Versions of wayland-scanner prior to 1.17.91 named every global array of // NOTE: Versions of wayland-scanner prior to 1.17.91 named every global array of
// wl_interface pointers 'types', making it impossible to combine several unmodified // wl_interface pointers 'types', making it impossible to combine several unmodified
@ -82,6 +83,10 @@
#include "wayland-idle-inhibit-unstable-v1-client-protocol-code.h" #include "wayland-idle-inhibit-unstable-v1-client-protocol-code.h"
#undef types #undef types
#define types _glfw_xdg_activation_types
#include "wayland-xdg-activation-v1-client-protocol-code.h"
#undef types
static void wmBaseHandlePing(void* userData, static void wmBaseHandlePing(void* userData,
struct xdg_wm_base* wmBase, struct xdg_wm_base* wmBase,
uint32_t serial) uint32_t serial)
@ -180,6 +185,13 @@ static void registryHandleGlobal(void* userData,
&zwp_idle_inhibit_manager_v1_interface, &zwp_idle_inhibit_manager_v1_interface,
1); 1);
} }
else if (strcmp(interface, "xdg_activation_v1") == 0)
{
_glfw.wl.activationManager =
wl_registry_bind(registry, name,
&xdg_activation_v1_interface,
1);
}
} }
static void registryHandleGlobalRemove(void* userData, static void registryHandleGlobalRemove(void* userData,
@ -777,6 +789,8 @@ void _glfwTerminateWayland(void)
zwp_pointer_constraints_v1_destroy(_glfw.wl.pointerConstraints); zwp_pointer_constraints_v1_destroy(_glfw.wl.pointerConstraints);
if (_glfw.wl.idleInhibitManager) if (_glfw.wl.idleInhibitManager)
zwp_idle_inhibit_manager_v1_destroy(_glfw.wl.idleInhibitManager); zwp_idle_inhibit_manager_v1_destroy(_glfw.wl.idleInhibitManager);
if (_glfw.wl.activationManager)
xdg_activation_v1_destroy(_glfw.wl.activationManager);
if (_glfw.wl.registry) if (_glfw.wl.registry)
wl_registry_destroy(_glfw.wl.registry); wl_registry_destroy(_glfw.wl.registry);
if (_glfw.wl.display) if (_glfw.wl.display)

View File

@ -272,6 +272,7 @@ typedef struct _GLFWwindowWayland
struct zwp_confined_pointer_v1* confinedPointer; struct zwp_confined_pointer_v1* confinedPointer;
struct zwp_idle_inhibitor_v1* idleInhibitor; struct zwp_idle_inhibitor_v1* idleInhibitor;
struct xdg_activation_token_v1* activationToken;
struct { struct {
struct wl_buffer* buffer; struct wl_buffer* buffer;
@ -300,6 +301,7 @@ typedef struct _GLFWlibraryWayland
struct zwp_relative_pointer_manager_v1* relativePointerManager; struct zwp_relative_pointer_manager_v1* relativePointerManager;
struct zwp_pointer_constraints_v1* pointerConstraints; struct zwp_pointer_constraints_v1* pointerConstraints;
struct zwp_idle_inhibit_manager_v1* idleInhibitManager; struct zwp_idle_inhibit_manager_v1* idleInhibitManager;
struct xdg_activation_v1* activationManager;
_GLFWofferWayland* offers; _GLFWofferWayland* offers;
unsigned int offerCount; unsigned int offerCount;

View File

@ -50,6 +50,7 @@
#include "wayland-relative-pointer-unstable-v1-client-protocol.h" #include "wayland-relative-pointer-unstable-v1-client-protocol.h"
#include "wayland-pointer-constraints-unstable-v1-client-protocol.h" #include "wayland-pointer-constraints-unstable-v1-client-protocol.h"
#include "wayland-idle-inhibit-unstable-v1-client-protocol.h" #include "wayland-idle-inhibit-unstable-v1-client-protocol.h"
#include "wayland-xdg-activation-v1-client-protocol.h"
#define GLFW_BORDER_SIZE 4 #define GLFW_BORDER_SIZE 4
#define GLFW_CAPTION_HEIGHT 24 #define GLFW_CAPTION_HEIGHT 24
@ -1854,6 +1855,9 @@ void _glfwDestroyWindowWayland(_GLFWwindow* window)
if (window == _glfw.wl.keyboardFocus) if (window == _glfw.wl.keyboardFocus)
_glfw.wl.keyboardFocus = NULL; _glfw.wl.keyboardFocus = NULL;
if (window->wl.activationToken)
xdg_activation_token_v1_destroy(window->wl.activationToken);
if (window->wl.idleInhibitor) if (window->wl.idleInhibitor)
zwp_idle_inhibitor_v1_destroy(window->wl.idleInhibitor); zwp_idle_inhibitor_v1_destroy(window->wl.idleInhibitor);
@ -2085,11 +2089,38 @@ void _glfwHideWindowWayland(_GLFWwindow* window)
} }
} }
static void xdgActivationHandleDone(void* userData,
struct xdg_activation_token_v1* activationToken,
const char* token)
{
_GLFWwindow* window = userData;
if(activationToken != window->wl.activationToken)
return;
xdg_activation_v1_activate(_glfw.wl.activationManager, token, window->wl.surface);
xdg_activation_token_v1_destroy(window->wl.activationToken);
window->wl.activationToken = NULL;
}
static const struct xdg_activation_token_v1_listener xdgActivationListener =
{
xdgActivationHandleDone
};
void _glfwRequestWindowAttentionWayland(_GLFWwindow* window) void _glfwRequestWindowAttentionWayland(_GLFWwindow* window)
{ {
// TODO if(!_glfw.wl.activationManager)
_glfwInputError(GLFW_FEATURE_UNIMPLEMENTED, return;
"Wayland: Window attention request not implemented yet");
//We're about to overwrite this with a new request
if(window->wl.activationToken)
xdg_activation_token_v1_destroy(window->wl.activationToken);
window->wl.activationToken = xdg_activation_v1_get_activation_token(_glfw.wl.activationManager);
xdg_activation_token_v1_add_listener(window->wl.activationToken, &xdgActivationListener, window);
xdg_activation_token_v1_commit(window->wl.activationToken);
} }
void _glfwFocusWindowWayland(_GLFWwindow* window) void _glfwFocusWindowWayland(_GLFWwindow* window)