[Spice-devel] [PATCH spice-gtk] win32: implement enabling/disable mouse accel

Marc-André Lureau marcandre.lureau at gmail.com
Thu Oct 18 12:17:22 PDT 2012


https://bugzilla.redhat.com/show_bug.cgi?id=867885
---
 gtk/spice-widget-priv.h |  1 +
 gtk/spice-widget.c      | 56 +++++++++++++++++++++++++++++--------------------
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/gtk/spice-widget-priv.h b/gtk/spice-widget-priv.h
index 4ee0e59..779e435 100644
--- a/gtk/spice-widget-priv.h
+++ b/gtk/spice-widget-priv.h
@@ -114,6 +114,7 @@ struct _SpiceDisplayPrivate {
     gint                    mark;
 #ifdef WIN32
     HHOOK                   keyboard_hook;
+    int                     win_mouse[3];
 #endif
     guint                   keypress_delay;
     gint                    zoom_level;
diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index a2691f7..9a6bfd3 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -689,6 +689,36 @@ static void update_keyboard_grab(SpiceDisplay *display)
         try_keyboard_ungrab(display);
 }
 
+static void set_mouse_accel(SpiceDisplay *display, gboolean enabled)
+{
+    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+
+#if defined GDK_WINDOWING_X11
+    GdkWindow *w = GDK_WINDOW(gtk_widget_get_window(GTK_WIDGET(display)));
+    Display *x_display = GDK_WINDOW_XDISPLAY(w);
+
+    if (enabled) {
+        /* restore mouse acceleration */
+        XChangePointerControl(x_display, True, True,
+                              d->x11_accel_numerator, d->x11_accel_denominator, d->x11_threshold);
+    } else {
+        XGetPointerControl(x_display,
+                           &d->x11_accel_numerator, &d->x11_accel_denominator, &d->x11_threshold);
+        /* set mouse acceleration to default */
+        XChangePointerControl(x_display, True, True, -1, -1, -1);
+        SPICE_DEBUG("disabled X11 mouse motion %d %d %d",
+                    d->x11_accel_numerator, d->x11_accel_denominator, d->x11_threshold);
+    }
+#elif defined GDK_WINDOWING_WIN32
+    if (enabled)
+        SystemParametersInfo(SPI_SETMOUSE, 0, &d->win_mouse, 0);
+    else
+        SystemParametersInfo(SPI_GETMOUSE, 0, &d->win_mouse, 0);
+#else
+    g_warning("Mouse acceleration code missing for your platform");
+#endif
+}
+
 static GdkGrabStatus do_pointer_grab(SpiceDisplay *display)
 {
     SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
@@ -738,19 +768,8 @@ static GdkGrabStatus do_pointer_grab(SpiceDisplay *display)
     }
 #endif
 
-#ifdef GDK_WINDOWING_X11
-    if (status == GDK_GRAB_SUCCESS) {
-        GdkWindow *w = GDK_WINDOW(gtk_widget_get_window(GTK_WIDGET(display)));
-        Display *x_display = GDK_WINDOW_XDISPLAY(w);
-
-        XGetPointerControl(x_display,
-                           &d->x11_accel_numerator, &d->x11_accel_denominator, &d->x11_threshold);
-        /* set mouse acceleration to default */
-        XChangePointerControl(x_display, True, True, -1, -1, -1);
-        SPICE_DEBUG("updated mouse motion %d %d %d",
-                    d->x11_accel_numerator, d->x11_accel_denominator, d->x11_threshold);
-    }
-#endif
+    if (status == GDK_GRAB_SUCCESS)
+        set_mouse_accel(display, FALSE);
 
     gdk_cursor_unref(blank);
     return status;
@@ -838,16 +857,7 @@ static void try_mouse_ungrab(SpiceDisplay *display)
 #ifdef WIN32
     ClipCursor(NULL);
 #endif
-#ifdef GDK_WINDOWING_X11
-    {
-        GdkWindow *w = GDK_WINDOW(gtk_widget_get_window(GTK_WIDGET(display)));
-        Display *x_display = GDK_WINDOW_XDISPLAY(w);
-
-        /* restore mouse acceleration */
-        XChangePointerControl(x_display, True, True,
-                              d->x11_accel_numerator, d->x11_accel_denominator, d->x11_threshold);
-    }
-#endif
+    set_mouse_accel(display, TRUE);
 
     d->mouse_grab_active = false;
 
-- 
1.7.11.7



More information about the Spice-devel mailing list