From 61a8166c4fda5e3486ae9d19ff102e36a14bfcb0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 22 Feb 2013 18:14:30 +0000 Subject: Maybe fix crash on close caused by key filter for X11 in Gtk. git-svn-id: http://svn.drobilla.net/lad/trunk/suil@5063 a436a847-0d15-0410-975c-d299462d15a1 --- AUTHORS | 1 + NEWS | 3 ++- src/x11_in_gtk2.c | 39 ++++++++++++++++++++++----------------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/AUTHORS b/AUTHORS index 70cccdb..2a82a14 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,3 +6,4 @@ Contributors: * Fix reparenting of Gtk UIs in Qt * Peter Nelson * Fix crash when a broken UI returns a NULL descriptor + * Fix crash on close caused by key filter for X11 in Gtk diff --git a/NEWS b/NEWS index 05183e9..4df90a0 100644 --- a/NEWS +++ b/NEWS @@ -1,10 +1,11 @@ suil (0.6.11) unstable; * Add compile time option to disable explicit Gtk to X11 key forwarding + * Fix crash on close caused by key filter for X11 in Gtk * Fix crash when a broken UI returns a NULL descriptor * Fix compilation on BSD - -- David Robillard Fri, 22 Feb 2013 12:51:26 -0500 + -- David Robillard Fri, 22 Feb 2013 13:03:48 -0500 suil (0.6.10) stable; diff --git a/src/x11_in_gtk2.c b/src/x11_in_gtk2.c index 2e3cdf9..0adc408 100644 --- a/src/x11_in_gtk2.c +++ b/src/x11_in_gtk2.c @@ -42,11 +42,33 @@ GType suil_x11_wrapper_get_type(void); // Accessor for SUIL_TYPE_X11_WRAPPER G_DEFINE_TYPE(SuilX11Wrapper, suil_x11_wrapper, GTK_TYPE_SOCKET) +#ifdef SUIL_FORWARD_KEYS +static GdkFilterReturn +event_filter(GdkXEvent* xevent, GdkEvent* event, gpointer data) +{ + SuilX11Wrapper* wrap = (SuilX11Wrapper*)data; + XEvent* ev = (XEvent*)xevent; + if (wrap->instance && + wrap->instance->handle && + (ev->type == KeyPress || ev->type == KeyRelease)) { + // Forward keyboard events to UI window + XSendEvent(ev->xkey.display, (Window)wrap->instance->ui_widget, 1, 0, ev); + XSync(ev->xkey.display, TRUE); + } + return GDK_FILTER_CONTINUE; +} +#endif + static gboolean on_plug_removed(GtkSocket* sock, gpointer data) { SuilX11Wrapper* const self = SUIL_X11_WRAPPER(sock); +#ifdef SUIL_FORWARD_KEYS + GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(self)); + gdk_window_remove_filter(window, event_filter, self); +#endif + if (self->instance->handle) { self->instance->descriptor->cleanup(self->instance->handle); self->instance->handle = NULL; @@ -130,23 +152,6 @@ wrapper_free(SuilWrapper* wrapper) } } -#ifdef SUIL_FORWARD_KEYS -static GdkFilterReturn -event_filter(GdkXEvent* xevent, GdkEvent* event, gpointer data) -{ - SuilX11Wrapper* wrap = (SuilX11Wrapper*)data; - XEvent* ev = (XEvent*)xevent; - if (wrap->instance && - wrap->instance->handle && - (ev->type == KeyPress || ev->type == KeyRelease)) { - // Forward keyboard events to UI window - XSendEvent(ev->xkey.display, (Window)wrap->instance->ui_widget, 1, 0, ev); - XSync(ev->xkey.display, TRUE); - } - return GDK_FILTER_CONTINUE; -} -#endif - SUIL_LIB_EXPORT SuilWrapper* suil_wrapper_new(SuilHost* host, -- cgit v1.2.1