summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-30 14:54:27 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-30 14:55:12 +0300
commitd27c0261cbbf77396e70c46c5fdb3745a85e48c0 (patch)
tree4802b3b2a537e4e278424fb722e79170f3f35933
parent3228d8104af43366ae80713594c5998791e09600 (diff)
Windows: Use the system UI scaling factor
Check for system UI scaling factor via Direct2D DPI values.
-rw-r--r--CMakeLists.txt3
-rw-r--r--res/about/version.gmi1
-rw-r--r--src/ui/window.c23
3 files changed, 27 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0a54a9eb..1e323d47 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -212,6 +212,9 @@ if (APPLE)
212 MACOSX_BUNDLE_COPYRIGHT "© ${COPYRIGHT_YEAR} Jaakko Keränen" 212 MACOSX_BUNDLE_COPYRIGHT "© ${COPYRIGHT_YEAR} Jaakko Keränen"
213 ) 213 )
214endif () 214endif ()
215if (MSYS)
216 target_link_libraries (app PUBLIC d2d1 uuid) # querying DPI
217endif ()
215if (UNIX) 218if (UNIX)
216 target_link_libraries (app PUBLIC m) 219 target_link_libraries (app PUBLIC m)
217endif () 220endif ()
diff --git a/res/about/version.gmi b/res/about/version.gmi
index f5b38149..788d2ea0 100644
--- a/res/about/version.gmi
+++ b/res/about/version.gmi
@@ -8,6 +8,7 @@
8 8
9## 0.4 9## 0.4
10* Visual fine-tuning: increased Fira Sans line spacing; list bullets use an accent color. 10* Visual fine-tuning: increased Fira Sans line spacing; list bullets use an accent color.
11* Windows: Support for HiDPI and system UI scaling factor.
11 12
12## 0.3 13## 0.3
13* Added style customization. 14* Added style customization.
diff --git a/src/ui/window.c b/src/ui/window.c
index 419e6a0a..c0e8fdad 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
38#include "../gmutil.h" 38#include "../gmutil.h"
39#if defined (iPlatformMsys) 39#if defined (iPlatformMsys)
40# include "../win32.h" 40# include "../win32.h"
41# include <d2d1.h>
41#endif 42#endif
42#if defined (iPlatformApple) && !defined (iPlatformIOS) 43#if defined (iPlatformApple) && !defined (iPlatformIOS)
43# include "macos.h" 44# include "macos.h"
@@ -491,10 +492,26 @@ static void updateRootSize_Window_(iWindow *d) {
491} 492}
492 493
493static float pixelRatio_Window_(const iWindow *d) { 494static float pixelRatio_Window_(const iWindow *d) {
495#if defined (iPlatformMsys)
496 /* Query Direct2D for the desktop DPI (not aware of which monitor, though). */ {
497 float ratio = 1.0f;
498 ID2D1Factory *d2dFactory = NULL;
499 HRESULT hr = D2D1CreateFactory(
500 D2D1_FACTORY_TYPE_SINGLE_THREADED, &IID_ID2D1Factory, NULL, (void **) &d2dFactory);
501 if (SUCCEEDED(hr)) {
502 FLOAT dpiX = 96;
503 FLOAT dpiY = 96;
504 ID2D1Factory_GetDesktopDpi(d2dFactory, &dpiX, &dpiY);
505 ratio = (float) (dpiX / 96.0);
506 ID2D1Factory_Release(d2dFactory);
507 }
508 }
509#else
494 int dx, x; 510 int dx, x;
495 SDL_GetRendererOutputSize(d->render, &dx, NULL); 511 SDL_GetRendererOutputSize(d->render, &dx, NULL);
496 SDL_GetWindowSize(d->win, &x, NULL); 512 SDL_GetWindowSize(d->win, &x, NULL);
497 return (float) dx / (float) x; 513 return (float) dx / (float) x;
514#endif
498} 515}
499 516
500static void drawBlank_Window_(iWindow *d) { 517static void drawBlank_Window_(iWindow *d) {
@@ -778,7 +795,13 @@ iInt2 rootSize_Window(const iWindow *d) {
778} 795}
779 796
780iInt2 coord_Window(const iWindow *d, int x, int y) { 797iInt2 coord_Window(const iWindow *d, int x, int y) {
798#if defined (iPlatformMsys)
799 /* On Windows, surface coordinates are in pixels. */
800 return init_I2(x, y);
801#else
802 /* Coordinates are in points. */
781 return mulf_I2(init_I2(x, y), d->pixelRatio); 803 return mulf_I2(init_I2(x, y), d->pixelRatio);
804#endif
782} 805}
783 806
784iInt2 mouseCoord_Window(const iWindow *d) { 807iInt2 mouseCoord_Window(const iWindow *d) {