pyglet icon indicating copy to clipboard operation
pyglet copied to clipboard

Supporting for HiDPI screens?

Open ZZY2357 opened this issue 2 years ago • 2 comments

On a HiDPI screen, the scale of the window is big and the resolution of the window is low. How to display a window on a HiDPI screen normally?

ZZY2357 avatar Aug 12 '22 14:08 ZZY2357

window.get_pixel_ratio() should help you in this case. The viewport size should be multiplied by this factor.

pyglet 2: I wonder if this could be solved internally in pyglet so hidpi will not become a problem. Basically just by applying the pixel ratio to the viewport when set. This makes sense unless somone have a reason to specifically use the extra space a hidpi screen provides, but I don't think this is very common.

einarf avatar Aug 13 '22 19:08 einarf

I have a separate branch I've messed with with bringing DPI aware windows to Windows. It works but the problem is Windows handles it differently than other OS's I believe. We would need a good way to make sure it's fairly consistent between platforms.

caffeinepills avatar Aug 14 '22 00:08 caffeinepills

Needs more testing on various OS's, but this is my initial implementation if anyone wants to test: https://github.com/caffeinepills/pyglet/tree/dpi_windows

caffeinepills avatar Mar 15 '23 19:03 caffeinepills

As a workaround on modern Windows you can try:


PROCESS_DPI_UNAWARE = 0,
PROCESS_SYSTEM_DPI_AWARE = 1,
PROCESS_PER_MONITOR_DPI_AWARE=2

system = platform.system()

if system == "Windows":
    # Set DPI awareness for HiDPI support on Windows
    try:
        ctypes.windll.shcore.SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)
    except AttributeError:
        pass  # Handle the case where SetProcessDpiAwareness is not available (pre-Windows 8.1)

sldsmkd avatar Aug 23 '23 10:08 sldsmkd

As a workaround on modern Windows you can try:


PROCESS_DPI_UNAWARE = 0,
PROCESS_SYSTEM_DPI_AWARE = 1,
PROCESS_PER_MONITOR_DPI_AWARE=2

system = platform.system()

if system == "Windows":
    # Set DPI awareness for HiDPI support on Windows
    try:
        ctypes.windll.shcore.SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)
    except AttributeError:
        pass  # Handle the case where SetProcessDpiAwareness is not available (pre-Windows 8.1)

Wow, it works well. Thank you.

ZZY2357 avatar Nov 11 '23 11:11 ZZY2357