History

win32: use dpi aware GetSystemMetricsForDpi

Kacper Michajłow committed 3 years ago

Commit 3045f141 parent ee586c51 file · +19 −9Browse files

Unified · Split

video/out/w32_common.c+19−9
@@ -78,6 +78,7 @@ typedef enum MONITOR_DPI_TYPE { · 77 unmodified lines
7878 struct w32_api {
7979 HRESULT (WINAPI *pGetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*);
8080 BOOL (WINAPI *pAdjustWindowRectExForDpi)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
81+ int (WINAPI *pGetSystemMetricsForDpi)(int nIndex, UINT dpi);
8182 BOOLEAN (WINAPI *pShouldAppsUseDarkMode)(void);
8283 DWORD (WINAPI *pSetPreferredAppMode)(DWORD mode);
8384 };
@@ -188,6 +189,13 @@ struct vo_w32_state { · 104 unmodified lines
188189 bool unmaximize;
189190 };
190191
192+static inline int get_system_metrics(struct vo_w32_state *w32, int metric)
193+{
194+ return w32->api.pGetSystemMetricsForDpi
195+ ? w32->api.pGetSystemMetricsForDpi(metric, w32->dpi)
196+ : GetSystemMetrics(metric);
197+}
198+
191199 static void adjust_window_rect(struct vo_w32_state *w32, HWND hwnd, RECT *rc)
192200 {
193201 if (!w32->opts->border)
@@ -231,13 +239,13 @@ static LRESULT borderless_nchittest(struct vo_w32_state *w32, int x, int y) · 37 unmodified lines
231239 if (!GetWindowRect(w32->window, &rc))
232240 return HTNOWHERE;
233241
234− POINT frame = {GetSystemMetrics(SM_CXSIZEFRAME),
235− GetSystemMetrics(SM_CYSIZEFRAME)};
242+ POINT frame = {get_system_metrics(w32, SM_CXSIZEFRAME),
243+ get_system_metrics(w32, SM_CYSIZEFRAME)};
236244 if (w32->opts->border) {
237− frame.x += GetSystemMetrics(SM_CXPADDEDBORDER);
238− frame.y += GetSystemMetrics(SM_CXPADDEDBORDER);
245+ frame.x += get_system_metrics(w32, SM_CXPADDEDBORDER);
246+ frame.y += get_system_metrics(w32, SM_CXPADDEDBORDER);
239247 if (!w32->opts->title_bar)
240− rc.top -= GetSystemMetrics(SM_CXPADDEDBORDER);
248+ rc.top -= get_system_metrics(w32, SM_CXPADDEDBORDER);
241249 }
242250 InflateRect(&rc, -frame.x, -frame.y);
243251
@@ -760,10 +768,10 @@ static RECT get_screen_area(struct vo_w32_state *w32) · 516 unmodified lines
760768 {
761769 // Handle --fs-screen=all
762770 if (w32->current_fs && w32->opts->fsscreen_id == -2) {
763− const int x = GetSystemMetrics(SM_XVIRTUALSCREEN);
764− const int y = GetSystemMetrics(SM_YVIRTUALSCREEN);
765− return (RECT) { x, y, x + GetSystemMetrics(SM_CXVIRTUALSCREEN),
766− y + GetSystemMetrics(SM_CYVIRTUALSCREEN) };
771+ const int x = get_system_metrics(w32, SM_XVIRTUALSCREEN);
772+ const int y = get_system_metrics(w32, SM_YVIRTUALSCREEN);
773+ return (RECT) { x, y, x + get_system_metrics(w32, SM_CXVIRTUALSCREEN),
774+ y + get_system_metrics(w32, SM_CYVIRTUALSCREEN) };
767775 }
768776 return get_monitor_info(w32).rcMonitor;
769777 }
@@ -1837,6 +1845,8 @@ static void w32_api_load(struct vo_w32_state *w32) · 1067 unmodified lines
18371845 // Available since Win10
18381846 w32->api.pAdjustWindowRectExForDpi = !user32_dll ? NULL :
18391847 (void *)GetProcAddress(user32_dll, "AdjustWindowRectExForDpi");
1848+ w32->api.pGetSystemMetricsForDpi = !user32_dll ? NULL :
1849+ (void *)GetProcAddress(user32_dll, "GetSystemMetricsForDpi");
18401850
18411851 // Dark mode related functions, available since the 1809 Windows 10 update
18421852 // Check the Windows build version as on previous versions used ordinals

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t