Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X11: Use XFixes to detect clipboard updates #7951

Merged
merged 1 commit into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/video/x11/SDL_x11events.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,27 @@ static void X11_DispatchEvent(_THIS, XEvent *xevent)
xevent->type, xevent->xany.display, xevent->xany.window);
#endif

#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
if (SDL_X11_HAVE_XFIXES &&
xevent->type == X11_GetXFixesSelectionNotifyEvent()) {
XFixesSelectionNotifyEvent *ev = (XFixesSelectionNotifyEvent *) xevent;

/* !!! FIXME: cache atoms */
Atom XA_CLIPBOARD = X11_XInternAtom(display, "CLIPBOARD", 0);

#ifdef DEBUG_XEVENTS
printf("window CLIPBOARD: XFixesSelectionNotify (selection = %s)\n",
X11_XGetAtomName(display, ev->selection));
#endif

if (ev->selection == XA_PRIMARY ||
(XA_CLIPBOARD != None && ev->selection == XA_CLIPBOARD)) {
SDL_SendClipboardUpdate();
return;
}
}
#endif /* SDL_VIDEO_DRIVER_X11_XFIXES */

if ((videodata->clipboard_window != None) &&
(videodata->clipboard_window == xevent->xany.window)) {
X11_HandleClipboardEvent(_this, xevent);
Expand Down
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11sym.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ SDL_X11_SYM(PointerBarrier, XFixesCreatePointerBarrier, (Display* a, Window b, i
SDL_X11_SYM(void, XFixesDestroyPointerBarrier, (Display* a, PointerBarrier b), (a,b),)
SDL_X11_SYM(int, XIBarrierReleasePointer,(Display* a, int b, PointerBarrier c, BarrierEventID d), (a,b,c,d), return) /* this is actually Xinput2 */
SDL_X11_SYM(Status, XFixesQueryVersion,(Display* a, int* b, int* c), (a,b,c), return)
SDL_X11_SYM(Status, XFixesSelectSelectionInput, (Display* a, Window b, Atom c, unsigned long d), (a,b,c,d), return)
#endif

#if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
Expand Down
15 changes: 15 additions & 0 deletions src/video/x11/SDL_x11xfixes.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "../../events/SDL_touch_c.h"

static int xfixes_initialized = 0;
static int xfixes_selection_notify_event = 0;

static int query_xfixes_version(Display *display, int major, int minor)
{
Expand All @@ -50,11 +51,20 @@ void X11_InitXfixes(_THIS)
int event, error;
int fixes_opcode;

Atom XA_CLIPBOARD = X11_XInternAtom(data->display, "CLIPBOARD", 0);

if (!SDL_X11_HAVE_XFIXES ||
!X11_XQueryExtension(data->display, "XFIXES", &fixes_opcode, &event, &error)) {
return;
}

/* Selection tracking is available in all versions of XFixes */
xfixes_selection_notify_event = event + XFixesSelectionNotify;
X11_XFixesSelectSelectionInput(data->display, DefaultRootWindow(data->display),
XA_CLIPBOARD, XFixesSetSelectionOwnerNotifyMask);
X11_XFixesSelectSelectionInput(data->display, DefaultRootWindow(data->display),
XA_PRIMARY, XFixesSetSelectionOwnerNotifyMask);

/* We need at least 5.0 for barriers. */
version = query_xfixes_version(data->display, 5, 0);
if (!xfixes_version_atleast(version, 5, 0)) {
Expand All @@ -69,6 +79,11 @@ int X11_XfixesIsInitialized()
return xfixes_initialized;
}

int X11_GetXFixesSelectionNotifyEvent()
{
return xfixes_selection_notify_event;
}

void X11_SetWindowMouseRect(_THIS, SDL_Window *window)
{
if (SDL_RectEmpty(&window->mouse_rect)) {
Expand Down
2 changes: 1 addition & 1 deletion src/video/x11/SDL_x11xfixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern int X11_XfixesIsInitialized(void);
extern void X11_SetWindowMouseRect(_THIS, SDL_Window *window);
extern int X11_ConfineCursorWithFlags(_THIS, SDL_Window *window, const SDL_Rect *rect, int flags);
extern void X11_DestroyPointerBarrier(_THIS, SDL_Window *window);

extern int X11_GetXFixesSelectionNotifyEvent(void);
#endif /* SDL_VIDEO_DRIVER_X11_XFIXES */

#endif /* SDL_x11xfixes_h_ */
Expand Down
Loading