Fix native resolution on hdpi screens

This commit is contained in:
mattmcclaskey 2023-10-11 06:27:14 -04:00
parent 954428d6c8
commit 19e8e924c2
No known key found for this signature in database
2 changed files with 20 additions and 14 deletions

View File

@ -245,13 +245,13 @@ export default class Display {
this._screens[i].serverWidth = width; this._screens[i].serverWidth = width;
this._screens[i].serverHeight = height; this._screens[i].serverHeight = height;
this._screens[i].scale = scale; this._screens[i].scale = scale;
this._screens[i].x2 = this._screens[i].x + this._screens[i].width; this._screens[i].x2 = this._screens[i].x + this._screens[i].serverWidth;
this._screens[i].y2 = this._screens[i].y + this._screens[i].height; this._screens[i].y2 = this._screens[i].y + this._screens[i].serverHeight;
} }
for (let i = 0; i < this._screens.length; i++) { for (let i = 0; i < this._screens.length; i++) {
data.serverWidth = Math.max(data.serverWidth, this._screens[i].x + this._screens[i].width); data.serverWidth = Math.max(data.serverWidth, this._screens[i].x + this._screens[i].serverWidth);
data.serverHeight = Math.max(data.serverHeight, this._screens[i].y + this._screens[i].height); data.serverHeight = Math.max(data.serverHeight, this._screens[i].y + this._screens[i].serverHeight);
} }
data.screens = this._screens; data.screens = this._screens;
@ -296,7 +296,7 @@ export default class Display {
//New Screen, add to far right until user repositions it //New Screen, add to far right until user repositions it
let x = 0; 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].width); x = Math.max(x, this._screens[i].x + this._screens[i].serverWidth);
} }
var new_screen = { var new_screen = {
@ -1038,7 +1038,7 @@ export default class Display {
rect.inSecondary = false; rect.inSecondary = false;
for (let i=0; i < this._screens.length; i++) { for (let i=0; i < this._screens.length; i++) {
let screen = this._screens[i]; let screen = this._screens[i];
if ( if (
!((rect.x > screen.x2 || screen.x > (rect.x + rect.width)) && (rect.y > screen.y2 || screen.y > (rect.y + rect.height))) !((rect.x > screen.x2 || screen.x > (rect.x + rect.width)) && (rect.y > screen.y2 || screen.y > (rect.y + rect.height)))
) { ) {
@ -1071,8 +1071,8 @@ export default class Display {
// style width to a number, the canvas is cleared. // style width to a number, the canvas is cleared.
// However, if you set the style width to a string // However, if you set the style width to a string
// ('NNNpx'), the canvas is scaled without clearing. // ('NNNpx'), the canvas is scaled without clearing.
const width = factor * vp.width + 'px'; const width = factor * vp.serverWidth + 'px';
const height = factor * vp.height + 'px'; const height = factor * vp.serverHeight + 'px';
if ((this._target.style.width !== width) || if ((this._target.style.width !== width) ||
(this._target.style.height !== height)) { (this._target.style.height !== height)) {
@ -1080,7 +1080,7 @@ export default class Display {
this._target.style.height = height; this._target.style.height = height;
} }
Log.Info('Pixel Ratio: ' + window.devicePixelRatio + ', VNC Scale: ' + factor + 'VNC Res: ' + vp.width + 'x' + vp.height); Log.Info('Pixel Ratio: ' + window.devicePixelRatio + ', VNC Scale: ' + factor + 'VNC Res: ' + vp.serverWidth + 'x' + vp.serverHeight);
var pixR = Math.abs(Math.ceil(window.devicePixelRatio)); var pixR = Math.abs(Math.ceil(window.devicePixelRatio));
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;

View File

@ -728,6 +728,10 @@ export default class RFB extends EventTargetMixin {
if (value !== this._hiDpi) { if (value !== this._hiDpi) {
this._hiDpi = value; this._hiDpi = value;
this._requestRemoteResize(); this._requestRemoteResize();
if (this._display.screens.length > 1) {
//force secondary displays to re-register and thus apply new hdpi setting
this._proxyRFBMessage('forceResize', [ value ]);
}
} }
} }
@ -741,7 +745,7 @@ export default class RFB extends EventTargetMixin {
applyScreenPlan(screenPlan) { applyScreenPlan(screenPlan) {
if (this._isPrimaryDisplay) { if (this._isPrimaryDisplay) {
let fullPlan = this._display.getScreenSize(); let fullPlan = this._screenSize();
//check plan for validity //check plan for validity
let minX = Number.MAX_SAFE_INTEGER, minY = Number.MAX_SAFE_INTEGER; let minX = Number.MAX_SAFE_INTEGER, minY = Number.MAX_SAFE_INTEGER;
@ -773,7 +777,7 @@ export default class RFB extends EventTargetMixin {
} }
getScreenPlan() { getScreenPlan() {
let fullPlan = this._display.getScreenSize(); let fullPlan = this._screenSize();
let sanitizedPlan = { let sanitizedPlan = {
screens: [], screens: [],
serverWidth: fullPlan.serverWidth, serverWidth: fullPlan.serverWidth,
@ -1457,7 +1461,7 @@ export default class RFB extends EventTargetMixin {
this._display.scale = 1.0; this._display.scale = 1.0;
} else { } else {
const size = this._screenSize(false); const size = this._screenSize(false);
this._display.autoscale(size.screens[0].containerWidth, size.screens[0].containerHeight, size.screens[0].scale); this._display.autoscale(size.screens[0].serverWidth, size.screens[0].serverHeight, size.screens[0].scale);
} }
this._fixScrollbars(); this._fixScrollbars();
} }
@ -1691,8 +1695,6 @@ export default class RFB extends EventTargetMixin {
// The following are primary to secondary messages that should be ignored on the primary // The following are primary to secondary messages that should be ignored on the primary
case 'updateCursor': case 'updateCursor':
break; break;
default:
Log.Warn(`Unhandled message type (${event.data.eventType}) from control channel.`);
} }
} else { } else {
// Primary to secondary screen message // Primary to secondary screen message
@ -1704,6 +1706,10 @@ export default class RFB extends EventTargetMixin {
break; break;
case 'disconnect': case 'disconnect':
this.disconnect(); this.disconnect();
case 'forceResize':
this._hiDpi = event.data.args[0];
this._updateScale();
this._requestRemoteResize();
} }
} }