Nw.js: Window resizeTo/By methods behave erratically on hidpi displays

Created on 1 Feb 2017  路  3Comments  路  Source: nwjs/nw.js

Version: 0.20.0-sdk
OS: Windows 10

Given a display with a devicePixelRatio of 1.25 (a typical 1080p 15" laptop) and the following specific outer proportions in a visible window such as:

window.outerHeight: 100
window.outerWidth: 100

The following:
nw.Window.get(window).resizeBy(1, 1);

Gets you something unpredictable such as:

window.outerHeight: 104
window.outerWidth: 102

Instead of the expected 101x101 dimensions. The discrepancy varies every time, so in this example you may get 103x102, 105x101, etc.

This behaviour is reproducible on devices with an non-integer devicePixelRatio only. With a devicePixelRatio of 1 or 2, resizing behaves predictably.

P2 bug triaged

All 3 comments

Ok, got a workaround, forcing the device scale to 1 in the manifest file seems to work for cases where pixel perfect accuracy is required (hopefully the flag won't be discontinued):

"chromium-args" : "--force-device-scale-factor=1"

Reproduced with nw.Window.get(window).resizeBy(1, 1).

Environment:
nwjs-sdk-0.20.3 
Windows 10(devicePixelRatio =1.25)

And it works fine on the display(devicePixelRatio =1).

Hi @Christywl @rogerwang ,
The talk app widely used in our company is having the bug.

Draging the window on desktop causes the size getting larger and larger.

Before upgrading from nw12.3 to nw21.2, it was fine.

Currently we have the workaround of appending "chromium-args" : "--force-device-scale-factor=1" as @jportoles mentioned.

But it's hard to tell what the value should exactly be.

Environment:
nwjs-sdk-0.21.2 
Windows 7 (devicePixelRatio =1.25, via display settings)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Asp3ctus picture Asp3ctus  路  4Comments

nawazishali picture nawazishali  路  3Comments

xzh-loop picture xzh-loop  路  3Comments

niutech picture niutech  路  4Comments

rumax picture rumax  路  4Comments