diff options
author | David Robillard <d@drobilla.net> | 2023-01-10 11:55:36 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-01-10 11:55:36 -0500 |
commit | 604dbd1e736c88bbba36da4a9422615936b856d7 (patch) | |
tree | f9a83d772b83fdab1f2f5834291e43d9b566851b /src/win.c | |
parent | 4e81c178ed8665c2f37fd6f3a35cd1a31598bc8d (diff) | |
download | pugl-604dbd1e736c88bbba36da4a9422615936b856d7.tar.gz pugl-604dbd1e736c88bbba36da4a9422615936b856d7.tar.bz2 pugl-604dbd1e736c88bbba36da4a9422615936b856d7.zip |
Windows: Make puglGetScaleFactor always return a reasonable value
This guesses the likely scale factor when the view hasn't been realized (and so
there's no real window to get information for). It may still be wrong for
multiple display systems, but will always return some scale factor that
"exists" on the system, and should always be correct when there's only one
display.
Diffstat (limited to 'src/win.c')
-rw-r--r-- | src/win.c | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -136,6 +136,27 @@ puglWinGetWindowExFlags(const PuglView* const view) return WS_EX_NOINHERITLAYOUT | (view->parent ? 0U : WS_EX_APPWINDOW); } +static HWND +puglWinGetWindow(const PuglView* const view) +{ + return view->impl->hwnd ? view->impl->hwnd + : view->parent ? (HWND)view->parent + : view->transientParent ? (HWND)view->transientParent + : NULL; +} + +static HMONITOR +puglWinGetMonitor(const PuglView* const view) +{ + const HWND hwnd = puglWinGetWindow(view); + if (hwnd) { + return MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY); + } + + const POINT point = {(long)view->frame.x, (long)view->frame.y}; + return MonitorFromPoint(point, MONITOR_DEFAULTTOPRIMARY); +} + static double puglWinGetViewScaleFactor(const PuglView* const view) { @@ -156,9 +177,7 @@ puglWinGetViewScaleFactor(const PuglView* const view) DWORD scaleFactor = 100; if (GetProcessDpiAwareness && GetScaleFactorForMonitor && !GetProcessDpiAwareness(NULL, &dpiAware) && dpiAware) { - GetScaleFactorForMonitor( - MonitorFromWindow(view->impl->hwnd, MONITOR_DEFAULTTOPRIMARY), - &scaleFactor); + GetScaleFactorForMonitor(puglWinGetMonitor(view), &scaleFactor); } FreeLibrary(shcore); @@ -1174,7 +1193,8 @@ adjustedWindowRect(PuglView* const view, double puglGetScaleFactor(const PuglView* const view) { - return view->impl->scaleFactor; + return view->impl->scaleFactor ? view->impl->scaleFactor + : puglWinGetViewScaleFactor(view); } PuglStatus |