Add useNativeDpi option
This allows the viewport to be scaled to compensate for DPI scaling on high-DPI monitors. Previously, if DPI scaling was set to 200% in Windows, for example, noVNC would set the client area to twice the dimensions of the server-side framebuffer and scale it up to fit, leading to the VNC session looking grainy and low-res. useNativeDpi can now be set to true to compensate for this, and let framebuffer pixels exactly match monitor pixels.
This commit is contained in:
parent
0e37a3f83a
commit
de47b93963
23
core/rfb.js
23
core/rfb.js
|
|
@ -337,6 +337,16 @@ export default class RFB extends EventTargetMixin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get useNativeDpi() { return this._nativeDpi; }
|
||||||
|
set useNativeDpi(nativeDpi) {
|
||||||
|
this._nativeDpi = nativeDpi;
|
||||||
|
this._updateScale();
|
||||||
|
this._updateClip();
|
||||||
|
if (this._resizeSession) {
|
||||||
|
this._requestRemoteResize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get showDotCursor() { return this._showDotCursor; }
|
get showDotCursor() { return this._showDotCursor; }
|
||||||
set showDotCursor(show) {
|
set showDotCursor(show) {
|
||||||
this._showDotCursor = show;
|
this._showDotCursor = show;
|
||||||
|
|
@ -604,7 +614,14 @@ export default class RFB extends EventTargetMixin {
|
||||||
|
|
||||||
_updateScale() {
|
_updateScale() {
|
||||||
if (!this._scaleViewport) {
|
if (!this._scaleViewport) {
|
||||||
this._display.scale = 1.0;
|
if (this._nativeDpi) {
|
||||||
|
const dpr = window.devicePixelRatio || 1;
|
||||||
|
const scaledWidth = Math.floor(window.innerWidth * dpr);
|
||||||
|
// Compute the exact scale factor to match the floored width/height
|
||||||
|
this._display.scale = window.innerWidth / scaledWidth;
|
||||||
|
} else {
|
||||||
|
this._display.scale = 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const size = this._screenSize();
|
const size = this._screenSize();
|
||||||
this._display.autoscale(size.w, size.h);
|
this._display.autoscale(size.w, size.h);
|
||||||
|
|
@ -624,8 +641,10 @@ export default class RFB extends EventTargetMixin {
|
||||||
}
|
}
|
||||||
|
|
||||||
const size = this._screenSize();
|
const size = this._screenSize();
|
||||||
|
size.w = Math.floor(size.w / this._display.scale);
|
||||||
|
size.h = Math.floor(size.h / this._display.scale);
|
||||||
RFB.messages.setDesktopSize(this._sock,
|
RFB.messages.setDesktopSize(this._sock,
|
||||||
Math.floor(size.w), Math.floor(size.h),
|
size.w, size.h,
|
||||||
this._screenID, this._screenFlags);
|
this._screenID, this._screenFlags);
|
||||||
|
|
||||||
Log.Debug('Requested new desktop size: ' +
|
Log.Debug('Requested new desktop size: ' +
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue