X11: Provide settings in logical pixels
authorLuca Bacci <luca.bacci982@gmail.com>
Wed, 26 Oct 2022 12:10:48 +0000 (14:10 +0200)
committerLuca Bacci <luca.bacci982@gmail.com>
Tue, 1 Nov 2022 12:09:28 +0000 (13:09 +0100)
This makes GtkSettings values on X11 match what we get on
other backends.

Reporting size settings in logical pixels (i.e for scale
== 1) is useful for properly supporting mixed-DPI setups.
As X11 doesn't support mixed-DPI setups anyway, XSettings
doesn't bother providing logical values. Thus we scale
from physical to logical values ourselves.

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5223
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5230

gdk/x11/gdkcursor-x11.c
gdk/x11/xsettings-client.c

index ce5f8618942d576447134ff547e9ee38bee125e0..33a126075f758c49f6b27c7682039cec39bd5be9 100644 (file)
@@ -281,27 +281,32 @@ gdk_x11_display_set_cursor_theme (GdkDisplay  *display,
                                   const int    size)
 {
 #if defined(HAVE_XCURSOR) && defined(HAVE_XFIXES) && XFIXES_MAJOR >= 2
+  GdkX11Screen *x11_screen;
   Display *xdisplay;
   char *old_theme;
+  int real_size;
   int old_size;
   gpointer cursor, xcursor;
   GHashTableIter iter;
 
   g_return_if_fail (GDK_IS_DISPLAY (display));
 
+  x11_screen = gdk_x11_display_get_screen (display);
   xdisplay = GDK_DISPLAY_XDISPLAY (display);
 
+  real_size = size * x11_screen->surface_scale;
+
   old_theme = XcursorGetTheme (xdisplay);
   old_size = XcursorGetDefaultSize (xdisplay);
 
-  if (old_size == size &&
+  if (old_size == real_size &&
       (old_theme == theme ||
        (old_theme && theme && strcmp (old_theme, theme) == 0)))
     return;
 
   XcursorSetTheme (xdisplay, theme);
-  if (size > 0)
-    XcursorSetDefaultSize (xdisplay, size);
+  if (real_size > 0)
+    XcursorSetDefaultSize (xdisplay, real_size);
 
   if (GDK_X11_DISPLAY (display)->cursors == NULL)
     return;
index 2e8bd45c7424a0a905cbdea641bd7b07846c8bc4..5a8fa708a0d93248df15945990ce4ef6b786352f 100644 (file)
@@ -457,16 +457,31 @@ read_settings (GdkX11Screen *x11_screen,
        }
     }
 
-  if (do_notify)
-    notify_changes (x11_screen, old_list);
-  if (old_list)
-    g_hash_table_unref (old_list);
-
   g_value_init (&value, G_TYPE_INT);
 
   if (!x11_screen->fixed_surface_scale &&
       gdk_display_get_setting (display, "gdk-window-scaling-factor", &value))
     _gdk_x11_screen_set_surface_scale (x11_screen, g_value_get_int (&value));
+
+  /* XSettings gives us the cursor theme size in physical pixel size,
+   * while we want logical pixel values instead.
+   */
+  if (x11_screen->surface_scale > 1 &&
+      gdk_display_get_setting (display, "gtk-cursor-theme-size", &value))
+    {
+      int cursor_theme_size = g_value_get_int (&value);
+
+      copy = g_new0 (GValue, 1);
+      g_value_init (copy, G_TYPE_INT);
+      g_value_set_int (copy, cursor_theme_size / x11_screen->surface_scale);
+      g_hash_table_insert (x11_screen->xsettings,
+                           (gpointer) "gtk-cursor-theme-size", copy);
+    }
+
+  if (do_notify)
+    notify_changes (x11_screen, old_list);
+  if (old_list)
+    g_hash_table_unref (old_list);
 }
 
 static Atom