[mutter/wip/carlosg/sync-pointer-in-mutter: 293/294] compositor: Sync pointer after begin/end modal on X11




commit c2167dcbe91868448dd10f77d8422a3f7cd04ec9
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Dec 18 14:59:17 2020 +0100

    compositor: Sync pointer after begin/end modal on X11
    
    Ensure we issue a motion event for the current pointer position,
    as there might be situations where compositor modals get X grabs
    from other clients stacked on top, or missed events in between
    otherwise.
    
    Ensure the Clutter state is still up-to-date afterwards here. This
    replaces some sync_pointer() calls done in GNOME Shell code, always
    done after modality changes.

 src/backends/x11/meta-backend-x11.c  | 25 +++++++++++++++++++++++++
 src/backends/x11/meta-backend-x11.h  |  2 ++
 src/compositor/meta-compositor-x11.c | 18 ++++++++++++++++++
 3 files changed, 45 insertions(+)
---
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index 722d7b3d9f..9c40ada2c1 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -921,3 +921,28 @@ meta_backend_x11_reload_cursor (MetaBackendX11 *x11)
 
   meta_cursor_renderer_force_update (cursor_renderer);
 }
+
+void
+meta_backend_x11_sync_pointer (MetaBackendX11 *backend_x11)
+{
+  MetaBackend *backend = META_BACKEND (backend_x11);
+  ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
+  ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend);
+  ClutterInputDevice *pointer = clutter_seat_get_pointer (seat);
+  ClutterStage *stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
+  ClutterModifierType modifiers;
+  ClutterEvent *event;
+  graphene_point_t pos;
+
+  event = clutter_event_new (CLUTTER_MOTION);
+  clutter_seat_query_state (seat, pointer, NULL, &pos, &modifiers);
+  clutter_event_set_flags (event, CLUTTER_EVENT_FLAG_SYNTHETIC);
+  clutter_event_set_coords (event, pos.x, pos.y);
+  clutter_event_set_device (event, pointer);
+  clutter_event_set_state (event, modifiers);
+  clutter_event_set_source_device (event, NULL);
+  clutter_event_set_stage (event, stage);
+
+  clutter_event_put (event);
+  clutter_event_free (event);
+}
diff --git a/src/backends/x11/meta-backend-x11.h b/src/backends/x11/meta-backend-x11.h
index 526bf0caa7..2815015d15 100644
--- a/src/backends/x11/meta-backend-x11.h
+++ b/src/backends/x11/meta-backend-x11.h
@@ -58,4 +58,6 @@ uint8_t meta_backend_x11_get_xkb_event_base (MetaBackendX11 *x11);
 
 void meta_backend_x11_reload_cursor (MetaBackendX11 *x11);
 
+void meta_backend_x11_sync_pointer (MetaBackendX11 *backend_x11);
+
 #endif /* META_BACKEND_X11_H */
diff --git a/src/compositor/meta-compositor-x11.c b/src/compositor/meta-compositor-x11.c
index e7da103e3a..27999fbaec 100644
--- a/src/compositor/meta-compositor-x11.c
+++ b/src/compositor/meta-compositor-x11.c
@@ -439,6 +439,22 @@ meta_compositor_x11_monotonic_to_high_res_xserver_time (MetaCompositor *composit
   return monotonic_time_us + compositor_x11->xserver_time_offset_us;
 }
 
+static void
+meta_compositor_x11_grab_begin (MetaCompositor *compositor)
+{
+  MetaBackendX11 *backend_x11 = META_BACKEND_X11 (meta_get_backend ());
+
+  meta_backend_x11_sync_pointer (backend_x11);
+}
+
+static void
+meta_compositor_x11_grab_end (MetaCompositor *compositor)
+{
+  MetaBackendX11 *backend_x11 = META_BACKEND_X11 (meta_get_backend ());
+
+  meta_backend_x11_sync_pointer (backend_x11);
+}
+
 Window
 meta_compositor_x11_get_output_xwindow (MetaCompositorX11 *compositor_x11)
 {
@@ -508,4 +524,6 @@ meta_compositor_x11_class_init (MetaCompositorX11Class *klass)
   compositor_class->remove_window = meta_compositor_x11_remove_window;
   compositor_class->monotonic_to_high_res_xserver_time =
    meta_compositor_x11_monotonic_to_high_res_xserver_time;
+  compositor_class->grab_begin = meta_compositor_x11_grab_begin;
+  compositor_class->grab_end = meta_compositor_x11_grab_end;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]