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.
This commit is contained in:
Jasper St. Pierre 2014-03-30 20:58:11 -04:00
parent b2405b701a
commit afce448281
3 changed files with 20 additions and 62 deletions

View File

@ -2124,13 +2124,17 @@ meta_display_handle_event (MetaDisplay *display,
return bypass_clutter; return bypass_clutter;
} }
static gboolean static GdkFilterReturn
xevent_callback (XEvent *event, xevent_filter (GdkXEvent *xevent,
gpointer data) GdkEvent *event,
gpointer data)
{ {
MetaDisplay *display = 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 static gboolean
@ -2145,9 +2149,7 @@ event_callback (const ClutterEvent *event,
void void
meta_display_init_events (MetaDisplay *display) meta_display_init_events (MetaDisplay *display)
{ {
meta_ui_add_event_func (display->xdisplay, gdk_window_add_filter (NULL, xevent_filter, display);
xevent_callback,
display);
display->clutter_event_filter = clutter_event_add_filter (NULL, display->clutter_event_filter = clutter_event_add_filter (NULL,
event_callback, event_callback,
NULL, NULL,
@ -2157,9 +2159,7 @@ meta_display_init_events (MetaDisplay *display)
void void
meta_display_free_events (MetaDisplay *display) meta_display_free_events (MetaDisplay *display)
{ {
meta_ui_remove_event_func (display->xdisplay, gdk_window_remove_filter (NULL, xevent_filter, display);
xevent_callback,
display);
clutter_event_remove_filter (display->clutter_event_filter); clutter_event_remove_filter (display->clutter_event_filter);
display->clutter_event_filter = 0; display->clutter_event_filter = 0;
} }

View File

@ -228,58 +228,17 @@ maybe_redirect_mouse_event (XEvent *xevent)
return TRUE; return TRUE;
} }
typedef struct _EventFunc EventFunc;
struct _EventFunc
{
MetaEventFunc func;
gpointer data;
};
static EventFunc *ef = NULL;
static GdkFilterReturn static GdkFilterReturn
filter_func (GdkXEvent *xevent, ui_filter_func (GdkXEvent *xevent,
GdkEvent *event, GdkEvent *event,
gpointer data) gpointer data)
{ {
g_return_val_if_fail (ef != NULL, GDK_FILTER_CONTINUE); if (maybe_redirect_mouse_event (xevent))
if ((* ef->func) (xevent, ef->data) ||
maybe_redirect_mouse_event (xevent))
return GDK_FILTER_REMOVE; return GDK_FILTER_REMOVE;
else else
return GDK_FILTER_CONTINUE; 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* MetaUI*
meta_ui_new (Display *xdisplay, meta_ui_new (Display *xdisplay,
Screen *screen) Screen *screen)
@ -294,6 +253,8 @@ meta_ui_new (Display *xdisplay,
gdisplay = gdk_x11_lookup_xdisplay (xdisplay); gdisplay = gdk_x11_lookup_xdisplay (xdisplay);
g_assert (gdisplay == gdk_display_get_default ()); g_assert (gdisplay == gdk_display_get_default ());
gdk_window_add_filter (NULL, ui_filter_func, NULL);
ui->frames = meta_frames_new (XScreenNumberOfScreen (screen)); ui->frames = meta_frames_new (XScreenNumberOfScreen (screen));
/* GTK+ needs the frame-sync protocol to work in order to properly /* GTK+ needs the frame-sync protocol to work in order to properly
* handle style changes. This means that the dummy widget we create * 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)); 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); g_object_set_data (G_OBJECT (gdisplay), "meta-ui", ui);
return ui; return ui;
@ -318,6 +281,8 @@ meta_ui_free (MetaUI *ui)
gdisplay = gdk_x11_lookup_xdisplay (ui->xdisplay); gdisplay = gdk_x11_lookup_xdisplay (ui->xdisplay);
g_object_set_data (G_OBJECT (gdisplay), "meta-ui", NULL); g_object_set_data (G_OBJECT (gdisplay), "meta-ui", NULL);
gdk_window_remove_filter (NULL, ui_filter_func, NULL);
g_free (ui); g_free (ui);
} }

View File

@ -46,13 +46,6 @@ Display* meta_ui_get_display (void);
gint meta_ui_get_screen_number (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, MetaUI* meta_ui_new (Display *xdisplay,
Screen *screen); Screen *screen);
void meta_ui_free (MetaUI *ui); void meta_ui_free (MetaUI *ui);