Skip to content

Commit

Permalink
Merge pull request novnc#1352 from uklatt/master
Browse files Browse the repository at this point in the history
Limit mouse move events to one every 17 mS.
  • Loading branch information
samhed authored May 1, 2020
2 parents e7fa686 + 44eb1fe commit c958269
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion core/input/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { setCapture, stopEvent, getPointerEvent } from '../util/events.js';
const WHEEL_STEP = 10; // Delta threshold for a mouse wheel step
const WHEEL_STEP_TIMEOUT = 50; // ms
const WHEEL_LINE_HEIGHT = 19;
const MOUSE_MOVE_DELAY = 17; // Minimum wait (ms) between two mouse moves

export default class Mouse {
constructor(target) {
Expand All @@ -22,6 +23,7 @@ export default class Mouse {
this._pos = null;
this._wheelStepXTimer = null;
this._wheelStepYTimer = null;
this._oldMouseMoveTime = 0;
this._accumulatedWheelDeltaX = 0;
this._accumulatedWheelDeltaY = 0;

Expand Down Expand Up @@ -195,7 +197,19 @@ export default class Mouse {

_handleMouseMove(e) {
this._updateMousePosition(e);
this.onmousemove(this._pos.x, this._pos.y);

// Limit mouse move events to one every MOUSE_MOVE_DELAY ms
clearTimeout(this.mouseMoveTimer);
const newMouseMoveTime = Date.now();
if (newMouseMoveTime < this._oldMouseMoveTime + MOUSE_MOVE_DELAY) {
this.mouseMoveTimer = setTimeout(this.onmousemove.bind(this),
MOUSE_MOVE_DELAY,
this._pos.x, this._pos.y);
} else {
this.onmousemove(this._pos.x, this._pos.y);
}
this._oldMouseMoveTime = newMouseMoveTime;

stopEvent(e);
}

Expand Down

0 comments on commit c958269

Please sign in to comment.