Bugfix/kasm 5601 display mgr changes (#97)

* KASM-5598 modify click logic to tell other windows they can receive a click event

* KASM-5598 dont run the rest of the switch on click focus set

* KASM-5598 forgot to false

* fix detection of changes of x and y of secondary screens

* always apply resize after recieving display reregister

---------

Co-authored-by: ryan.kuba <ryan.kuba@kasmweb.com>
Co-authored-by: mattmcclaskey <matt@kasmweb.com>
This commit is contained in:
Matt McClaskey 2024-02-08 16:05:08 -05:00 committed by GitHub
parent 3d7047e546
commit 5a3b4f0d69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 27 deletions

View File

@ -329,18 +329,24 @@ export default class Display {
} }
applyScreenPlan(screenPlan) { applyScreenPlan(screenPlan) {
//check all screens for any changes, but only apply changes to primary screen, secondary screens will individually be updated and report back with their new settings
let changes = false; let changes = false;
for (let i = 0; i < screenPlan.screens.length; i++) { for (let i = 0; i < screenPlan.screens.length; i++) {
for (let z = 0; z < this._screens.length; z++) { for (let z = 0; z < this._screens.length; z++) {
if (screenPlan.screens[i].screenID === this._screens[z].screenID) { if (screenPlan.screens[i].screenID === this._screens[z].screenID) {
if (this._screens[z].x !== screenPlan.screens[i].x || this._screens[z].y !== screenPlan.screens[i].y) { if (this._screens[z].x !== screenPlan.screens[i].x || this._screens[z].y !== screenPlan.screens[i].y) {
this._screens[z].x = screenPlan.screens[i].x; if (z == 0) {
this._screens[z].y = screenPlan.screens[i].y; this._screens[z].x = screenPlan.screens[i].x;
this._screens[z].y = screenPlan.screens[i].y;
}
changes = true; changes = true;
} }
if (this._screens[z].x2 !== this._screens[z].x + this._screens[z].serverWidth || this._screens[z].y2 !== this._screens[z].y + this._screens[z].serverHeight) { if (this._screens[z].x2 !== this._screens[z].x + this._screens[z].serverWidth || this._screens[z].y2 !== this._screens[z].y + this._screens[z].serverHeight) {
this._screens[z].x2 = this._screens[z].x + this._screens[z].serverWidth if (z == 0) {
this._screens[z].y2 = this._screens[z].y + this._screens[z].serverHeight this._screens[z].x2 = this._screens[z].x + this._screens[z].serverWidth
this._screens[z].y2 = this._screens[z].y + this._screens[z].serverHeight
}
changes = true; changes = true;
} }
} }
@ -349,7 +355,7 @@ export default class Display {
return changes; return changes;
} }
addScreen(screenID, width, height, pixelRatio, containerHeight, containerWidth, scale, serverWidth, serverHeight) { addScreen(screenID, width, height, pixelRatio, containerHeight, containerWidth, scale, serverWidth, serverHeight, x, y) {
if (!this._isPrimaryDisplay) { if (!this._isPrimaryDisplay) {
throw new Error("Cannot add a screen to a secondary display."); throw new Error("Cannot add a screen to a secondary display.");
} }
@ -367,23 +373,26 @@ export default class Display {
if (screenIdx > 0) { if (screenIdx > 0) {
//existing screen, update //existing screen, update
const screen = this._screens[screenIdx]; const existing_screen = this._screens[screenIdx];
if (screen.serverHeight !== serverHeight || screen.serverWidth !== serverWidth || screen.width !== width || screen.height !== height || screen.containerHeight !== containerHeight || screen.containerWidth !== containerWidth || screen.scale !== screen.scale || screen.pixelRatio !== screen.pixelRatio) { if (existing_screen.serverHeight !== serverHeight || existing_screen.serverWidth !== serverWidth || existing_screen.width !== width || existing_screen.height !== height
screen.width = width; || existing_screen.containerHeight !== containerHeight || existing_screen.containerWidth !== containerWidth || existing_screen.scale !== scale || existing_screen.pixelRatio !== pixelRatio ||
screen.height = height; existing_screen.x !== x || existing_screen.y !== y) {
screen.containerHeight = containerHeight; existing_screen.width = width;
screen.containerWidth = containerWidth; existing_screen.height = height;
screen.pixelRatio = pixelRatio; existing_screen.containerHeight = containerHeight;
screen.scale = scale; existing_screen.containerWidth = containerWidth;
screen.serverWidth = serverWidth; existing_screen.pixelRatio = pixelRatio;
screen.serverHeight = serverHeight; existing_screen.scale = scale;
screen.x2 = screen.x + screen.serverWidth; existing_screen.serverWidth = serverWidth;
screen.y2 = screen.y + screen.serverHeight; existing_screen.serverHeight = serverHeight;
existing_screen.x = x;
existing_screen.y = y;
existing_screen.x2 = existing_screen.x + existing_screen.serverWidth;
existing_screen.y2 = existing_screen.y + existing_screen.serverHeight;
return true; return true;
} }
} else { } else {
//New Screen, add to far right until user repositions it //New Screen, add to far right until user repositions it
let x = 0;
for (let i = 0; i < this._screens.length; i++) { for (let i = 0; i < this._screens.length; i++) {
x = Math.max(x, this._screens[i].x + this._screens[i].serverWidth); x = Math.max(x, this._screens[i].x + this._screens[i].serverWidth);
} }

View File

@ -805,6 +805,8 @@ export default class RFB extends EventTargetMixin {
} }
this._pendingApplyResolutionChange = true; this._pendingApplyResolutionChange = true;
} else {
Log.Debug("Screen plan did not apply, no changes detected.");
} }
return changes; return changes;
@ -1814,7 +1816,7 @@ export default class RFB extends EventTargetMixin {
...event.data.details, ...event.data.details,
screenID: event.data.screenID screenID: event.data.screenID
} }
let screenIndex = this._display.addScreen(event.data.screenID, event.data.width, event.data.height, event.data.pixelRatio, event.data.containerHeight, event.data.containerWidth, event.data.scale, event.data.serverWidth, event.data.serverHeight); let screenIndex = this._display.addScreen(event.data.screenID, event.data.width, event.data.height, event.data.pixelRatio, event.data.containerHeight, event.data.containerWidth, event.data.scale, event.data.serverWidth, event.data.serverHeight, event.data.x, event.data.y);
this._proxyRFBMessage('screenRegistrationConfirmed', [ this._display.screens[screenIndex].screenID, screenIndex ]); this._proxyRFBMessage('screenRegistrationConfirmed', [ this._display.screens[screenIndex].screenID, screenIndex ]);
this._sendEncodings(); this._sendEncodings();
clearTimeout(this._resizeTimeout); clearTimeout(this._resizeTimeout);
@ -1823,14 +1825,12 @@ export default class RFB extends EventTargetMixin {
Log.Info(`Secondary monitor (${event.data.screenID}) has been registered.`); Log.Info(`Secondary monitor (${event.data.screenID}) has been registered.`);
break; break;
case 'reattach': case 'reattach':
let changes = this._display.addScreen(event.data.screenID, event.data.width, event.data.height, event.data.pixelRatio, event.data.containerHeight, event.data.containerWidth, event.data.scale, event.data.serverWidth, event.data.serverHeight); let changes = this._display.addScreen(event.data.screenID, event.data.width, event.data.height, event.data.pixelRatio, event.data.containerHeight, event.data.containerWidth, event.data.scale, event.data.serverWidth, event.data.serverHeight, event.data.x, event.data.y);
if (changes) { clearTimeout(this._resizeTimeout);
clearTimeout(this._resizeTimeout); this._resizeTimeout = setTimeout(this._requestRemoteResize.bind(this), 500);
this._resizeTimeout = setTimeout(this._requestRemoteResize.bind(this), 500); this.dispatchEvent(new CustomEvent("screenregistered", {}));
this.dispatchEvent(new CustomEvent("screenregistered", {})); Log.Info(`Secondary monitor (${event.data.screenID}) has been reattached.`);
Log.Info(`Secondary monitor (${event.data.screenID}) has been reattached.`);
}
break; break;
case 'unregister': case 'unregister':
if (this._display.removeScreen(event.data.screenID)) { if (this._display.removeScreen(event.data.screenID)) {
@ -2257,7 +2257,7 @@ export default class RFB extends EventTargetMixin {
//Simulate a left click on focus change //Simulate a left click on focus change
//this was added to aid multi-display, not requiring two clicks when switching between displays //this was added to aid multi-display, not requiring two clicks when switching between displays
if (this._sendLeftClickonNextMove) { if (this._sendLeftClickonNextMove && this._display.screens.length > 1) {
this._sendLeftClickonNextMove = false; this._sendLeftClickonNextMove = false;
this._handleMouseButton(this._mousePos.x, this._mousePos.y, true, 0x1); this._handleMouseButton(this._mousePos.x, this._mousePos.y, true, 0x1);
this._handleMouseButton(this._mousePos.x, this._mousePos.y, false, 0x1); this._handleMouseButton(this._mousePos.x, this._mousePos.y, false, 0x1);