[Spice-devel] [PATCH spice-gtk] widget: release keys when the grab is taken elsewhere

Marc-André Lureau marcandre.lureau at gmail.com
Thu May 9 06:26:05 PDT 2013


gtk may propagate some press event up to the Spice display widget, but
a widget may take focus and grab the release event, so the guest will
keep seeing the key pressed.

Releasing the keys when the grab is taken solves two menu-related bugs:

https://bugzilla.redhat.com/show_bug.cgi?id=820829
https://bugzilla.redhat.com/show_bug.cgi?id=924577
---
 gtk/spice-widget.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 1efbb02..3253caa 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -137,6 +137,7 @@ static void channel_destroy(SpiceSession *s, SpiceChannel *channel, gpointer dat
 static void sync_keyboard_lock_modifiers(SpiceDisplay *display);
 static void cursor_invalidate(SpiceDisplay *display);
 static void update_area(SpiceDisplay *display, gint x, gint y, gint width, gint height);
+static void release_keys(SpiceDisplay *display);
 
 /* ---------------------------------------------------------------- */
 
@@ -533,6 +534,14 @@ static void drag_data_received_callback(SpiceDisplay *self,
     gtk_drag_finish(drag_context, TRUE, FALSE, time);
 }
 
+static void grab_notify(SpiceDisplay *display, gboolean was_grabbed)
+{
+    SPICE_DEBUG("grab notify %d", was_grabbed);
+
+    if (was_grabbed == FALSE)
+        release_keys(display);
+}
+
 static void spice_display_init(SpiceDisplay *display)
 {
     GtkWidget *widget = GTK_WIDGET(display);
@@ -542,9 +551,12 @@ static void spice_display_init(SpiceDisplay *display)
     d = display->priv = SPICE_DISPLAY_GET_PRIVATE(display);
 
     g_signal_connect(display, "grab-broken-event", G_CALLBACK(grab_broken), NULL);
+    g_signal_connect(display, "grab-notify", G_CALLBACK(grab_notify), NULL);
+
     gtk_drag_dest_set(widget, GTK_DEST_DEFAULT_ALL, &targets, 1, GDK_ACTION_COPY);
     g_signal_connect(display, "drag-data-received",
                      G_CALLBACK(drag_data_received_callback), NULL);
+
     gtk_widget_add_events(widget,
                           GDK_STRUCTURE_MASK |
                           GDK_POINTER_MOTION_MASK |
-- 
1.8.2.1.342.gfa7285d



More information about the Spice-devel mailing list