[Spice-devel] [PATCH spice-gtk] widget: don't grab mouse when switching to server mode

Marc-André Lureau marcandre.lureau at gmail.com
Mon Apr 29 16:44:25 PDT 2013


spice-gtk used to try taking the grab when switching to server mode, so
that the current mouse interaction, ex a drag, isn't interrupted if the
agent dies. However, shuting down a VM will automatically try taking the
grab when the is no tablet input, and agent exits.

Some users are complaining about it (especially when they don't know the
ungrab combination).

Instead, let's try to keep the grab only if we have currently a mouse
button pressed.

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

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index d260367..b882106 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -1999,10 +1999,14 @@ static void spice_display_class_init(SpiceDisplayClass *klass)
 
 /* ---------------------------------------------------------------- */
 
+#define SPICE_GDK_BUTTONS_MASK \
+    (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK|GDK_BUTTON3_MASK|GDK_BUTTON4_MASK|GDK_BUTTON5_MASK)
+
 static void update_mouse_mode(SpiceChannel *channel, gpointer data)
 {
     SpiceDisplay *display = data;
     SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+    GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(display));
 
     g_object_get(channel, "mouse-mode", &d->mouse_mode, NULL);
     SPICE_DEBUG("mouse mode %d", d->mouse_mode);
@@ -2012,9 +2016,16 @@ static void update_mouse_mode(SpiceChannel *channel, gpointer data)
         try_mouse_ungrab(display);
         break;
     case SPICE_MOUSE_MODE_SERVER:
-        try_mouse_grab(display);
         d->mouse_guest_x = -1;
         d->mouse_guest_y = -1;
+
+        if (window != NULL) {
+            GdkModifierType modifiers;
+            gdk_window_get_pointer(window, NULL, NULL, &modifiers);
+
+            if (modifiers & SPICE_GDK_BUTTONS_MASK)
+                try_mouse_grab(display);
+        }
         break;
     default:
         g_warn_if_reached();
-- 
1.8.2.1.342.gfa7285d



More information about the Spice-devel mailing list