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:
parent
b2405b701a
commit
afce448281
@ -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;
|
||||
}
|
||||
|
55
src/ui/ui.c
55
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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user