From ac60bc6095b81bb990bb6bffb38f40917fd00fa6 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Wed, 26 Oct 2022 14:10:48 +0200 Subject: [PATCH] X11: Provide settings in logical pixels 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 | 11 ++++++++--- gdk/x11/xsettings-client.c | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/gdk/x11/gdkcursor-x11.c b/gdk/x11/gdkcursor-x11.c index ce5f861894..33a126075f 100644 --- a/gdk/x11/gdkcursor-x11.c +++ b/gdk/x11/gdkcursor-x11.c @@ -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; diff --git a/gdk/x11/xsettings-client.c b/gdk/x11/xsettings-client.c index 2e8bd45c74..5a8fa708a0 100644 --- a/gdk/x11/xsettings-client.c +++ b/gdk/x11/xsettings-client.c @@ -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