From 416fe35c67352dd23ad698d8f732545caee3d82d Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Fri, 28 Dec 2018 21:40:36 +0100 Subject: add per-monitor dpi support --- alf/alf.cpp | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'alf/alf.cpp') diff --git a/alf/alf.cpp b/alf/alf.cpp index 2ec33ca..9b2f60f 100644 --- a/alf/alf.cpp +++ b/alf/alf.cpp @@ -1,5 +1,9 @@ #include "alfpriv.h" +#ifndef WM_DPICHANGED +#define WM_DPICHANGED 0x02E0 +#endif + /* ALF App and Window */ static void @@ -39,31 +43,25 @@ ALF_UpdateFontForWidget(ALFWindowPriv *priv, ALFWidgetPriv *widget) { if (widget->hwnd && (widget->flags & ALF_MESSAGEFONT) == ALF_MESSAGEFONT) { SendMessage(widget->hwnd, WM_SETFONT, (WPARAM)priv->fonts.hMessageFont, (LPARAM)NULL); + + // XXX: Invalidating should IMHO be the decision of the control, but at + // least the commctl32 V5 static control doesn't do it. + InvalidateRect(widget->hwnd, NULL, TRUE); } } void ALF_UpdateFonts(HWND win) { - // TODO per-monitor DPI aware: GetDpiForWindow, SystemParametersInfoForDpi etc. ALFWindowPriv *priv = (ALFWindowPriv*)GetWindowLongPtr(win, 0); - priv->fonts.dpi = 0; - HDC hdcScreen = GetDC(NULL); - if (hdcScreen) { - priv->fonts.dpi = GetDeviceCaps(hdcScreen, LOGPIXELSY); - ReleaseDC(NULL, hdcScreen); - } - - if (!priv->fonts.dpi) { - priv->fonts.dpi = 96; // FIXME! fallback to default DPI - } + priv->fonts.dpi = priv->app->compatFn->GetDpiForWindow(win); NONCLIENTMETRICS ncm; ZeroMemory(&ncm, sizeof(ncm)); ncm.cbSize = sizeof(ncm); - if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0)) { + if (priv->app->compatFn->SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0, priv->fonts.dpi)) { priv->fonts.lfMessageFont = ncm.lfMessageFont; } else { // FIXME! fallback to default font, 8pt MS Shell Dlg @@ -375,11 +373,12 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) tmp.right = priv->layout.totalMinWidth; tmp.bottom = priv->layout.totalMinHeight; - // TODO ..ForDpi - if (AdjustWindowRectEx(&tmp, + if (priv->app->compatFn->AdjustWindowRectExForDpi( + &tmp, GetWindowLong(hwnd, GWL_STYLE), GetMenu(hwnd) != NULL, - GetWindowLong(hwnd, GWL_EXSTYLE))) { + GetWindowLong(hwnd, GWL_EXSTYLE), + priv->fonts.dpi)) { MINMAXINFO *i = (MINMAXINFO *)lparam; i->ptMinTrackSize.x = tmp.right - tmp.left; i->ptMinTrackSize.y = tmp.bottom - tmp.top; @@ -417,6 +416,13 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) ALF_DestroyWindowPriv(priv); } + if (msg == WM_DPICHANGED) { + ALF_UpdateFonts(hwnd); + ALF_RecalculateLayout(hwnd); + RECT *r = (RECT*)lparam; + SetWindowPos(hwnd, NULL, r->left, r->top, r->right-r->left, r->bottom-r->top, SWP_NOACTIVATE|SWP_NOZORDER); + } + if (msg == DM_GETDEFID) { if (priv->defid == (WORD)-1) { return 0; -- cgit v1.2.3