From 437f5d1c663e5d5467ad57d287181a7a7dbc978c Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 18 Dec 2020 14:59:17 +0100 Subject: [PATCH] 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. Part-of: --- src/backends/x11/meta-backend-x11.c | 25 +++++++++++++++++++++++++ src/backends/x11/meta-backend-x11.h | 2 ++ src/compositor/meta-compositor-x11.c | 6 ++++++ 3 files changed, 33 insertions(+) diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c index 722d7b3d9..9c40ada2c 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 526bf0caa..2815015d1 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 6cfdef52b..27999fbae 100644 --- a/src/compositor/meta-compositor-x11.c +++ b/src/compositor/meta-compositor-x11.c @@ -442,11 +442,17 @@ meta_compositor_x11_monotonic_to_high_res_xserver_time (MetaCompositor *composit 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