[Spice-devel] [PATCH spice-gtk] Handle grab-broken event

Marc-André Lureau marcandre.lureau at gmail.com
Fri Mar 30 17:06:20 PDT 2012


This fixes the pointer being "trapped" in the center of the screen in
server-side mouse mode. It also correctly inform the client that the
pointer/keyboard is no longer grabbed so it can adjust its UI state
accordingly (remote the "press ctrl+alt to ungrab" messages etc).

I can reproduce only with RHEVM22 host, and a RHEL6 guest, when
switching consoles.
---
 gtk/spice-widget.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 4a907e1..c4ccc56 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -349,6 +349,23 @@ static GdkCursor* get_blank_cursor(void)
     return gdk_cursor_new(GDK_BLANK_CURSOR);
 }
 
+static gboolean grab_broken(SpiceDisplay *self, GdkEventGrabBroken *event,
+                            gpointer user_data G_GNUC_UNUSED)
+{
+    SpiceDisplayPrivate *d = self->priv;
+
+    SPICE_DEBUG("%s (%d)", __FUNCTION__, event->implicit);
+    if (event->keyboard) {
+        d->keyboard_grab_active = false;
+        g_signal_emit(self, signals[SPICE_DISPLAY_KEYBOARD_GRAB], 0, false);
+    } else {
+        d->mouse_grab_active = false;
+        g_signal_emit(self, signals[SPICE_DISPLAY_MOUSE_GRAB], 0, false);
+    }
+
+    return false;
+}
+
 static void spice_display_init(SpiceDisplay *display)
 {
     GtkWidget *widget = GTK_WIDGET(display);
@@ -356,6 +373,7 @@ 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);
     gtk_widget_add_events(widget,
                           GDK_STRUCTURE_MASK |
                           GDK_POINTER_MOTION_MASK |
@@ -368,7 +386,6 @@ static void spice_display_init(SpiceDisplay *display)
     gtk_widget_set_double_buffered(widget, false);
     gtk_widget_set_can_focus(widget, true);
     gtk_widget_set_has_window(widget, true);
-
     d->keycode_map = vnc_display_keymap_gdk2xtkbd_table(&d->keycode_maplen);
     d->grabseq = spice_grab_sequence_new_from_string("Control_L+Alt_L");
     d->activeseq = g_new0(gboolean, d->grabseq->nkeysyms);
-- 
1.7.7.6



More information about the Spice-devel mailing list