Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KASM-5652 Fix update loop and get window placement working #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -2012,9 +2011,9 @@ const UI = {

},

updateMonitors(screenPlan) {
updateMonitors(screenPlan, setScreenPlan = true) {
UI.initMonitors(screenPlan)
UI.recenter()
UI.recenter(setScreenPlan)
UI.draw()
},

Expand All @@ -2030,7 +2029,7 @@ const UI = {
}
},

recenter() {
recenter(setScreenPlan = true) {
const monitors = UI.sortedMonitors
UI.removeSpaces()
const { startLeft, startTop } = UI.getSizes(monitors)
Expand All @@ -2040,7 +2039,9 @@ const UI = {
m.x += startLeft
m.y += startTop
}
UI.setScreenPlan()
if (setScreenPlan === true) {
UI.setScreenPlan()
}
},

removeSpaces() {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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')

Expand All @@ -2928,6 +2948,7 @@ const UI = {
screenPlan.screens[current].x = left
screenPlan.screens[current].y = top
}
screenPlan = UI.resetScreenPositions(screenPlan)
}

UI.updateMonitors(screenPlan)
Expand Down
2 changes: 1 addition & 1 deletion core/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down