From eef34b3b4d73f855b3b8cadcd44535b5e5392bea Mon Sep 17 00:00:00 2001 From: Wouter Date: Fri, 11 Sep 2020 11:53:43 +0200 Subject: [PATCH] Support per-monitor DPI scaling --- main.c | 16 +--------------- misc.c | 14 ++++++++++++++ misc.h | 1 + openvpn.c | 11 +++++++++++ res/openvpn-gui.manifest | 9 ++++++++- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index c877ea6..0436cb1 100644 --- a/main.c +++ b/main.c @@ -384,20 +384,6 @@ ResumeConnections() } } -/* - * Set scale factor of windows in pixels. Scale = 100% for dpi = 96 - */ -static void -dpi_setscale(UINT dpix) -{ - /* scale factor in percentage compared to the reference dpi of 96 */ - if (dpix != 0) - o.dpi_scale = MulDiv(dpix, 100, 96); - else - o.dpi_scale = 100; - PrintDebug(L"DPI scale set to %u", o.dpi_scale); -} - /* * Get dpi of the system and set the scale factor. * The system dpi may be different from the per monitor dpi on @@ -423,7 +409,7 @@ dpi_initialize(void) dpix = 96; } - dpi_setscale(dpix); + DpiSetScale(&o, dpix); } static int diff --git a/misc.c b/misc.c index 64e2c6b..d5594ae 100644 --- a/misc.c +++ b/misc.c @@ -340,6 +340,20 @@ ForceForegroundWindow(HWND hWnd) return ret; } +/* + * Set scale factor of windows in pixels. Scale = 100% for dpi = 96 + */ +void +DpiSetScale(options_t* options, UINT dpix) +{ + /* scale factor in percentage compared to the reference dpi of 96 */ + if (dpix != 0) + options->dpi_scale = MulDiv(dpix, 100, 96); + else + options->dpi_scale = 100; + PrintDebug(L"DPI scale set to %u", options->dpi_scale); +} + /* * Check user has admin rights * Taken from https://msdn.microsoft.com/en-us/library/windows/desktop/aa376389(v=vs.85).aspx diff --git a/misc.h b/misc.h index d56b087..6eb3bb0 100644 --- a/misc.h +++ b/misc.h @@ -32,6 +32,7 @@ BOOL strbegins(const char *str, const char *begin); BOOL wcsbegins(LPCWSTR, LPCWSTR); BOOL ForceForegroundWindow(HWND); +void DpiSetScale(options_t*, UINT dpix); BOOL IsUserAdmin(VOID); HANDLE InitSemaphore (WCHAR *); diff --git a/openvpn.c b/openvpn.c index f0c4c8b..533befd 100644 --- a/openvpn.c +++ b/openvpn.c @@ -35,6 +35,10 @@ #include #include +#ifndef WM_DPICHANGED +#define WM_DPICHANGED 0x02E0 +#endif + #include "tray.h" #include "main.h" #include "openvpn.h" @@ -1656,6 +1660,13 @@ StatusDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) SetFocus(hLogWnd); return FALSE; + case WM_DPICHANGED: + DpiSetScale(&o, HIWORD(wParam)); + RECT dlgRect; + GetClientRect(hwndDlg, &dlgRect); + RenderStatusWindow(hwndDlg, dlgRect.right, dlgRect.bottom); + return FALSE; + case WM_SIZE: RenderStatusWindow(hwndDlg, LOWORD(lParam), HIWORD(lParam)); InvalidateRect(hwndDlg, NULL, TRUE); diff --git a/res/openvpn-gui.manifest b/res/openvpn-gui.manifest index a8f9a97..5509c03 100644 --- a/res/openvpn-gui.manifest +++ b/res/openvpn-gui.manifest @@ -43,7 +43,14 @@ - true + + true/PM + + + PerMonitorV2, PerMonitor