Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

per-monitor DPI handling with MS Windows clients #1526

Closed
totaam opened this issue May 23, 2017 · 3 comments
Closed

per-monitor DPI handling with MS Windows clients #1526

totaam opened this issue May 23, 2017 · 3 comments
Labels
client win32 MS Windows OS
Milestone

Comments

@totaam
Copy link
Collaborator

totaam commented May 23, 2017

Blocked by #56, X11 doesn't have per-monitor DPI data either.. so not very useful in the short term.

But we can get per-monitor DPI information:

$ from comtypes.client import CreateObject
o=CreateObject('WbemScripting.SWbemLocator')
s=o.ConnectServer('.', 'root\\cimv2')
res=s.ExecQuery('SELECT * FROM Win32_DesktopMonitor')
print([(x.Properties_['DeviceID'].Value, x.Properties_['PixelsPerXLogicalInch'].Value, x.Properties_['PixelsPerYLogicalInch'].Value,) for x in res])
[(u'DesktopMonitor1', 96, 96)]
@totaam totaam added client win32 MS Windows OS labels Jan 23, 2021
@totaam totaam added this to the future milestone Jan 23, 2021
@totaam
Copy link
Collaborator Author

totaam commented Apr 12, 2022

No longer blocked by #56, but blocked by comtypes bugs again (similar to #2573 and #1899): it pollutes the gen directory with broken generated files, then after wiping them out, it generates files with missing imports (ie: missing from ctypes import c_int) and the generated WbemScripting.py file is empty and unusable.

Just for fun have a look at all those wrong answers: How do I get monitor resolution in Python?

totaam added a commit that referenced this issue Aug 20, 2022
and refactor comtypes query into a utility context manager
@totaam
Copy link
Collaborator Author

totaam commented Aug 20, 2022

The latest version of comtypes (1.1.14 at time of writing) seems to have fixed these runtime loading issues so the commit above allows us to expose the dpi-x and dpi-y.

But, as usual, there are other problems:

  • we get the rest of the monitor data and geometry from GTK and can only match the monitor by manufacturer and model... which could be wrong if there are multiple monitors of the same type but using different resolutions
  • the Win32_DesktopMonitor query returns null values for the screen dimensions so we have to use the values we get from GTK to derive the width-mm and height-mm... but GTK might have been lied to by the win32 API

If this causes problems, it can be disabled with XPRA_WIN32_MONITOR_DPI=0.

@totaam totaam closed this as completed Aug 20, 2022
@totaam
Copy link
Collaborator Author

totaam commented Sep 5, 2023

See also #3943 and #3514

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client win32 MS Windows OS
Projects
None yet
Development

No branches or pull requests

1 participant