From f1f869acf72df2ed5afe0973d3c443cda56116ec Mon Sep 17 00:00:00 2001 From: Alex Sanchez-Stern Date: Thu, 3 Oct 2024 13:01:59 -0700 Subject: [PATCH] Hooks to allow serving non-text selections --- include/GLFW/glfw3native.h | 7 +++++++ src/x11_init.c | 2 ++ src/x11_platform.h | 2 ++ src/x11_window.c | 12 +++++++++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/GLFW/glfw3native.h b/include/GLFW/glfw3native.h index 011b239c..d4daa1f5 100644 --- a/include/GLFW/glfw3native.h +++ b/include/GLFW/glfw3native.h @@ -442,6 +442,13 @@ GLFWAPI void glfwSetX11SelectionString(const char* string); * @ingroup native */ GLFWAPI const char* glfwGetX11SelectionString(void); + +#include +extern void (*handleSelectionRequest)(XEvent*); +void (*getSelectionRequestHandler(void))(XEvent*); +void setSelectionRequestHandler(void (*handler)(XEvent*)); +Display* getGLFWDisplay(void); + #endif #if defined(GLFW_EXPOSE_NATIVE_GLX) diff --git a/src/x11_init.c b/src/x11_init.c index 982c526c..33b827af 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -1314,6 +1314,8 @@ GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform) _glfw.x11.xlib.handle = module; *platform = x11; + + handleSelectionRequest = handleSelectionRequest_; return GLFW_TRUE; } diff --git a/src/x11_platform.h b/src/x11_platform.h index 30326c5b..63fb893c 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -896,6 +896,8 @@ typedef struct _GLFWcursorX11 Cursor handle; } _GLFWcursorX11; +extern void (*handleSelectionRequest)(XEvent*); +void handleSelectionRequest_(XEvent* event); GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform); int _glfwInitX11(void); diff --git a/src/x11_window.c b/src/x11_window.c index 322349f0..787004d1 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -921,7 +921,8 @@ static Atom writeTargetToProperty(const XSelectionRequestEvent* request) return None; } -static void handleSelectionRequest(XEvent* event) +void (*handleSelectionRequest)(XEvent*); +void handleSelectionRequest_(XEvent* event) { const XSelectionRequestEvent* request = &event->xselectionrequest; @@ -3356,6 +3357,15 @@ GLFWAPI const char* glfwGetX11SelectionString(void) return getSelectionString(_glfw.x11.PRIMARY); } +void (*getSelectionRequestHandler(void))(XEvent*) { + return handleSelectionRequest; +} +void setSelectionRequestHandler(void (*handler)(XEvent*)) { + handleSelectionRequest = handler; +} +Display* getGLFWDisplay(void) { + return _glfw.x11.display; +} #endif // _GLFW_X11