diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h index 5435fbefd..44b36ba3c 100644 --- a/src/backends/meta-backend-private.h +++ b/src/backends/meta-backend-private.h @@ -55,6 +55,13 @@ struct _MetaBackendClass int device_id); MetaMonitorManager * (* create_monitor_manager) (MetaBackend *backend); MetaCursorRenderer * (* create_cursor_renderer) (MetaBackend *backend); + + gboolean (* grab_device) (MetaBackend *backend, + int device_id, + uint32_t timestamp); + gboolean (* ungrab_device) (MetaBackend *backend, + int device_id, + uint32_t timestamp); }; #endif /* META_BACKEND_PRIVATE_H */ diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index 91cd83705..3fb8aa915 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -82,6 +82,24 @@ meta_backend_real_create_cursor_renderer (MetaBackend *backend) return meta_cursor_renderer_new (); } +static gboolean +meta_backend_real_grab_device (MetaBackend *backend, + int device_id, + uint32_t timestamp) +{ + /* Do nothing */ + return TRUE; +} + +static gboolean +meta_backend_real_ungrab_device (MetaBackend *backend, + int device_id, + uint32_t timestamp) +{ + /* Do nothing */ + return TRUE; +} + static void meta_backend_class_init (MetaBackendClass *klass) { @@ -91,6 +109,8 @@ meta_backend_class_init (MetaBackendClass *klass) klass->post_init = meta_backend_real_post_init; klass->create_cursor_renderer = meta_backend_real_create_cursor_renderer; + klass->grab_device = meta_backend_real_grab_device; + klass->ungrab_device = meta_backend_real_ungrab_device; } static void @@ -153,6 +173,22 @@ meta_backend_get_cursor_renderer (MetaBackend *backend) return priv->cursor_renderer; } +gboolean +meta_backend_grab_device (MetaBackend *backend, + int device_id, + uint32_t timestamp) +{ + return META_BACKEND_GET_CLASS (backend)->grab_device (backend, device_id, timestamp); +} + +gboolean +meta_backend_ungrab_device (MetaBackend *backend, + int device_id, + uint32_t timestamp) +{ + return META_BACKEND_GET_CLASS (backend)->ungrab_device (backend, device_id, timestamp); +} + static GType get_backend_type (void) { diff --git a/src/backends/meta-backend.h b/src/backends/meta-backend.h index d0a187785..9bcfd8ee6 100644 --- a/src/backends/meta-backend.h +++ b/src/backends/meta-backend.h @@ -43,6 +43,13 @@ MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend, MetaMonitorManager * meta_backend_get_monitor_manager (MetaBackend *backend); MetaCursorRenderer * meta_backend_get_cursor_renderer (MetaBackend *backend); +gboolean meta_backend_grab_device (MetaBackend *backend, + int device_id, + uint32_t timestamp); +gboolean meta_backend_ungrab_device (MetaBackend *backend, + int device_id, + uint32_t timestamp); + void meta_clutter_init (void); #endif /* META_BACKEND_H */ diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c index cda2caf55..3839c295c 100644 --- a/src/backends/x11/meta-backend-x11.c +++ b/src/backends/x11/meta-backend-x11.c @@ -30,11 +30,14 @@ #include -#include #include "meta-idle-monitor-xsync.h" #include "meta-monitor-manager-xrandr.h" #include "backends/meta-monitor-manager-dummy.h" +#include "meta-cursor-tracker-private.h" +#include "meta-cursor.h" +#include + struct _MetaBackendX11Private { /* The host X11 display */ @@ -189,6 +192,52 @@ meta_backend_x11_create_monitor_manager (MetaBackend *backend) return g_object_new (META_TYPE_MONITOR_MANAGER_XRANDR, NULL); } +static gboolean +meta_backend_x11_grab_device (MetaBackend *backend, + int device_id, + uint32_t timestamp) +{ + MetaBackendX11 *x11 = META_BACKEND_X11 (backend); + MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11); + unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 }; + XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits }; + int ret; + + XISetMask (mask.mask, XI_ButtonPress); + XISetMask (mask.mask, XI_ButtonRelease); + XISetMask (mask.mask, XI_Enter); + XISetMask (mask.mask, XI_Leave); + XISetMask (mask.mask, XI_Motion); + + MetaCursorTracker *tracker = meta_cursor_tracker_get_for_screen (NULL); + MetaCursorReference *cursor_ref = meta_cursor_tracker_get_displayed_cursor (tracker); + MetaCursor cursor = meta_cursor_reference_get_meta_cursor (cursor_ref); + + ret = XIGrabDevice (priv->xdisplay, device_id, + DefaultRootWindow (priv->xdisplay), + timestamp, + meta_cursor_create_x_cursor (priv->xdisplay, cursor), + XIGrabModeAsync, XIGrabModeAsync, + False, /* owner_events */ + &mask); + + return (ret == Success); +} + +static gboolean +meta_backend_x11_ungrab_device (MetaBackend *backend, + int device_id, + uint32_t timestamp) +{ + MetaBackendX11 *x11 = META_BACKEND_X11 (backend); + MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11); + int ret; + + ret = XIUngrabDevice (priv->xdisplay, device_id, timestamp); + + return (ret == Success); +} + static void meta_backend_x11_class_init (MetaBackendX11Class *klass) { @@ -197,6 +246,9 @@ meta_backend_x11_class_init (MetaBackendX11Class *klass) backend_class->post_init = meta_backend_x11_post_init; backend_class->create_idle_monitor = meta_backend_x11_create_idle_monitor; backend_class->create_monitor_manager = meta_backend_x11_create_monitor_manager; + + backend_class->grab_device = meta_backend_x11_grab_device; + backend_class->ungrab_device = meta_backend_x11_ungrab_device; } static void diff --git a/src/core/display.c b/src/core/display.c index c982f8fa2..64b549c3f 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -50,6 +50,7 @@ #include "mutter-enum-types.h" #include "meta-idle-monitor-dbus.h" #include "meta-cursor-tracker-private.h" +#include "meta-backend.h" #ifdef HAVE_RANDR #include @@ -1728,54 +1729,17 @@ meta_display_set_grab_op_cursor (MetaDisplay *display, guint32 timestamp) { /* Set root cursor */ - { - MetaCursorTracker *tracker = meta_cursor_tracker_get_for_screen (display->screen); - MetaCursor cursor = meta_cursor_for_grab_op (op); - MetaCursorReference *cursor_ref; + MetaBackend *backend = meta_get_backend (); + MetaCursorTracker *tracker = meta_cursor_tracker_get_for_screen (display->screen); + MetaCursor cursor = meta_cursor_for_grab_op (op); + MetaCursorReference *cursor_ref; - cursor_ref = meta_cursor_reference_from_theme (cursor); - meta_cursor_tracker_set_grab_cursor (tracker, cursor_ref); - meta_cursor_reference_unref (cursor_ref); - } + cursor_ref = meta_cursor_reference_from_theme (cursor); + meta_cursor_tracker_set_grab_cursor (tracker, cursor_ref); + meta_cursor_reference_unref (cursor_ref); - /* Take grab */ - { - unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 }; - XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits }; - - XISetMask (mask.mask, XI_ButtonPress); - XISetMask (mask.mask, XI_ButtonRelease); - XISetMask (mask.mask, XI_Enter); - XISetMask (mask.mask, XI_Leave); - XISetMask (mask.mask, XI_Motion); - - MetaCursorTracker *tracker = meta_cursor_tracker_get_for_screen (display->screen); - MetaCursorReference *cursor_ref = meta_cursor_tracker_get_displayed_cursor (tracker); - MetaCursor cursor = meta_cursor_reference_get_meta_cursor (cursor_ref); - - meta_error_trap_push (display); - if (XIGrabDevice (display->xdisplay, - META_VIRTUAL_CORE_POINTER_ID, - display->screen->xroot, - timestamp, - meta_display_create_x_cursor (display, cursor), - XIGrabModeAsync, XIGrabModeAsync, - False, /* owner_events */ - &mask) == Success) - { - display->grab_have_pointer = TRUE; - meta_topic (META_DEBUG_WINDOW_OPS, - "XIGrabDevice() returned GrabSuccess time %u\n", - timestamp); - } - else - { - meta_topic (META_DEBUG_WINDOW_OPS, - "XIGrabDevice() failed time %u\n", - timestamp); - } - meta_error_trap_pop (display); - } + if (meta_backend_grab_device (backend, META_VIRTUAL_CORE_POINTER_ID, timestamp)) + display->grab_have_pointer = TRUE; } gboolean @@ -1839,8 +1803,7 @@ meta_display_begin_grab_op (MetaDisplay *display, if (!display->grab_have_pointer && !meta_grab_op_is_keyboard (op)) { - meta_topic (META_DEBUG_WINDOW_OPS, - "XIGrabDevice() failed\n"); + meta_topic (META_DEBUG_WINDOW_OPS, "XIGrabDevice() failed\n"); return FALSE; } @@ -1854,12 +1817,12 @@ meta_display_begin_grab_op (MetaDisplay *display, else display->grab_have_keyboard = meta_screen_grab_all_keys (screen, timestamp); - + if (!display->grab_have_keyboard) { - meta_topic (META_DEBUG_WINDOW_OPS, - "grabbing all keys failed, ungrabbing pointer\n"); - XIUngrabDevice (display->xdisplay, META_VIRTUAL_CORE_POINTER_ID, timestamp); + MetaBackend *backend = meta_get_backend (); + meta_topic (META_DEBUG_WINDOW_OPS, "grabbing all keys failed, ungrabbing pointer\n"); + meta_backend_ungrab_device (backend, META_VIRTUAL_CORE_POINTER_ID, timestamp); display->grab_have_pointer = FALSE; return FALSE; } @@ -1965,9 +1928,8 @@ meta_display_end_grab_op (MetaDisplay *display, if (display->grab_have_pointer) { - meta_topic (META_DEBUG_WINDOW_OPS, - "Ungrabbing pointer with timestamp %u\n", timestamp); - XIUngrabDevice (display->xdisplay, META_VIRTUAL_CORE_POINTER_ID, timestamp); + MetaBackend *backend = meta_get_backend (); + meta_backend_ungrab_device (backend, META_VIRTUAL_CORE_POINTER_ID, timestamp); } if (display->grab_have_keyboard)