From d9ea4b873a5214110c0f1d974c9a9c3017473502 Mon Sep 17 00:00:00 2001 From: El Date: Tue, 8 Jul 2025 03:07:20 +0500 Subject: [PATCH 1/4] VNC-132 Fix monitor addition bug --- app/ui.js | 3 +++ core/display.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/ui.js b/app/ui.js index da9f67d9c..8724d2acf 100644 --- a/app/ui.js +++ b/app/ui.js @@ -1458,6 +1458,9 @@ const UI = { } url += '/' + path; + UI.monitors = []; + UI.sortedMonitors = []; + UI.rfb = new RFB(document.getElementById('noVNC_container'), document.getElementById('noVNC_keyboardinput'), url, diff --git a/core/display.js b/core/display.js index c635caf3b..1f342a9e8 100644 --- a/core/display.js +++ b/core/display.js @@ -473,7 +473,7 @@ export default class Display { for (let i=1; i 0) { - this._screens[i].channel.postMessage({ eventType: "registered", screenIndex: i }); + this._screens[i].channel?.postMessage({ eventType: "registered", screenIndex: i }); } } return removed; From 001f0a1b0f117410c17518f18b425beb4f917258 Mon Sep 17 00:00:00 2001 From: El Date: Tue, 8 Jul 2025 03:20:21 +0500 Subject: [PATCH 2/4] Revert "VNC-132 Fix monitor addition bug" This reverts commit 3c37ed2aeb59423becec7e039c172858fc4e56e3. --- app/ui.js | 3 --- core/display.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/ui.js b/app/ui.js index 8724d2acf..da9f67d9c 100644 --- a/app/ui.js +++ b/app/ui.js @@ -1458,9 +1458,6 @@ const UI = { } url += '/' + path; - UI.monitors = []; - UI.sortedMonitors = []; - UI.rfb = new RFB(document.getElementById('noVNC_container'), document.getElementById('noVNC_keyboardinput'), url, diff --git a/core/display.js b/core/display.js index 1f342a9e8..c635caf3b 100644 --- a/core/display.js +++ b/core/display.js @@ -473,7 +473,7 @@ export default class Display { for (let i=1; i 0) { - this._screens[i].channel?.postMessage({ eventType: "registered", screenIndex: i }); + this._screens[i].channel.postMessage({ eventType: "registered", screenIndex: i }); } } return removed; From f1c60667f485a46e5fe0bb73f164ab2428b19091 Mon Sep 17 00:00:00 2001 From: El Date: Tue, 8 Jul 2025 14:37:04 +0500 Subject: [PATCH 3/4] VNC-212 Fix monitors addition issue --- app/ui.js | 26 ++++++++++++++++++-------- core/display.js | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/ui.js b/app/ui.js index da9f67d9c..168328ca4 100644 --- a/app/ui.js +++ b/app/ui.js @@ -1458,6 +1458,8 @@ const UI = { } url += '/' + path; + UI.monitors = []; + UI.sortedMonitors = []; UI.rfb = new RFB(document.getElementById('noVNC_container'), document.getElementById('noVNC_keyboardinput'), url, @@ -1657,6 +1659,8 @@ const UI = { UI.connected = false; UI.rfb = undefined; + UI.monitors = []; + UI.sortedMonitors = []; if (!e.detail.clean) { UI.updateVisualState('disconnected'); @@ -1969,11 +1973,13 @@ const UI = { openDisplays() { document.getElementById('noVNC_displays').classList.add("noVNC_open"); - if (UI.monitors.length < 1 ) { + if (UI.monitors.length < 1 && UI.rfb) { let screenPlan = UI.rfb.getScreenPlan(); - UI.initMonitors(screenPlan) + UI.initMonitors(screenPlan); + } + if (UI.monitors.length > 0) { + UI.displayMonitors() } - UI.displayMonitors() }, closeDisplays() { @@ -2106,6 +2112,9 @@ const UI = { recenter() { const monitors = UI.sortedMonitors UI.removeSpaces() + if (!monitors.length) { + return; + } const { startLeft, startTop } = UI.getSizes(monitors) for (var i = 0; i < monitors.length; i++) { @@ -2183,11 +2192,12 @@ const UI = { }, getSizes(monitors) { - const { canvasWidth, canvasHeight } = UI.multiMonitorSettings() - let top = monitors[0].y - let left = monitors[0].x - let width = monitors[0].w - let height = monitors[0].h + const { canvasWidth, canvasHeight } = UI.multiMonitorSettings(); + + let top = monitors[0].y; + let left = monitors[0].x; + let width = monitors[0].w; + let height = monitors[0].h; for (var i = 0; i < monitors.length; i++) { var m = monitors[i]; if (m.x < left) { diff --git a/core/display.js b/core/display.js index c635caf3b..1f342a9e8 100644 --- a/core/display.js +++ b/core/display.js @@ -473,7 +473,7 @@ export default class Display { for (let i=1; i 0) { - this._screens[i].channel.postMessage({ eventType: "registered", screenIndex: i }); + this._screens[i].channel?.postMessage({ eventType: "registered", screenIndex: i }); } } return removed; From 878eb43c0cf2218c668a8c214b2f0e6e968878fb Mon Sep 17 00:00:00 2001 From: El Date: Wed, 9 Jul 2025 18:57:21 +0500 Subject: [PATCH 4/4] VNC-212 Determine whether the current window is embedded in a frame or if it's a standalone one --- app/ui.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/ui.js b/app/ui.js index 168328ca4..b612ae2d8 100644 --- a/app/ui.js +++ b/app/ui.js @@ -2023,6 +2023,7 @@ const UI = { let new_display_path = window.location.pathname.replace(/[^/]*$/, ''); const windowId = uuidv4(); let new_display_url = `${window.location.protocol}//${window.location.host}${new_display_path}screen.html?windowId=${windowId}`; + const topWindow = window.top === window.self ? window : window.top || window; const auto_placement = document.getElementById('noVNC_auto_placement').checked if (auto_placement && 'getScreenDetails' in window) { @@ -2034,8 +2035,8 @@ const UI = { const details = await window.getScreenDetails() const current = UI.increaseCurrentDisplay(details) let screen = details.screens[current] - const options = 'left='+screen.availLeft+',top='+screen.availTop+',width='+screen.availWidth+',height='+screen.availHeight+',fullscreen' - let newdisplay = window.open(new_display_url, '_blank', options); + const options = 'left='+screen.availLeft+',top='+screen.availTop+',width='+screen.availWidth+',height='+screen.availHeight+',fullscreen'; + let newdisplay = topWindow.open(new_display_url, '_blank', options); UI.displayWindows.set(windowId, newdisplay); return; } @@ -2045,8 +2046,8 @@ const UI = { } } - Log.Debug(`Opening a secondary display ${new_display_url}`) - let newdisplay = window.open(new_display_url, '_blank', 'toolbar=0,location=0,menubar=0'); + Log.Debug(`Opening a secondary display ${new_display_url}`); + let newdisplay = topWindow.open(new_display_url, '_blank', 'toolbar=0,location=0,menubar=0'); if (newdisplay) { UI.displayWindows.set(windowId, newdisplay); }