Wayland: Implement glfwRequestWindowAttention

This implements window attention requests via the xdg-activation-v1
protocol.

This was updated by @ elmindreda to work with recent Wayland related
 changes to the main branch:
 - Switched to current way of handling Wayland protocol files
 - Added the xdg-activation-v1.xml protocol file to deps/wayland
 - Added missing macros to rename protocol interface globals

The protocol file was copied from wayland-protocols 1.33.

Closes #2287
This commit is contained in:
Jan Schürkamp
2024-01-24 21:34:47 +01:00
committed by Camilla Löwy
parent 2590d4cdd4
commit 9317970243
8 changed files with 261 additions and 3 deletions
+1
View File
@@ -101,6 +101,7 @@ if (GLFW_BUILD_WAYLAND)
generate_wayland_protocol("idle-inhibit-unstable-v1.xml")
generate_wayland_protocol("pointer-constraints-unstable-v1.xml")
generate_wayland_protocol("relative-pointer-unstable-v1.xml")
generate_wayland_protocol("xdg-activation-v1.xml")
generate_wayland_protocol("xdg-decoration-unstable-v1.xml")
endif()
+14
View File
@@ -46,6 +46,7 @@
#include "viewporter-client-protocol.h"
#include "relative-pointer-unstable-v1-client-protocol.h"
#include "pointer-constraints-unstable-v1-client-protocol.h"
#include "xdg-activation-v1-client-protocol.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
// NOTE: Versions of wayland-scanner prior to 1.17.91 named every global array of
@@ -77,6 +78,10 @@
#include "pointer-constraints-unstable-v1-client-protocol-code.h"
#undef types
#define types _glfw_xdg_activation_types
#include "xdg-activation-v1-client-protocol-code.h"
#undef types
#define types _glfw_idle_inhibit_types
#include "idle-inhibit-unstable-v1-client-protocol-code.h"
#undef types
@@ -177,6 +182,13 @@ static void registryHandleGlobal(void* userData,
&zwp_idle_inhibit_manager_v1_interface,
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,
@@ -929,6 +941,8 @@ void _glfwTerminateWayland(void)
zwp_pointer_constraints_v1_destroy(_glfw.wl.pointerConstraints);
if (_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)
wl_registry_destroy(_glfw.wl.registry);
if (_glfw.wl.display)
+4
View File
@@ -129,6 +129,8 @@ struct wl_output;
#define xdg_surface_interface _glfw_xdg_surface_interface
#define xdg_toplevel_interface _glfw_xdg_toplevel_interface
#define xdg_wm_base_interface _glfw_xdg_wm_base_interface
#define xdg_activation_v1_interface _glfw_xdg_activation_v1_interface
#define xdg_activation_token_v1_interface _glfw_xdg_activation_token_v1_interface
#define GLFW_WAYLAND_WINDOW_STATE _GLFWwindowWayland wl;
#define GLFW_WAYLAND_LIBRARY_WINDOW_STATE _GLFWlibraryWayland wl;
@@ -406,6 +408,7 @@ typedef struct _GLFWwindowWayland
struct zwp_confined_pointer_v1* confinedPointer;
struct zwp_idle_inhibitor_v1* idleInhibitor;
struct xdg_activation_token_v1* activationToken;
struct {
struct wl_buffer* buffer;
@@ -434,6 +437,7 @@ typedef struct _GLFWlibraryWayland
struct zwp_relative_pointer_manager_v1* relativePointerManager;
struct zwp_pointer_constraints_v1* pointerConstraints;
struct zwp_idle_inhibit_manager_v1* idleInhibitManager;
struct xdg_activation_v1* activationManager;
_GLFWofferWayland* offers;
unsigned int offerCount;
+34 -3
View File
@@ -48,6 +48,7 @@
#include "viewporter-client-protocol.h"
#include "relative-pointer-unstable-v1-client-protocol.h"
#include "pointer-constraints-unstable-v1-client-protocol.h"
#include "xdg-activation-v1-client-protocol.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#define GLFW_BORDER_SIZE 4
@@ -2054,6 +2055,9 @@ void _glfwDestroyWindowWayland(_GLFWwindow* window)
if (window == _glfw.wl.keyboardFocus)
_glfw.wl.keyboardFocus = NULL;
if (window->wl.activationToken)
xdg_activation_token_v1_destroy(window->wl.activationToken);
if (window->wl.idleInhibitor)
zwp_idle_inhibitor_v1_destroy(window->wl.idleInhibitor);
@@ -2335,11 +2339,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)
{
// TODO
_glfwInputError(GLFW_FEATURE_UNIMPLEMENTED,
"Wayland: Window attention request not implemented yet");
if(!_glfw.wl.activationManager)
return;
//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)