From def478edc8e16bdd4d9fabce35747ddd00e7dbe7 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 2 Aug 2023 11:13:47 +0200 Subject: [PATCH] backends/x11: Handle a11y changing XKB events together with other XKB events There's no need for an XEvent filter, since this is already code close enough to MetaBackendX11 XEvent handling and always required anyways. Make the a11y configuration checks happen directly from MetaBackendX11 event handling. Part-of: --- src/backends/x11/meta-backend-x11.c | 13 +++++++++ src/backends/x11/meta-xkb-a11y-x11.c | 43 ++-------------------------- src/backends/x11/meta-xkb-a11y-x11.h | 2 ++ 3 files changed, 17 insertions(+), 41 deletions(-) diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c index 50fd57812..6fe6a7ee6 100644 --- a/src/backends/x11/meta-backend-x11.c +++ b/src/backends/x11/meta-backend-x11.c @@ -346,6 +346,8 @@ handle_host_xevent (MetaBackend *backend, { MetaBackendX11 *x11 = META_BACKEND_X11 (backend); MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11); + ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); + ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend); MetaContext *context = meta_backend_get_context (backend); gboolean bypass_clutter = FALSE; MetaDisplay *display; @@ -408,6 +410,17 @@ handle_host_xevent (MetaBackend *backend, layout_group); } break; + case XkbControlsNotify: + /* 'event_type' is set to zero on notifying us of updates in + * response to client requests (including our own) and non-zero + * to notify us of key/mouse events causing changes (like + * pressing shift 5 times to enable sticky keys). + * + * We only want to update our settings when it's in response to an + * explicit user input event, so require a non-zero event_type. + */ + if (xkb_ev->ctrls.event_type != 0) + meta_seat_x11_check_xkb_a11y_settings_changed (seat); default: break; } diff --git a/src/backends/x11/meta-xkb-a11y-x11.c b/src/backends/x11/meta-xkb-a11y-x11.c index a041dcad8..1404b0096 100644 --- a/src/backends/x11/meta-xkb-a11y-x11.c +++ b/src/backends/x11/meta-xkb-a11y-x11.c @@ -43,8 +43,6 @@ XkbAccessXFeedbackMask | \ XkbControlsEnabledMask -static int _xkb_event_base; - static Display * xdisplay_from_seat (ClutterSeat *seat) { @@ -86,8 +84,8 @@ set_xkb_desc_rec (Display *xdisplay, meta_clutter_x11_untrap_x_errors (); } -static void -check_settings_changed (ClutterSeat *seat) +void +meta_seat_x11_check_xkb_a11y_settings_changed (ClutterSeat *seat) { MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat); MetaBackend *backend = meta_seat_x11_get_backend (META_SEAT_X11 (seat_x11)); @@ -145,37 +143,11 @@ check_settings_changed (ClutterSeat *seat) XkbFreeKeyboard (desc, XkbAllComponentsMask, TRUE); } -static MetaX11FilterReturn -xkb_a11y_event_filter (XEvent *xevent, - ClutterEvent *clutter_event, - gpointer data) -{ - ClutterSeat *seat = CLUTTER_SEAT (data); - XkbEvent *xkbev = (XkbEvent *) xevent; - - /* 'event_type' is set to zero on notifying us of updates in - * response to client requests (including our own) and non-zero - * to notify us of key/mouse events causing changes (like - * pressing shift 5 times to enable sticky keys). - * - * We only want to update out settings when it's in response to an - * explicit user input event, so require a non-zero event_type. - */ - if (xevent->xany.type == (_xkb_event_base + XkbEventCode) && - xkbev->any.xkb_type == XkbControlsNotify && xkbev->ctrls.event_type != 0) - check_settings_changed (seat); - - return META_X11_FILTER_CONTINUE; -} - static gboolean is_xkb_available (Display *xdisplay) { int opcode, error_base, event_base, major, minor; - if (_xkb_event_base) - return TRUE; - if (!XkbQueryExtension (xdisplay, &opcode, &event_base, @@ -187,8 +159,6 @@ is_xkb_available (Display *xdisplay) if (!XkbUseExtension (xdisplay, &major, &minor)) return FALSE; - _xkb_event_base = event_base; - return TRUE; } @@ -337,11 +307,6 @@ meta_seat_x11_apply_kbd_a11y_settings (ClutterSeat *seat, gboolean meta_seat_x11_a11y_init (ClutterSeat *seat) { - MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat); - MetaBackend *backend = meta_seat_x11_get_backend (META_SEAT_X11 (seat_x11)); - ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); - MetaClutterBackendX11 *clutter_backend_x11 = - META_CLUTTER_BACKEND_X11 (clutter_backend); Display *xdisplay = xdisplay_from_seat (seat); guint event_mask; @@ -352,9 +317,5 @@ meta_seat_x11_a11y_init (ClutterSeat *seat) XkbSelectEvents (xdisplay, XkbUseCoreKbd, event_mask, event_mask); - meta_clutter_backend_x11_add_filter (clutter_backend_x11, - xkb_a11y_event_filter, - seat); - return TRUE; } diff --git a/src/backends/x11/meta-xkb-a11y-x11.h b/src/backends/x11/meta-xkb-a11y-x11.h index cf9a79091..ef88f0c13 100644 --- a/src/backends/x11/meta-xkb-a11y-x11.h +++ b/src/backends/x11/meta-xkb-a11y-x11.h @@ -34,3 +34,5 @@ meta_seat_x11_apply_kbd_a11y_settings (ClutterSeat *seat, gboolean meta_seat_x11_a11y_init (ClutterSeat *seat); + +void meta_seat_x11_check_xkb_a11y_settings_changed (ClutterSeat *seat);