getWindowDPI returns the wrong DPI

I have two monitors: #1 with a DPI of 100% and #2 with a DPI of 125%.
I have a non-native window that is launched on screen #2.

When calling, I’m expecting to get 1.25 as my second monitor is 125% DPI.

Instead, I’m getting 1.0 - the DPI of the monitor it was launched on - monitor #1 with 100% DPI.

Why? (note that it does not happen on NATIVE windows. I’m always getting the right DPI ).

The reason is that non-native windows will always return the DPI of the MAIN MONITOR.
While native windows return the DPI of the windows that it was launched on.

If you can’t use a native window but you still need to get the “right” DPI, you can use this workaround:

Identify the current window monitor (you can use getCurrentWindow() and getMonitorList()) and get the DPI of the current moitor.

BTW - to extract the monitor’s DPI from getMonitorList(), just divide the DpiX value by 96:
For example -

  • DpiX = 96 ==> 96/96 = 1 ==> DPI=100%.
  • DpiX = 96 ==> 120/96 = 1.25 ==> DPI=125%.