From 0dfb5d1c31e052eefe6f2c367bc2349f770692b8 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 2 Aug 2023 10:28:04 +0200 Subject: [PATCH] backends/x11: Call cogl xlib event handler directly when handling XEvents We are pretty much guaranteed that the first event will be handled after the cogl renderer has been set up. We can avoid the loop through ClutterBackend vmethods and X11 event filters, and call this directly from the code that is already close to the MetaClutterBackendX11. Part-of: --- src/backends/x11/meta-clutter-backend-x11.c | 46 --------------------- src/backends/x11/meta-event-x11.c | 8 ++++ 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/src/backends/x11/meta-clutter-backend-x11.c b/src/backends/x11/meta-clutter-backend-x11.c index 2c43e9f35..97767c686 100644 --- a/src/backends/x11/meta-clutter-backend-x11.c +++ b/src/backends/x11/meta-clutter-backend-x11.c @@ -82,32 +82,6 @@ static gboolean clutter_enable_stereo = FALSE; static int TrappedErrorCode = 0; static int (* old_error_handler) (Display *, XErrorEvent *); -static MetaX11FilterReturn -cogl_xlib_filter (XEvent *xevent, - ClutterEvent *event, - gpointer data) -{ - ClutterBackend *clutter_backend = data; - MetaX11FilterReturn retval; - CoglFilterReturn ret; - - ret = cogl_xlib_renderer_handle_event (clutter_backend->cogl_renderer, - xevent); - switch (ret) - { - case COGL_FILTER_REMOVE: - retval = META_X11_FILTER_REMOVE; - break; - - case COGL_FILTER_CONTINUE: - default: - retval = META_X11_FILTER_CONTINUE; - break; - } - - return retval; -} - static gboolean meta_clutter_backend_x11_finish_init (ClutterBackend *clutter_backend, GError **error) @@ -121,11 +95,6 @@ meta_clutter_backend_x11_finish_init (ClutterBackend *clutter_backend, clutter_backend_x11->xdisplay = meta_backend_x11_get_xdisplay (backend_x11); - /* add event filter for Cogl events */ - meta_clutter_backend_x11_add_filter (clutter_backend_x11, - cogl_xlib_filter, - clutter_backend); - XInternAtoms (clutter_backend_x11->xdisplay, (char **) atom_names, N_ATOM_NAMES, False, atoms); @@ -144,18 +113,6 @@ meta_clutter_backend_x11_finish_init (ClutterBackend *clutter_backend, return TRUE; } -static void -meta_clutter_backend_x11_finalize (GObject *gobject) -{ - MetaClutterBackendX11 *clutter_backend_x11 = META_CLUTTER_BACKEND_X11 (gobject); - - meta_clutter_backend_x11_remove_filter (clutter_backend_x11, - cogl_xlib_filter, - clutter_backend_x11); - - G_OBJECT_CLASS (meta_clutter_backend_x11_parent_class)->finalize (gobject); -} - static void update_last_event_time (MetaClutterBackendX11 *clutter_backend_x11, XEvent *xevent) @@ -406,11 +363,8 @@ meta_clutter_backend_x11_init (MetaClutterBackendX11 *clutter_backend_x11) static void meta_clutter_backend_x11_class_init (MetaClutterBackendX11Class *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); ClutterBackendClass *clutter_backend_class = CLUTTER_BACKEND_CLASS (klass); - gobject_class->finalize = meta_clutter_backend_x11_finalize; - clutter_backend_class->finish_init = meta_clutter_backend_x11_finish_init; clutter_backend_class->get_display = meta_clutter_backend_x11_get_display; diff --git a/src/backends/x11/meta-event-x11.c b/src/backends/x11/meta-event-x11.c index e1ac17c4a..f0b04edd7 100644 --- a/src/backends/x11/meta-event-x11.c +++ b/src/backends/x11/meta-event-x11.c @@ -29,6 +29,7 @@ #include "backends/x11/meta-backend-x11.h" #include "backends/x11/meta-event-x11.h" #include "clutter/clutter-mutter.h" +#include "cogl/cogl-xlib.h" /** * meta_x11_handle_event: @@ -77,6 +78,13 @@ meta_x11_handle_event (MetaBackend *backend, allocated_event = XGetEventData (xdisplay, &xevent->xcookie); + if (cogl_xlib_renderer_handle_event (clutter_backend->cogl_renderer, + xevent) == COGL_FILTER_REMOVE) + { + clutter_event_free (event); + goto out; + } + if (_clutter_backend_translate_event (clutter_backend, xevent, event)) { _clutter_event_push (event, FALSE);