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>
This commit is contained in:
Jonas Ådahl 2021-09-16 15:37:02 +02:00 committed by Marge Bot
parent 6ae9bc9045
commit 92b95b0b4b
3 changed files with 26 additions and 43 deletions

View File

@ -160,7 +160,9 @@ meta_clutter_backend_x11_finish_init (ClutterBackend *clutter_backend,
g_debug ("Getting the X screen"); g_debug ("Getting the X screen");
/* add event filter for Cogl events */ /* 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); xscreen = DefaultScreenOfDisplay (clutter_backend_x11->xdisplay);
clutter_backend_x11->xscreen_num = XScreenNumberOfScreen (xscreen); 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); 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); XCloseDisplay (clutter_backend_x11->xdisplay);
@ -593,29 +597,14 @@ meta_clutter_x11_get_root_window (void)
} }
void void
meta_clutter_x11_add_filter (MetaX11FilterFunc func, meta_clutter_backend_x11_add_filter (MetaClutterBackendX11 *clutter_backend_x11,
MetaX11FilterFunc func,
gpointer data) gpointer data)
{ {
MetaX11EventFilter *filter; MetaX11EventFilter *filter;
ClutterBackend *clutter_backend = clutter_get_default_backend ();
MetaClutterBackendX11 *clutter_backend_x11;
g_return_if_fail (func != NULL); 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 = g_new0 (MetaX11EventFilter, 1);
filter->func = func; filter->func = func;
filter->data = data; filter->data = data;
@ -627,30 +616,15 @@ meta_clutter_x11_add_filter (MetaX11FilterFunc func,
} }
void void
meta_clutter_x11_remove_filter (MetaX11FilterFunc func, meta_clutter_backend_x11_remove_filter (MetaClutterBackendX11 *clutter_backend_x11,
MetaX11FilterFunc func,
gpointer data) gpointer data)
{ {
GSList *tmp_list, *this; GSList *tmp_list, *this;
MetaX11EventFilter *filter; MetaX11EventFilter *filter;
ClutterBackend *clutter_backend = clutter_get_default_backend ();
MetaClutterBackendX11 *clutter_backend_x11;
g_return_if_fail (func != NULL); 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; tmp_list = clutter_backend_x11->event_filters;
while (tmp_list) while (tmp_list)

View File

@ -84,9 +84,12 @@ int meta_clutter_x11_get_default_screen (void);
Window meta_clutter_x11_get_root_window (void); Window meta_clutter_x11_get_root_window (void);
void meta_clutter_x11_set_display (Display * xdpy); void meta_clutter_x11_set_display (Display * xdpy);
void meta_clutter_x11_add_filter (MetaX11FilterFunc func, void meta_clutter_backend_x11_add_filter (MetaClutterBackendX11 *clutter_backend_x11,
MetaX11FilterFunc func,
gpointer data); gpointer data);
void meta_clutter_x11_remove_filter (MetaX11FilterFunc func,
void meta_clutter_backend_x11_remove_filter (MetaClutterBackendX11 *clutter_backend_x11,
MetaX11FilterFunc func,
gpointer data); gpointer data);
void meta_clutter_x11_set_use_stereo_stage (gboolean use_stereo); void meta_clutter_x11_set_use_stereo_stage (gboolean use_stereo);

View File

@ -323,6 +323,10 @@ meta_seat_x11_apply_kbd_a11y_settings (ClutterSeat *seat,
gboolean gboolean
meta_seat_x11_a11y_init (ClutterSeat *seat) 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 (); Display *xdisplay = meta_clutter_x11_get_default_display ();
guint event_mask; guint event_mask;
@ -333,7 +337,9 @@ meta_seat_x11_a11y_init (ClutterSeat *seat)
XkbSelectEvents (xdisplay, XkbUseCoreKbd, event_mask, event_mask); 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; return TRUE;
} }