GdkWin32: Scale text with DPI like in GTK3 with SYSTEM_DPI_AWARENESS
authorLuca Bacci <luca.bacci982@gmail.com>
Tue, 23 Aug 2022 12:49:59 +0000 (14:49 +0200)
committerLuca Bacci <luca.bacci982@gmail.com>
Tue, 23 Aug 2022 17:53:44 +0000 (19:53 +0200)
Right now we only support system DPI awareness in GTK4. In that case
it makes sense to scale text with the DPI of the primary monitor, like
done in GTK3.

We plan to land support for proper fractional scaling in Gdk/Win32, so
in the future the "gtk-xft-dpi" setting will be gathered as intended,
i.e. for text magnification, as an a11y feature.

gdk/win32/gdkproperty-win32.c

index f919e53e9ccb88dfb68df5d876f211b92cb1d781..b8197495f23b754436ec6b93acca114d26bda217 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "gdkdisplayprivate.h"
 #include "gdkprivate-win32.h"
+#include "gdkdisplay-win32.h"
 #include "gdkwin32.h"
 
 static char *
@@ -162,6 +163,25 @@ _gdk_win32_get_setting (const char *name,
       g_value_set_int (value, 1);
       return TRUE;
     }
+  else if (strcmp ("gtk-xft-dpi", name) == 0)
+    {
+      GdkWin32Display *display = GDK_WIN32_DISPLAY (_gdk_display);
+
+      if (display->dpi_aware_type == PROCESS_SYSTEM_DPI_AWARE &&
+          !display->has_fixed_scale)
+        {
+          int dpi = GetDeviceCaps (GetDC (NULL), LOGPIXELSX);
+          if (dpi >= 96)
+            {
+              int xft_dpi = 1024 * dpi / display->surface_scale;
+              g_value_set_int (value, xft_dpi);
+              GDK_NOTE(MISC, g_print ("gdk_screen_get_setting(\"%s\") : %d\n", name, xft_dpi));
+              return TRUE;
+            }
+        }
+
+      return FALSE;
+    }
   else if (strcmp ("gtk-xft-hintstyle", name) == 0)
     {
       g_value_set_static_string (value, "hintfull");