[Spice-commits] 2 commits - gtk/spice-widget.c

Hans de Goede jwrdegoede at kemper.freedesktop.org
Tue Apr 3 00:20:43 PDT 2012


 gtk/spice-widget.c |   22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

New commits:
commit 215065514cf220a1e945e29a6f74c92eacfb761e
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Mon Apr 2 17:10:10 2012 +0200

    SpiceDisplay: Fix rounding of mouse motion events with GTK-3.0
    
    Before this patch we were assuming that the GdkEventMotion value we receive
    are always whole (integer) numbers, which is not the case with GTK-3.0.
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 28e8a7d..ff361bf 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -1160,11 +1160,21 @@ static gboolean motion_event(GtkWidget *widget, GdkEventMotion *motion)
         sx = (double)d->width / (double)ww;
         sy = (double)d->height / (double)wh;
 
-        /* Scaling the desktop, so scale the mouse coords by same
-         * ratio - ceil() seems to be more accurate - not sure
-         * though - scaling is more likely reversible.. */
-        motion->x = ceil(motion->x * sx);
-        motion->y = ceil(motion->y * sy);
+        /* Scaling the desktop, so scale the mouse coords by the same.
+         * Ratio for the rounding used:
+         * 1) We should be able to send mouse coords for all 4 corner pixels
+         * 2) The GdkMotion events are double's, so we've X.Xfrac and Y.Yfrac
+         * 3) The X and Y integer values always go from 0 - (ww/wh - 1)
+         * 4) Note that even if Xfrac = .99999, X will still go from 0 - (ww-1)
+         *    so x will go from 0.99999 - (ww-1).99999
+         * 5) Given 4, the only way to be sure we can always generate 0
+         *    coordinates is to first floor the input coordinates
+         * 6) To avoid rounding errors causing us to be unable to generate
+         *    coordinates for the bottom row / left column of pixels we ceil
+         *    the end result
+         */
+        motion->x = ceil(floor(motion->x) * sx);
+        motion->y = ceil(floor(motion->y) * sy);
     } else {
         motion->x -= d->mx;
         motion->y -= d->my;
commit 5d773be6ebb274432a66cfb50947c51628fd8fd0
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Mon Apr 2 16:52:54 2012 +0200

    SpiceDisplay: Don't try to scale mouse coordinates when we're not scaling
    
    Often (when not resized by the user) even though scaling is enabled, we are
    not actually scaling. In this case it is not necessary to scale the
    mouse coordinates, and sometimes it is even harmful.
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 0defb60..28e8a7d 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -1155,7 +1155,7 @@ static gboolean motion_event(GtkWidget *widget, GdkEventMotion *motion)
         return true;
 
     gdk_drawable_get_size(gtk_widget_get_window(widget), &ww, &wh);
-    if (spicex_is_scaled(display)) {
+    if (spicex_is_scaled(display) && (d->width != ww || d->height != wh)) {
         double sx, sy;
         sx = (double)d->width / (double)ww;
         sy = (double)d->height / (double)wh;


More information about the Spice-commits mailing list