mirror of https://github.com/OpenVPN/openvpn-gui
Support per-monitor DPI scaling
parent
bf47b62c36
commit
eef34b3b4d
16
main.c
16
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.
|
* Get dpi of the system and set the scale factor.
|
||||||
* The system dpi may be different from the per monitor dpi on
|
* The system dpi may be different from the per monitor dpi on
|
||||||
|
@ -423,7 +409,7 @@ dpi_initialize(void)
|
||||||
dpix = 96;
|
dpix = 96;
|
||||||
}
|
}
|
||||||
|
|
||||||
dpi_setscale(dpix);
|
DpiSetScale(&o, dpix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
14
misc.c
14
misc.c
|
@ -340,6 +340,20 @@ ForceForegroundWindow(HWND hWnd)
|
||||||
return ret;
|
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
|
* Check user has admin rights
|
||||||
* Taken from https://msdn.microsoft.com/en-us/library/windows/desktop/aa376389(v=vs.85).aspx
|
* Taken from https://msdn.microsoft.com/en-us/library/windows/desktop/aa376389(v=vs.85).aspx
|
||||||
|
|
1
misc.h
1
misc.h
|
@ -32,6 +32,7 @@ BOOL strbegins(const char *str, const char *begin);
|
||||||
BOOL wcsbegins(LPCWSTR, LPCWSTR);
|
BOOL wcsbegins(LPCWSTR, LPCWSTR);
|
||||||
|
|
||||||
BOOL ForceForegroundWindow(HWND);
|
BOOL ForceForegroundWindow(HWND);
|
||||||
|
void DpiSetScale(options_t*, UINT dpix);
|
||||||
|
|
||||||
BOOL IsUserAdmin(VOID);
|
BOOL IsUserAdmin(VOID);
|
||||||
HANDLE InitSemaphore (WCHAR *);
|
HANDLE InitSemaphore (WCHAR *);
|
||||||
|
|
11
openvpn.c
11
openvpn.c
|
@ -35,6 +35,10 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <commctrl.h>
|
#include <commctrl.h>
|
||||||
|
|
||||||
|
#ifndef WM_DPICHANGED
|
||||||
|
#define WM_DPICHANGED 0x02E0
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "tray.h"
|
#include "tray.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "openvpn.h"
|
#include "openvpn.h"
|
||||||
|
@ -1656,6 +1660,13 @@ StatusDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
SetFocus(hLogWnd);
|
SetFocus(hLogWnd);
|
||||||
return FALSE;
|
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:
|
case WM_SIZE:
|
||||||
RenderStatusWindow(hwndDlg, LOWORD(lParam), HIWORD(lParam));
|
RenderStatusWindow(hwndDlg, LOWORD(lParam), HIWORD(lParam));
|
||||||
InvalidateRect(hwndDlg, NULL, TRUE);
|
InvalidateRect(hwndDlg, NULL, TRUE);
|
||||||
|
|
|
@ -43,7 +43,14 @@
|
||||||
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||||
<asmv3:windowsSettings
|
<asmv3:windowsSettings
|
||||||
xmlns="http://schemas.microsoft.com/SMI/2005/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:windowsSettings>
|
||||||
</asmv3:application>
|
</asmv3:application>
|
||||||
</assembly>
|
</assembly>
|
||||||
|
|
Loading…
Reference in New Issue