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:
Thomas Sondergaard 2019-05-22 16:27:18 +02:00 committed by Jesper Alf Dam
parent 0e37a3f83a
commit de47b93963
1 changed files with 21 additions and 2 deletions

View File

@ -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; }
set showDotCursor(show) {
this._showDotCursor = show;
@ -604,7 +614,14 @@ export default class RFB extends EventTargetMixin {
_updateScale() {
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 {
const size = this._screenSize();
this._display.autoscale(size.w, size.h);
@ -624,8 +641,10 @@ export default class RFB extends EventTargetMixin {
}
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,
Math.floor(size.w), Math.floor(size.h),
size.w, size.h,
this._screenID, this._screenFlags);
Log.Debug('Requested new desktop size: ' +