From ace35fa6529dbe6a55a385beee8e2948a64e2a62 Mon Sep 17 00:00:00 2001 From: Mariusz Marciniak Date: Mon, 30 Aug 2021 21:10:55 +0200 Subject: [PATCH] KASM-1882 MacOs pinch and zoom --- core/rfb.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/rfb.js b/core/rfb.js index da8ce5be..cf9cccaf 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -176,12 +176,26 @@ export default class RFB extends EventTargetMixin { this._mousePos = {}; this._mouseButtonMask = 0; this._mouseLastMoveTime = 0; + this._mouseLastPinchAndZoomTime = 0; this._viewportDragging = false; this._viewportDragPos = {}; this._viewportHasMoved = false; this._accumulatedWheelDeltaX = 0; this._accumulatedWheelDeltaY = 0; + // On MacOs we simulate the CTRL key being pressed on pinch and zoom + // so we need to manually unselect it whenever the action is completed (500ms since last scroll) + if (isMac()) { + setInterval(() => { + const timeSinceLastPinchAndZoom = Math.max(0, +new Date() - this._mouseLastPinchAndZoomTime); + + if (timeSinceLastPinchAndZoom > 500) { + this._keyboard._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", false); + this._mouseLastPinchAndZoomTime = Infinity; + } + }, 10); + } + // Gesture state this._gestureLastTapTime = null; this._gestureFirstDoubleTapEv = null; @@ -1346,6 +1360,12 @@ export default class RFB extends EventTargetMixin { this._keyboard._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true); } + // On MacOs we need to send a CTRL key to let the remote know we are pinch and zooming + if (isMac() && ev.ctrlKey && !this._keyboard._keyDownList["ControlLeft"]) { + this._keyboard._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true); + this._mouseLastPinchAndZoomTime = +new Date(); + } + // Generate a mouse wheel step event when the accumulated delta // for one of the axes is large enough. if (Math.abs(this._accumulatedWheelDeltaX) >= WHEEL_STEP) {