[mutter] clutter/backend/x11: Make filter add/remove take a clutter backend



commit 92b95b0b4b8153743dc770e33f92896b5a521c06
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Thu Sep 16 15:37:02 2021 +0200

    clutter/backend/x11: Make filter add/remove take a clutter backend
    
    This avoids some global fetching, which is problematic if it happens
    during init.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2002>

 src/backends/x11/meta-clutter-backend-x11.c | 50 +++++++----------------------
 src/backends/x11/meta-clutter-backend-x11.h | 11 ++++---
 src/backends/x11/meta-xkb-a11y-x11.c        |  8 ++++-
 3 files changed, 26 insertions(+), 43 deletions(-)
---
diff --git a/src/backends/x11/meta-clutter-backend-x11.c b/src/backends/x11/meta-clutter-backend-x11.c
index 4fa72b059c..501ae8b323 100644
--- a/src/backends/x11/meta-clutter-backend-x11.c
+++ b/src/backends/x11/meta-clutter-backend-x11.c
@@ -160,7 +160,9 @@ meta_clutter_backend_x11_finish_init (ClutterBackend  *clutter_backend,
   g_debug ("Getting the X screen");
 
   /* add event filter for Cogl events */
-  meta_clutter_x11_add_filter (cogl_xlib_filter, clutter_backend);
+  meta_clutter_backend_x11_add_filter (clutter_backend_x11,
+                                       cogl_xlib_filter,
+                                       clutter_backend);
 
   xscreen = DefaultScreenOfDisplay (clutter_backend_x11->xdisplay);
   clutter_backend_x11->xscreen_num = XScreenNumberOfScreen (xscreen);
@@ -201,7 +203,9 @@ meta_clutter_backend_x11_finalize (GObject *gobject)
 {
   MetaClutterBackendX11 *clutter_backend_x11 = META_CLUTTER_BACKEND_X11 (gobject);
 
-  meta_clutter_x11_remove_filter (cogl_xlib_filter, gobject);
+  meta_clutter_backend_x11_remove_filter (clutter_backend_x11,
+                                          cogl_xlib_filter,
+                                          clutter_backend_x11);
 
   XCloseDisplay (clutter_backend_x11->xdisplay);
 
@@ -593,29 +597,14 @@ meta_clutter_x11_get_root_window (void)
 }
 
 void
-meta_clutter_x11_add_filter (MetaX11FilterFunc func,
-                             gpointer             data)
+meta_clutter_backend_x11_add_filter (MetaClutterBackendX11 *clutter_backend_x11,
+                                     MetaX11FilterFunc      func,
+                                     gpointer               data)
 {
   MetaX11EventFilter *filter;
-  ClutterBackend *clutter_backend = clutter_get_default_backend ();
-  MetaClutterBackendX11 *clutter_backend_x11;
 
   g_return_if_fail (func != NULL);
 
-  if (clutter_backend == NULL)
-    {
-      g_critical ("The Clutter backend has not been initialised");
-      return;
-    }
-
-  if (!META_IS_CLUTTER_BACKEND_X11 (clutter_backend))
-    {
-      g_critical ("The Clutter backend is not a X11 backend");
-      return;
-    }
-
-  clutter_backend_x11 = META_CLUTTER_BACKEND_X11 (clutter_backend);
-
   filter = g_new0 (MetaX11EventFilter, 1);
   filter->func = func;
   filter->data = data;
@@ -627,30 +616,15 @@ meta_clutter_x11_add_filter (MetaX11FilterFunc func,
 }
 
 void
-meta_clutter_x11_remove_filter (MetaX11FilterFunc func,
-                                gpointer          data)
+meta_clutter_backend_x11_remove_filter (MetaClutterBackendX11 *clutter_backend_x11,
+                                        MetaX11FilterFunc      func,
+                                        gpointer               data)
 {
   GSList *tmp_list, *this;
   MetaX11EventFilter *filter;
-  ClutterBackend *clutter_backend = clutter_get_default_backend ();
-  MetaClutterBackendX11 *clutter_backend_x11;
 
   g_return_if_fail (func != NULL);
 
-  if (clutter_backend == NULL)
-    {
-      g_critical ("The Clutter backend has not been initialised");
-      return;
-    }
-
-  if (!META_IS_CLUTTER_BACKEND_X11 (clutter_backend))
-    {
-      g_critical ("The Clutter backend is not a X11 backend");
-      return;
-    }
-
-  clutter_backend_x11 = META_CLUTTER_BACKEND_X11 (clutter_backend);
-
   tmp_list = clutter_backend_x11->event_filters;
 
   while (tmp_list)
diff --git a/src/backends/x11/meta-clutter-backend-x11.h b/src/backends/x11/meta-clutter-backend-x11.h
index d5c9ae302a..50b8434b01 100644
--- a/src/backends/x11/meta-clutter-backend-x11.h
+++ b/src/backends/x11/meta-clutter-backend-x11.h
@@ -84,10 +84,13 @@ int meta_clutter_x11_get_default_screen (void);
 Window meta_clutter_x11_get_root_window (void);
 void meta_clutter_x11_set_display (Display * xdpy);
 
-void meta_clutter_x11_add_filter (MetaX11FilterFunc func,
-                                  gpointer          data);
-void meta_clutter_x11_remove_filter (MetaX11FilterFunc func,
-                                     gpointer          data);
+void meta_clutter_backend_x11_add_filter (MetaClutterBackendX11 *clutter_backend_x11,
+                                          MetaX11FilterFunc      func,
+                                          gpointer               data);
+
+void meta_clutter_backend_x11_remove_filter (MetaClutterBackendX11 *clutter_backend_x11,
+                                             MetaX11FilterFunc      func,
+                                             gpointer               data);
 
 void meta_clutter_x11_set_use_stereo_stage (gboolean use_stereo);
 gboolean meta_clutter_x11_get_use_stereo_stage (void);
diff --git a/src/backends/x11/meta-xkb-a11y-x11.c b/src/backends/x11/meta-xkb-a11y-x11.c
index c73b9dc4f3..4cfd52e77b 100644
--- a/src/backends/x11/meta-xkb-a11y-x11.c
+++ b/src/backends/x11/meta-xkb-a11y-x11.c
@@ -323,6 +323,10 @@ meta_seat_x11_apply_kbd_a11y_settings (ClutterSeat         *seat,
 gboolean
 meta_seat_x11_a11y_init (ClutterSeat *seat)
 {
+  MetaBackend *backend = meta_get_backend ();
+  ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
+  MetaClutterBackendX11 *clutter_backend_x11 =
+    META_CLUTTER_BACKEND_X11 (clutter_backend);
   Display *xdisplay = meta_clutter_x11_get_default_display ();
   guint event_mask;
 
@@ -333,7 +337,9 @@ meta_seat_x11_a11y_init (ClutterSeat *seat)
 
   XkbSelectEvents (xdisplay, XkbUseCoreKbd, event_mask, event_mask);
 
-  meta_clutter_x11_add_filter (xkb_a11y_event_filter, seat);
+  meta_clutter_backend_x11_add_filter (clutter_backend_x11,
+                                       xkb_a11y_event_filter,
+                                       seat);
 
   return TRUE;
 }


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