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

No longer fail to start NVDA from sources on Windows 7 when setting DPI awareness #14161

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions source/winAPI/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ class SystemErrorCodes(enum.IntEnum):
# https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
ACCESS_DENIED = 0x5
INVALID_PARAMETER = 0x57
MOD_NOT_FOUND = 0x7E
19 changes: 17 additions & 2 deletions source/winAPI/dpiAwareness.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,25 @@ def setDPIAwareness() -> None:
# This window checks for the DPI when it is created and adjusts the scale factor whenever the DPI changes.
# These processes are not automatically scaled by the system.
PROCESS_PER_MONITOR_DPI_AWARE = 2
# Method introduced in Windows 8
# Method introduced in Windows 8.1
hResult = ctypes.windll.shcore.SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)
except AttributeError:
log.debug("Cannot set PROCESS_PER_MONITOR_DPI_AWARE")
# Windows 8 / Server 2012 - `shcore` library exists,
# but `SetProcessDpiAwareness` is not present yet.
log.debug("Cannot set PROCESS_PER_MONITOR_DPI_AWARE - SetProcessDpiAwareness missing")
except WindowsError as e:
# `ctypes` raises `WindowsError` for missing DLL's.
# On Windows 7 `shcore` library is not present.
# Inspect error code and either ignore the exception falling back to the legacy method
# if it is caused by missing dll, log an error otherwise.
# In Python 3.8 and later `ctypes` raises `FileNotFoundError`
# rather than `WindowsError` for missing libraries.
# When updating NVDA the exception has to be changed
# or, if support for Windows 7 is dropped, this section should be removed.
if e.winerror == SystemErrorCodes.MOD_NOT_FOUND:
log.debug("Cannot set PROCESS_PER_MONITOR_DPI_AWARE - shcore not found")
else:
log.error("Failed to set PROCESS_PER_MONITOR_DPI_AWARE", exc_info=True)
else:
if hResult == HResult.S_OK:
return
Expand Down