diff --git a/app/ui.js b/app/ui.js index 231947d06..b9cd3d355 100644 --- a/app/ui.js +++ b/app/ui.js @@ -1432,6 +1432,7 @@ const UI = { UI.rfb.addEventListener("inputlock", UI.inputLockChanged); UI.rfb.addEventListener("inputlockerror", UI.inputLockError); UI.rfb.addEventListener("screenregistered", UI.screenRegistered); + UI.rfb.addEventListener("screenupdated", UI.screenUpdated); UI.rfb.translateShortcuts = UI.getSetting('translate_shortcuts'); UI.rfb.clipViewport = UI.getSetting('view_clip'); UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale'; @@ -1918,8 +1919,6 @@ const UI = { document.getElementById('noVNC_refreshMonitors_icon').style.transform = "rotate(" + rotation + "deg)" UI.refreshRotation = rotation UI.updateMonitors(screenPlan) - UI.recenter() - UI.draw() }, normalizePlacementValues(details) { @@ -2012,9 +2011,9 @@ const UI = { }, - updateMonitors(screenPlan) { + updateMonitors(screenPlan, setScreenPlan = true) { UI.initMonitors(screenPlan) - UI.recenter() + UI.recenter(setScreenPlan) UI.draw() }, @@ -2030,7 +2029,7 @@ const UI = { } }, - recenter() { + recenter(setScreenPlan = true) { const monitors = UI.sortedMonitors UI.removeSpaces() const { startLeft, startTop } = UI.getSizes(monitors) @@ -2040,7 +2039,9 @@ const UI = { m.x += startLeft m.y += startTop } - UI.setScreenPlan() + if (setScreenPlan === true) { + UI.setScreenPlan() + } }, removeSpaces() { @@ -2143,8 +2144,8 @@ const UI = { const { top, left, width, height } = UI.getSizes(sortedMonitors) const screens = [] for (var i = 0; i < monitors.length; i++) { - var monitor = monitors[i]; - var a = sortedMonitors.find(el => el.id === monitor.id) + const monitor = monitors[i]; + const a = sortedMonitors.find(el => el.id === monitor.id) screens.push({ screenID: a.id, serverHeight: Math.round(a.h * scale), @@ -2914,6 +2915,25 @@ const UI = { } }, + resetScreenPositions(screenPlan) { + const leftMost = Math.min(...screenPlan.screens.map(screen => screen.x)) + if (leftMost >= 0) { + return screenPlan + } + + const increaseBy = Math.abs(leftMost) + screenPlan.screens.map(screen => screen.x += increaseBy) + return screenPlan + }, + + screenUpdated(e) { + if (UI.rfb) { + let screenPlan = UI.rfb.getScreenPlan(); + UI.updateMonitors(screenPlan, false) + UI._identify(UI.monitors) + } + }, + screenRegistered(e) { console.log('screen registered') @@ -2928,6 +2948,7 @@ const UI = { screenPlan.screens[current].x = left screenPlan.screens[current].y = top } + screenPlan = UI.resetScreenPositions(screenPlan) } UI.updateMonitors(screenPlan) diff --git a/core/rfb.js b/core/rfb.js index 3d9626623..49f7a1931 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -1819,7 +1819,7 @@ export default class RFB extends EventTargetMixin { clearTimeout(this._resizeTimeout); this._resizeTimeout = setTimeout(this._requestRemoteResize.bind(this), 500); - this.dispatchEvent(new CustomEvent("screenregistered", {})); + this.dispatchEvent(new CustomEvent("screenupdated", {})); Log.Info(`Secondary monitor (${event.data.screenID}) has been reattached.`); break; case 'unregister':