[Spice-devel] spice-html5 cursor positioning problem

Gianni Pirozzi germanium at gmx.us
Fri Sep 12 05:35:37 PDT 2014


Hello,
I also have a cursor positioning problem with spice-html5 which I now realize is layout specific too.

The calculation of the pointer position relative to the canvas in function SpiceMsgcMousePosition (spicemsg.js) seems to rely on the assumptions that:
- the canvas offsetParent is the body or an element with the same position
- only either the body or the root element may have scrolling

The spice screen in my layout is a positioned element and it has its own scrollbars. It is a sort of popup that comes up on top of another page and I need to position other elements relative to it, such as an X button in the top-right corner.

I don't know about performance issues but I would suggest to calculate the pointer position relative to the canvas like this:

  var rect = sc.display.surfaces[sc.display.primary_surface].canvas.getBoundingClientRect();
  this.x = e.clientX - rect.left;
  this.y = e.clientY - rect.top;

instead of like this:

  var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  var scrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
  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;

getBoundingClientRect returns the border-box rectangle relative to the viewport and e.clientX/Y are relative to the viewport too, therefore it should work no matter how many elements are positioned or scrolled (if the canvas had a border you would also subtract clientLeft/Top, but no one is expected to place a border on the canvas).

I'm not sure how SpiceMsgcMouseMotion would be changed since it takes the distance from the offsetParent into account but not any scrolling.
In my tests I couldn't observe that function running (sc.mouse_mode == SPICE_MOUSE_MODE_CLIENT every time I checked). Can someone explain briefly or point me to an explanation about mouse modes and when they are used?

Thanks,
GP


More information about the Spice-devel mailing list