Skip to content

Commit

Permalink
Adjust cursor coordinates by hotspot.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Feb 4, 2024
1 parent 6175985 commit 2c11e27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,11 @@ export default class RFB extends EventTargetMixin {
// Finally, translate the coordinates to those relative to the
// canvas and send the pointer move event to the remote machine.
const posFromCanvas = clientToElement(safeX, safeY, this._canvas);
this._sendMouse(posFromCanvas.x, posFromCanvas.y, this._mouseButtonMask);
const hotspot = this._cursor.hotspot;
this._sendMouse(
posFromCanvas.x + hotspot.x,
posFromCanvas.y + hotspot.y,
this._mouseButtonMask);
}

_handleTouchpadOneTapEvent() {
Expand Down Expand Up @@ -1616,7 +1620,10 @@ export default class RFB extends EventTargetMixin {
* @returns {{x: number, y: number}}
*/
_getCursorPositionToCanvas() {
const cursorPos = this._cursor.position;
const cursorPos = {
x: this._cursor.position.x + this._cursor.hotspot.x,
y: this._cursor.position.y + this._cursor.hotspot.y
};
return clientToElement(cursorPos.x, cursorPos.y, this._canvas);
}

Expand Down
7 changes: 7 additions & 0 deletions core/util/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export default class Cursor {
get position() {
return this._position;
}

/**
* @returns {{ x: number, y: number }}
*/
get hotspot() {
return this._hotSpot;
}

attach(target) {
if (this._target) {
Expand Down

0 comments on commit 2c11e27

Please sign in to comment.