mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-25 12:50:05 +01:00
debug-gui: pointer locking on X11
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
This commit is contained in:
parent
a9b334ebb5
commit
be7264f35b
2 changed files with 67 additions and 0 deletions
|
|
@ -561,6 +561,7 @@ if get_option('debug-gui')
|
||||||
dep_glib = dependency('glib-2.0')
|
dep_glib = dependency('glib-2.0')
|
||||||
dep_wayland_client = dependency('wayland-client', required : false)
|
dep_wayland_client = dependency('wayland-client', required : false)
|
||||||
dep_wayland_protocols = dependency('wayland-protocols', required : false)
|
dep_wayland_protocols = dependency('wayland-protocols', required : false)
|
||||||
|
dep_x11 = dependency('x11', required : false)
|
||||||
|
|
||||||
debug_gui_sources = [ 'tools/libinput-debug-gui.c' ]
|
debug_gui_sources = [ 'tools/libinput-debug-gui.c' ]
|
||||||
|
|
||||||
|
|
@ -592,6 +593,7 @@ if get_option('debug-gui')
|
||||||
dep_glib,
|
dep_glib,
|
||||||
dep_wayland_client,
|
dep_wayland_client,
|
||||||
dep_wayland_protocols,
|
dep_wayland_protocols,
|
||||||
|
dep_x11,
|
||||||
] + deps_tools
|
] + deps_tools
|
||||||
executable('libinput-debug-gui',
|
executable('libinput-debug-gui',
|
||||||
debug_gui_sources,
|
debug_gui_sources,
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,16 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef GDK_WINDOWING_X11
|
||||||
|
#include <X11/X.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#if HAVE_GTK4
|
||||||
|
#include <gdk/x11/gdkx.h>
|
||||||
|
#else
|
||||||
|
#include <gdk/gdkx.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#define clip(val_, min_, max_) min((max_), max((min_), (val_)))
|
#define clip(val_, min_, max_) min((max_), max((min_), (val_)))
|
||||||
|
|
||||||
enum touch_state {
|
enum touch_state {
|
||||||
|
|
@ -293,6 +303,51 @@ backend_is_wayland(void)
|
||||||
}
|
}
|
||||||
#endif /* GDK_WINDOWING_WAYLAND */
|
#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
|
static bool
|
||||||
window_lock_pointer(struct window *w)
|
window_lock_pointer(struct window *w)
|
||||||
{
|
{
|
||||||
|
|
@ -303,6 +358,11 @@ window_lock_pointer(struct window *w)
|
||||||
w->lock_pointer.locked = wayland_lock_pointer(w);
|
w->lock_pointer.locked = wayland_lock_pointer(w);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef GDK_WINDOWING_X11
|
||||||
|
if (backend_is_x11())
|
||||||
|
w->lock_pointer.locked = x_lock_pointer(w);
|
||||||
|
#endif
|
||||||
|
|
||||||
return w->lock_pointer.locked;
|
return w->lock_pointer.locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -318,6 +378,11 @@ window_unlock_pointer(struct window *w)
|
||||||
if (backend_is_wayland())
|
if (backend_is_wayland())
|
||||||
wayland_unlock_pointer(w);
|
wayland_unlock_pointer(w);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef GDK_WINDOWING_X11
|
||||||
|
if (backend_is_x11())
|
||||||
|
x_unlock_pointer(w);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBINPUT_ATTRIBUTE_PRINTF(1, 2)
|
LIBINPUT_ATTRIBUTE_PRINTF(1, 2)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue