[Spice-commits] src/spicemsg.js

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Feb 18 16:18:53 UTC 2019


 src/spicemsg.js |   18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

New commits:
commit 54755c2565d41815806c18c325ca32dad3d5e69c
Author: Cédric Bosdonnat <cbosdonnat at suse.com>
Date:   Thu Feb 14 10:44:56 2019 +0100

    More reliable mouse position reporting
    
    Depending on the structure of the page, the computed mouse position was
    not correct. Typically the case happend when there is no offset between
    the canvas and the view area, but an offset on the view area.
    
    The MouseEvent.offsetX and offsetY functions are now widely enough spread
    to use them and avoid complex computations.

diff --git a/src/spicemsg.js b/src/spicemsg.js
index f1b4c74..23ee9c7 100644
--- a/src/spicemsg.js
+++ b/src/spicemsg.js
@@ -952,13 +952,11 @@ function SpiceMsgcMousePosition(sc, e)
     this.buttons_state = sc.buttons_state;
     if (e)
     {
-        var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
-        var scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
+        this.x = e.offsetX;
+        this.y = e.offsetY;
 
-        this.x = e.clientX - sc.display.surfaces[sc.display.primary_surface].canvas.offsetLeft + scrollLeft;
-        this.y = e.clientY - sc.display.surfaces[sc.display.primary_surface].canvas.offsetTop + scrollTop;
-        sc.mousex = this.x;
-        sc.mousey = this.y;
+        sc.mousex = e.offsetX;
+        sc.mousey = e.offsetY;
     }
     else
     {
@@ -991,16 +989,16 @@ function SpiceMsgcMouseMotion(sc, e)
     this.buttons_state = sc.buttons_state;
     if (e)
     {
-        this.x = e.clientX - sc.display.surfaces[sc.display.primary_surface].canvas.offsetLeft;
-        this.y = e.clientY - sc.display.surfaces[sc.display.primary_surface].canvas.offsetTop;
+        this.x = e.offsetX;
+        this.y = e.offsetY;
 
         if (sc.mousex !== undefined)
         {
             this.x -= sc.mousex;
             this.y -= sc.mousey;
         }
-        sc.mousex = e.clientX - sc.display.surfaces[sc.display.primary_surface].canvas.offsetLeft;
-        sc.mousey = e.clientY - sc.display.surfaces[sc.display.primary_surface].canvas.offsetTop;
+        sc.mousex = e.offsetX;
+        sc.mousey = e.offsetY;
     }
     else
     {


More information about the Spice-commits mailing list