[Spice-devel] [PATCH spice-gtk] win32: implement enabling/disable mouse accel
Christophe Fergeau
cfergeau at redhat.com
Fri Oct 19 01:47:56 PDT 2012
90% of this patch is code movement that should have been done as a separate
patch, this would make review much easier...
On Thu, Oct 18, 2012 at 09:17:22PM +0200, Marc-André Lureau wrote:
> 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);
http://msdn.microsoft.com/en-us/library/ms940383.aspx says that
SPI_GETMOUSE "Retrieves the two mouse threshold values and the mouse
speed", so I'm not sure how this disables mouse acceleration? Or am I just
misled by the name, and do we want to save the mouse accel parameters on
grab, and restore them at ungrab time? If that's what we are trying to do, then
the code looks good, but maybe things would be more obvious with 2 separate
save_mouse_accel/restore_mouse_accel ?
Christophe
> +#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
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20121019/3e9f3875/attachment.pgp>
More information about the Spice-devel
mailing list