GtkSettings priority

Hello,

If I understand GtkSettings correctly, they’re evaluated in this order, the last one with highest priority:

  • hardcoded defaults
  • settings.ini (from /etc or $HOME/.config)
  • theme settings.ini
  • GdkDisplay’s backend (xsettings, wayland, win32, …)
  • application

It means unless an application offers an option to change them, the typical settings are the ones from the GdkDisplay.

Is there any way to override the settings from GdkDisplay without hacking every applications?

A typical usecase I have is on Windows10, the gtk-font-name is forced to the system one (typically “Segoe UI 9”), and GdkDisplay settings like gtk-xft-hinting or gtk-xft-rgba are tailored for the native Cleartype/DWrite rendering. If I want to used another font renderer like PANGOCAIRO_BACKEND=fc then these default settings are unsuitable, so I’m looking for a way to override them.

Hello @gwillems! As it curently stands there’s no way to do that, unfortunately. Do you have any suggestion? Perhaps we could use another .ini file to override settings from the system, though that would make things more complex…

1 Like

Hi @lb90 ,

TBH I was surprised to see that the user’s settings.ini actually had a lower priority than GdkDisplay… Sounds fine for the one under /etc, but user settings should allow more flexibility I think.

Anyway, I don’t think we can change the way settings.ini are managed, too risky.

On Linux everyone uses the fontconfig backend for rendering so my particular example above is not a problem.

On Windows we have the choice between win32 and fontconfig backends, so one possibility could be to check for the default Pango renderer and to apply the GdkDisplay settings only if we use the win32 one, otherwise, for fontconfig, we will fallback on settings.ini.

I tested that patch yesterday, seems to work fine:

diff --git a/gdk/win32/gdkproperty-win32.c b/gdk/win32/gdkproperty-win32.c
index c92853e70b..8fc104a689 100644
--- a/gdk/win32/gdkproperty-win32.c
+++ b/gdk/win32/gdkproperty-win32.c
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <glib/gprintf.h>
 #include <pango/pangowin32.h>
+#include <pango/pangofc-fontmap.h>
 
 #include "gdkdisplayprivate.h"
 #include "gdkprivate-win32.h"
@@ -64,6 +65,9 @@ gboolean
 _gdk_win32_get_setting (const char *name,
                         GValue      *value)
 {
+  PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
+  gboolean use_fontconfig = PANGO_IS_FC_FONT_MAP (fontmap);
+
   if (strcmp ("gtk-alternative-button-order", name) == 0)
     {
       GDK_NOTE(MISC, g_print("gdk_display_get_setting(\"%s\") : TRUE\n", name));
@@ -111,7 +115,7 @@ _gdk_win32_get_setting (const char *name,
       g_value_set_int (value, i);
       return TRUE;
     }
-  else if (strcmp ("gtk-font-name", name) == 0)
+  else if (strcmp ("gtk-font-name", name) == 0 && !use_fontconfig)
     {
       char *font_name = NULL;
       HDC hdc = NULL;
@@ -195,7 +199,7 @@ _gdk_win32_get_setting (const char *name,
             }
         }
     }
-  else if (strcmp ("gtk-xft-antialias", name) == 0)
+  else if (strcmp ("gtk-xft-antialias", name) == 0 && !use_fontconfig)
     {
       GDK_NOTE(MISC, g_print ("gdk_screen_get_setting(\"%s\") : 1\n", name));
       g_value_set_int (value, 1);
@@ -225,19 +229,19 @@ _gdk_win32_get_setting (const char *name,
             }
         }
     }
-  else if (strcmp ("gtk-xft-hinting", name) == 0)
+  else if (strcmp ("gtk-xft-hinting", name) == 0 && !use_fontconfig)
     {
       GDK_NOTE(MISC, g_print ("gdk_screen_get_setting(\"%s\") : 1\n", name));
       g_value_set_int (value, 1);
       return TRUE;
     }
-  else if (strcmp ("gtk-xft-hintstyle", name) == 0)
+  else if (strcmp ("gtk-xft-hintstyle", name) == 0 && !use_fontconfig)
     {
       g_value_set_static_string (value, "hintfull");
       GDK_NOTE(MISC, g_print ("gdk_screen_get_setting(\"%s\") : %s\n", name, g_value_get_string (value)));
       return TRUE;
     }
-  else if (strcmp ("gtk-xft-rgba", name) == 0)
+  else if (strcmp ("gtk-xft-rgba", name) == 0 && !use_fontconfig)
     {
       unsigned int orientation = 0;
       if (SystemParametersInfoW (SPI_GETFONTSMOOTHINGORIENTATION, 0, &orientation, 0))

Does it look sane enough to propose a MR?
The advantage is that it doesn’t impact anything when using the default win32 backend, only users explicitly requesting fontconfig will benefit for that flexibility.

1 Like

It’s not a bad idea, indeed! However GIMP3 recently switched to using FontConfig on Windows too: Improve text quality of UI on Windows (!1058) · Merge requests · GNOME / GIMP · GitLab. I don’t know if GIMP would like to continue using the default system font…

Out of curiosity, what issues did you find using Pango Win32?

hmm… not sure it was a good idea, there was actually a Cairo issue in Gtk3 that was fixed a few month ago, I supposed GIMP was shipped with that broken version, should be much better with the latest Cairo version now.

I’ve 2 issues:

(1)
I’m using a GtkSourceView with minimap, it uses the special BuilderBlock.ttf font for clean and fast rendering, which is not compatible with Windows renderer (can’t install the font, says its broken), while it renders perfectly with fontconfig.

(2)
Regarding the font rendering in general, Gtk4 somehow uses Cleartype but with grayscale subpixel aliasing, which looks blurrier (or sometimes more pixelated) than the RGB aliasing of native apps or even Gtk3, especially at small font sizes (and the default 9pt size is quite small…)

So by default, we already have a different rendering between Gtk4 (grayscale) and native (RGB).

Also, while the default font SegoeUI looks fine even in Gtk4, because it’s optimized for cleartype, bur most other fonts, especially the monospaced ones I tried in my editor, look quite bad.

Fontconfig + FreeType allow me to use the same grid-fitted hinting rendering that I use on Linux, which IMO looks quite beautiful and comfortable for the eyes.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.