Skip to content

Commit

Permalink
Avoid blurry display on Windows High-DPI resolutions
Browse files Browse the repository at this point in the history
Blurriness comes from scaling, this handles scaling correctly for pixel
count of our slides though it may lead to tiny windows. This is not an
issue when setting the window fullscreen however, so can be ignored (for
now?).

Closes #302.
  • Loading branch information
Cimbali committed Dec 14, 2023
1 parent 69580bd commit 3606954
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pympress/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def uncaught_handler(*exc_info):
lang, enc = locale.getdefaultlocale()
os.environ['LANG'] = lang

# Before any initialisation or imports
util.make_windows_dpi_aware()


try:
loaded_locale = locale.setlocale(locale.LC_ALL, '')
except locale.Error as err:
Expand Down
12 changes: 12 additions & 0 deletions pympress/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import gettext
import os
import sys
import ctypes
import pathlib

if sys.version_info >= (3, 9):
Expand Down Expand Up @@ -524,6 +525,17 @@ def lookup_monitors(display, *windows):

return (*pos, prim_area.most_intersection(all_geom), prim_area.least_intersection(all_geom))


def make_windows_dpi_aware():
""" Set to avoid blurriness issues on High-DPI resolutions with scaling. """
if not IS_WINDOWS:
return

if hasattr(ctypes.windll.shcore, 'SetProcessDpiAwareness'):
ctypes.windll.shcore.SetProcessDpiAwareness(2)
else:
ctypes.windll.user32.SetProcessDPIAware()

##
# Local Variables:
# mode: python
Expand Down

0 comments on commit 3606954

Please sign in to comment.