From 6383fa6384ed672c83f63693cdc3609851889a0a Mon Sep 17 00:00:00 2001 From: Adam Halim Date: Tue, 14 Jan 2025 12:32:51 +0100 Subject: [PATCH] Flush mouseMove when initiating viewport dragging We want to flush pending mouse moves before we initiate viewport dragging. Before this commit, there were scenarios where the _mouseButtonMask would track a released button as being down. --- core/rfb.js | 2 ++ tests/test.rfb.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/core/rfb.js b/core/rfb.js index 5e08e32f5..89e9197d2 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -1103,6 +1103,8 @@ export default class RFB extends EventTargetMixin { this._viewportDragPos = {'x': pos.x, 'y': pos.y}; this._viewportHasMoved = false; + this._flushMouseMoveTimer(pos.x, pos.y); + // Skip sending mouse events, instead save the current // mouse mask so we can send it later. this._mouseButtonMask = bmask; diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 85c9eb66b..62f2a6498 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -898,6 +898,24 @@ describe('Remote Frame Buffer protocol client', function () { expect(client._display.viewportChangePos).to.not.have.been.called; }); + + it('should flush move events when initiating viewport drag', function () { + sendMouseMoveEvent(13, 9, 0x0, client); + sendMouseMoveEvent(14, 9, 0x0, client); + sendMouseButtonEvent(14, 9, true, 0x1, client); + + expect(RFB.messages.pointerEvent).to.have.been.calledTwice; + expect(RFB.messages.pointerEvent.firstCall).to.have.been.calledWith(client._sock, + 13, 9, 0x0); + expect(RFB.messages.pointerEvent.secondCall).to.have.been.calledWith(client._sock, + 14, 9, 0x0); + + RFB.messages.pointerEvent.resetHistory(); + + clock.tick(100); + + expect(RFB.messages.pointerEvent).to.not.have.been.called;; + }); }); });