From 05ddc913820e69fad0dc878040302a8ea126c853 Mon Sep 17 00:00:00 2001 From: mattmcclaskey Date: Wed, 11 Oct 2023 09:27:04 -0400 Subject: [PATCH] handle window moved to diffent monitor --- core/display.js | 1 + core/rfb.js | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/display.js b/core/display.js index 833128f8..bcf36177 100644 --- a/core/display.js +++ b/core/display.js @@ -204,6 +204,7 @@ export default class Display { this._screens[0].containerWidth = this._target.parentNode.offsetWidth; this._screens[0].width = this._target.parentNode.offsetWidth; this._screens[0].height = this._target.parentNode.offsetHeight; + this._screens[0].pixelRatio = window.devicePixelRatio; //this._screens[0].width = this._target.width; //this._screens[0].height = this._target.height; diff --git a/core/rfb.js b/core/rfb.js index 25872245..cfaa9b98 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -239,6 +239,7 @@ export default class RFB extends EventTargetMixin { handleWheel: this._handleWheel.bind(this), handleGesture: this._handleGesture.bind(this), handleFocusChange: this._handleFocusChange.bind(this), + handleMouseOut: this._handleMouseOut.bind(this), }; // main setup @@ -1163,6 +1164,9 @@ export default class RFB extends EventTargetMixin { window.addEventListener("focus", this._eventHandlers.handleFocusChange); window.addEventListener("blur", this._eventHandlers.handleFocusChange); + //User cursor moves outside of the window + window.addEventListener("mouseover", this._eventHandlers.handleMouseOut); + // In order for the keyboard to not occlude the input being edited // we move the hidden input we use for triggering the keyboard to the last click // position which should trigger a page being moved down enough @@ -1757,7 +1761,6 @@ export default class RFB extends EventTargetMixin { } _handleSecondaryDisplayMessage(event) { - console.log("Message Received: " + event); if (this._isPrimaryDisplay) { } @@ -1796,6 +1799,18 @@ export default class RFB extends EventTargetMixin { this.sendKey(keysym, code, down); } + _handleMouseOut(ev) { + if (ev.toElement !== null && ev.relatedTarget === null) { + //mouse was outside of the window and just came in, this is our chance to do things + + //Ensure the window was not moved to a different screen with a different pixel ratio + if (this._display.screens[0].pixelRatio !== window.devicePixelRatio) { + Log.Debug("Window moved to another screen with different pixel ratio, sending resize request."); + this._requestRemoteResize(); + } + } + } + _handleMouse(ev) { /* * We don't check connection status or viewOnly here as the @@ -4286,7 +4301,6 @@ RFB.messages = { }, setDesktopSize(sock, size, flags) { - console.log(size); const buff = sock._sQ; const offset = sock._sQlen;