Support per-monitor DPI scaling

pull/367/head
Wouter 2020-09-11 11:53:43 +02:00 committed by Selva Nair
parent bf47b62c36
commit eef34b3b4d
5 changed files with 35 additions and 16 deletions

16
main.c
View File

@ -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

14
misc.c
View File

@ -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

1
misc.h
View File

@ -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 *);

View File

@ -35,6 +35,10 @@
#include <time.h>
#include <commctrl.h>
#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);

View File

@ -43,7 +43,14 @@
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings
xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
<!-- Per Monitor V1 [OS >= Windows 8.1]
Values: False, True, Per-monitor, True/PM -->
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
<!-- Per Monitor V1 [OS >= Windows 10 Anniversary Update (1607, 10.0.14393, Redstone 1)]
Values: Unaware, System, PerMonitor -->
<!-- Per Monitor V2 [OS >= Windows 10 Creators Update (1703, 10.0.15063, Redstone 2)]
Value: PerMonitorV2 -->
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>