From be7264f35b0dc369a4add984f5b8e2cbd7d6215f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Thu, 29 Jul 2021 19:01:44 +0200 Subject: debug-gui: pointer locking on X11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Expósito --- tools/libinput-debug-gui.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'tools') diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c index 460fd3c7..861116e4 100644 --- a/tools/libinput-debug-gui.c +++ b/tools/libinput-debug-gui.c @@ -58,6 +58,16 @@ #endif #endif +#ifdef GDK_WINDOWING_X11 + #include + #include + #if HAVE_GTK4 + #include + #else + #include + #endif +#endif + #define clip(val_, min_, max_) min((max_), max((min_), (val_))) enum touch_state { @@ -293,6 +303,51 @@ backend_is_wayland(void) } #endif /* GDK_WINDOWING_WAYLAND */ +#ifdef GDK_WINDOWING_X11 +static bool +x_lock_pointer(struct window *w) +{ + Display *x_display; + Window x_win; + int result; + + x_display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + +#if HAVE_GTK4 + GtkNative *window = gtk_widget_get_native(w->win); + GdkSurface *surface = gtk_native_get_surface(window); + x_win = GDK_SURFACE_XID(surface); +#else + GdkWindow *window = gtk_widget_get_window(w->win); + x_win = GDK_WINDOW_XID(window); +#endif + + result = XGrabPointer(x_display, x_win, + False, NoEventMask, + GrabModeAsync, GrabModeAsync, + x_win, + None, + CurrentTime); + return (result == GrabSuccess); +} + +static void +x_unlock_pointer(struct window *w) +{ + Display *x_display; + + x_display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + + XUngrabPointer(x_display, CurrentTime); +} + +static inline bool +backend_is_x11(void) +{ + return GDK_IS_X11_DISPLAY(gdk_display_get_default()); +} +#endif /* GDK_WINDOWING_X11 */ + static bool window_lock_pointer(struct window *w) { @@ -303,6 +358,11 @@ window_lock_pointer(struct window *w) w->lock_pointer.locked = wayland_lock_pointer(w); #endif +#ifdef GDK_WINDOWING_X11 + if (backend_is_x11()) + w->lock_pointer.locked = x_lock_pointer(w); +#endif + return w->lock_pointer.locked; } @@ -318,6 +378,11 @@ window_unlock_pointer(struct window *w) if (backend_is_wayland()) wayland_unlock_pointer(w); #endif + +#ifdef GDK_WINDOWING_X11 + if (backend_is_x11()) + x_unlock_pointer(w); +#endif } LIBINPUT_ATTRIBUTE_PRINTF(1, 2) -- cgit v1.2.1