From 94021a7d359b33af282f1c5eeb516d3783f1c63e Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <1446935823@qq.com> Date: Thu, 5 Sep 2024 16:03:21 +0000 Subject: [PATCH 1/3] Added resize browser mode --- NewWindow.html | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ app/ui.js | 38 ++++++++++++++++++++++++++++ core/rfb.js | 13 ++++++++++ 3 files changed, 118 insertions(+) create mode 100644 NewWindow.html diff --git a/NewWindow.html b/NewWindow.html new file mode 100644 index 000000000..a8f0acf00 --- /dev/null +++ b/NewWindow.html @@ -0,0 +1,67 @@ + + + + noVNC + + + +
+ +
+ + + + \ No newline at end of file diff --git a/app/ui.js b/app/ui.js index 71933af63..a3840cbde 100644 --- a/app/ui.js +++ b/app/ui.js @@ -42,6 +42,10 @@ const UI = { reconnectCallback: null, reconnectPassword: null, + // Old browser resolution + bodyWidth_browser_resize: 0, + bodyHeight_browser_resize: 0, + prime() { return WebUtil.initSettings().then(() => { if (document.readyState === "interactive" || document.readyState === "complete") { @@ -988,6 +992,28 @@ const UI = { .classList.remove("noVNC_open"); }, + _updateBrowserWindows(width, height) { + let bodyWidth = document.body.clientWidth; + let bodyHeight = document.body.clientHeight; + + let OldResolutionEqual = false; + if (UI.bodyWidth_browser_resize === document.body.clientWidth && + UI.bodyHeight_browser_resize === document.body.clientHeight) { + OldResolutionEqual = true; + } + if (UI.bodyHeight_browser_resize === 0 || + OldResolutionEqual) { + if((width != 0) && (height != 0)) { + window.resizeBy(width - bodyWidth, height - bodyHeight); + UI.bodyWidth_browser_resize = width; + UI.bodyHeight_browser_resize = height; + } + } else { + // disabled + UI.bodyWidth_browser_resize = 0; + } + }, + connect(event, password) { // Ignore when rfb already exists @@ -1058,6 +1084,12 @@ const UI = { UI.rfb.clipViewport = UI.getSetting('view_clip'); UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale'; UI.rfb.resizeSession = UI.getSetting('resize') === 'remote'; + if (UI.getSetting('resize') === 'off') { + UI.bodyHeight_browser_resize = 0; + UI.rfb.resizeBrowser = UI._updateBrowserWindows; + } else { + UI.rfb.resizeBrowser = false; + } UI.rfb.qualityLevel = parseInt(UI.getSetting('quality')); UI.rfb.compressionLevel = parseInt(UI.getSetting('compression')); UI.rfb.showDotCursor = UI.getSetting('show_dot'); @@ -1311,6 +1343,12 @@ const UI = { UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale'; UI.rfb.resizeSession = UI.getSetting('resize') === 'remote'; + if (UI.getSetting('resize') === 'off') { + UI.bodyHeight_browser_resize = 0; + UI.rfb.resizeBrowser = UI._updateBrowserWindows; + } else { + UI.rfb.resizeBrowser = false; + } }, /* ------^------- diff --git a/core/rfb.js b/core/rfb.js index 0007bed86..447abc45e 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -294,6 +294,7 @@ export default class RFB extends EventTargetMixin { this._clippingViewport = false; this._scaleViewport = false; this._resizeSession = false; + this._resizeBrowser = false; this._showDotCursor = false; if (options.showDotCursor !== undefined) { @@ -364,6 +365,14 @@ export default class RFB extends EventTargetMixin { } } + get resizeBrowser() { return this._resizeBrowser; } + set resizeBrowser(void_) { + this._resizeBrowser = void_; + if(this._resizeBrowser && (this._rfbConnectionState === 'connected')){ + this._resizeBrowser(this._fbWidth, this._fbHeight); + } + } + get showDotCursor() { return this._showDotCursor; } set showDotCursor(show) { this._showDotCursor = show; @@ -2875,6 +2884,10 @@ export default class RFB extends EventTargetMixin { this._fbWidth = width; this._fbHeight = height; + if (this._resizeBrowser) { + this._resizeBrowser(width, height); + } + this._display.resize(this._fbWidth, this._fbHeight); // Adjust the visible viewport based on the new dimensions From 1f6913bb2775a43b64c37661463559c8bf8b62a3 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <1446935823@qq.com> Date: Thu, 5 Sep 2024 16:07:13 +0000 Subject: [PATCH 2/3] Dealing with Lint issues --- app/ui.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/ui.js b/app/ui.js index a3840cbde..2cd0cb00d 100644 --- a/app/ui.js +++ b/app/ui.js @@ -43,8 +43,8 @@ const UI = { reconnectPassword: null, // Old browser resolution - bodyWidth_browser_resize: 0, - bodyHeight_browser_resize: 0, + bodyWidthBrowserResize: 0, + bodyHeightBrowserResize: 0, prime() { return WebUtil.initSettings().then(() => { @@ -997,20 +997,20 @@ const UI = { let bodyHeight = document.body.clientHeight; let OldResolutionEqual = false; - if (UI.bodyWidth_browser_resize === document.body.clientWidth && - UI.bodyHeight_browser_resize === document.body.clientHeight) { + if (UI.bodyWidthBrowserResize === document.body.clientWidth && + UI.bodyHeightBrowserResize === document.body.clientHeight) { OldResolutionEqual = true; } - if (UI.bodyHeight_browser_resize === 0 || + if (UI.bodyHeightBrowserResize === 0 || OldResolutionEqual) { if((width != 0) && (height != 0)) { window.resizeBy(width - bodyWidth, height - bodyHeight); - UI.bodyWidth_browser_resize = width; - UI.bodyHeight_browser_resize = height; + UI.bodyWidthBrowserResize = width; + UI.bodyHeightBrowserResize = height; } } else { // disabled - UI.bodyWidth_browser_resize = 0; + UI.bodyWidthBrowserResize = 0; } }, @@ -1085,7 +1085,7 @@ const UI = { UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale'; UI.rfb.resizeSession = UI.getSetting('resize') === 'remote'; if (UI.getSetting('resize') === 'off') { - UI.bodyHeight_browser_resize = 0; + UI.bodyHeightBrowserResize = 0; UI.rfb.resizeBrowser = UI._updateBrowserWindows; } else { UI.rfb.resizeBrowser = false; @@ -1344,7 +1344,7 @@ const UI = { UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale'; UI.rfb.resizeSession = UI.getSetting('resize') === 'remote'; if (UI.getSetting('resize') === 'off') { - UI.bodyHeight_browser_resize = 0; + UI.bodyHeightBrowserResize = 0; UI.rfb.resizeBrowser = UI._updateBrowserWindows; } else { UI.rfb.resizeBrowser = false; From 9edae1da0900fb4805597316a64e47845bd2d865 Mon Sep 17 00:00:00 2001 From: XiaoXianNv-boot <1446935823@qq.com> Date: Thu, 5 Sep 2024 16:13:09 +0000 Subject: [PATCH 3/3] Dealing with Lint issues --- NewWindow.html | 4 ++-- app/ui.js | 6 +++--- core/rfb.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NewWindow.html b/NewWindow.html index a8f0acf00..ddbfa4928 100644 --- a/NewWindow.html +++ b/NewWindow.html @@ -9,11 +9,11 @@