[Spice-devel] [PATCH spice-gtk 1/2] gtk: keep cursor in the same place on ungrab

Marc-André Lureau marcandre.lureau at gmail.com
Fri Oct 24 09:34:16 PDT 2014


On ungrab, the transition from remote (server-side) cursor to host
cursor makes it jump somewhere else rather than staying at the same
place. Restore cursor position on ungrab to match with guest position.

https://bugs.freedesktop.org/show_bug.cgi?id=85117
---
 gtk/spice-widget.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 1220030..85757cb 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -992,6 +992,8 @@ static void mouse_wrap(SpiceDisplay *display, GdkEventMotion *motion)
 static void try_mouse_ungrab(SpiceDisplay *display)
 {
     SpiceDisplayPrivate *d = display->priv;
+    double s;
+    int x, y;
 
     if (!d->mouse_grab_active)
         return;
@@ -1005,6 +1007,17 @@ static void try_mouse_ungrab(SpiceDisplay *display)
 
     d->mouse_grab_active = false;
 
+    spice_display_get_scaling(display, &s, &x, &y, NULL, NULL);
+
+    gdk_window_get_root_coords(gtk_widget_get_window(GTK_WIDGET(display)),
+                               x + d->mouse_guest_x * s,
+                               y + d->mouse_guest_y * s,
+                               &x, &y);
+
+    GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(display));
+    gdk_display_warp_pointer(gtk_widget_get_display(GTK_WIDGET(display)),
+                             screen, x, y);
+
     g_signal_emit(display, signals[SPICE_DISPLAY_MOUSE_GRAB], 0, false);
 }
 
-- 
1.9.3



More information about the Spice-devel mailing list