From afce4482819642645c6f74938f844b1400824c21 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 30 Mar 2014 20:58:11 -0400 Subject: [PATCH] Kill meta_ui_add_event_func / remove_event_func The reason we don't simply use gdk_window_add_filter directly is because of some twisted idea that any GDK symbol being used from core/ is a layer violation. While we certainly want to keep any serious GDK code out of ui/, event handling is quite important to have in core/, so simply use a GDK event filter directly. --- src/core/events.c | 20 ++++++++--------- src/ui/ui.c | 55 +++++++++-------------------------------------- src/ui/ui.h | 7 ------ 3 files changed, 20 insertions(+), 62 deletions(-) diff --git a/src/core/events.c b/src/core/events.c index 1cbd6ba8f..aaf97f9f7 100644 --- a/src/core/events.c +++ b/src/core/events.c @@ -2124,13 +2124,17 @@ meta_display_handle_event (MetaDisplay *display, return bypass_clutter; } -static gboolean -xevent_callback (XEvent *event, - gpointer data) +static GdkFilterReturn +xevent_filter (GdkXEvent *xevent, + GdkEvent *event, + gpointer data) { MetaDisplay *display = data; - return meta_display_handle_xevent (display, event); + if (meta_display_handle_xevent (display, xevent)) + return GDK_FILTER_REMOVE; + else + return GDK_FILTER_CONTINUE; } static gboolean @@ -2145,9 +2149,7 @@ event_callback (const ClutterEvent *event, void meta_display_init_events (MetaDisplay *display) { - meta_ui_add_event_func (display->xdisplay, - xevent_callback, - display); + gdk_window_add_filter (NULL, xevent_filter, display); display->clutter_event_filter = clutter_event_add_filter (NULL, event_callback, NULL, @@ -2157,9 +2159,7 @@ meta_display_init_events (MetaDisplay *display) void meta_display_free_events (MetaDisplay *display) { - meta_ui_remove_event_func (display->xdisplay, - xevent_callback, - display); + gdk_window_remove_filter (NULL, xevent_filter, display); clutter_event_remove_filter (display->clutter_event_filter); display->clutter_event_filter = 0; } diff --git a/src/ui/ui.c b/src/ui/ui.c index 1a19838f4..822eff5cf 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -228,58 +228,17 @@ maybe_redirect_mouse_event (XEvent *xevent) return TRUE; } -typedef struct _EventFunc EventFunc; - -struct _EventFunc -{ - MetaEventFunc func; - gpointer data; -}; - -static EventFunc *ef = NULL; - static GdkFilterReturn -filter_func (GdkXEvent *xevent, - GdkEvent *event, - gpointer data) +ui_filter_func (GdkXEvent *xevent, + GdkEvent *event, + gpointer data) { - g_return_val_if_fail (ef != NULL, GDK_FILTER_CONTINUE); - - if ((* ef->func) (xevent, ef->data) || - maybe_redirect_mouse_event (xevent)) + if (maybe_redirect_mouse_event (xevent)) return GDK_FILTER_REMOVE; else return GDK_FILTER_CONTINUE; } -void -meta_ui_add_event_func (Display *xdisplay, - MetaEventFunc func, - gpointer data) -{ - g_return_if_fail (ef == NULL); - - ef = g_new (EventFunc, 1); - ef->func = func; - ef->data = data; - - gdk_window_add_filter (NULL, filter_func, ef); -} - -/* removal is by data due to proxy function */ -void -meta_ui_remove_event_func (Display *xdisplay, - MetaEventFunc func, - gpointer data) -{ - g_return_if_fail (ef != NULL); - - gdk_window_remove_filter (NULL, filter_func, ef); - - g_free (ef); - ef = NULL; -} - MetaUI* meta_ui_new (Display *xdisplay, Screen *screen) @@ -294,6 +253,8 @@ meta_ui_new (Display *xdisplay, gdisplay = gdk_x11_lookup_xdisplay (xdisplay); g_assert (gdisplay == gdk_display_get_default ()); + gdk_window_add_filter (NULL, ui_filter_func, NULL); + ui->frames = meta_frames_new (XScreenNumberOfScreen (screen)); /* GTK+ needs the frame-sync protocol to work in order to properly * handle style changes. This means that the dummy widget we create @@ -303,6 +264,8 @@ meta_ui_new (Display *xdisplay, */ gtk_widget_show (GTK_WIDGET (ui->frames)); + gdk_window_add_filter (NULL, ui_filter_func, NULL); + g_object_set_data (G_OBJECT (gdisplay), "meta-ui", ui); return ui; @@ -318,6 +281,8 @@ meta_ui_free (MetaUI *ui) gdisplay = gdk_x11_lookup_xdisplay (ui->xdisplay); g_object_set_data (G_OBJECT (gdisplay), "meta-ui", NULL); + gdk_window_remove_filter (NULL, ui_filter_func, NULL); + g_free (ui); } diff --git a/src/ui/ui.h b/src/ui/ui.h index ca52f4c45..42b2b0975 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -46,13 +46,6 @@ Display* meta_ui_get_display (void); gint meta_ui_get_screen_number (void); -void meta_ui_add_event_func (Display *xdisplay, - MetaEventFunc func, - gpointer data); -void meta_ui_remove_event_func (Display *xdisplay, - MetaEventFunc func, - gpointer data); - MetaUI* meta_ui_new (Display *xdisplay, Screen *screen); void meta_ui_free (MetaUI *ui);