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
This commit is contained in:
Luca Bacci 2022-10-26 14:10:48 +02:00
parent 114e2b607b
commit ac60bc6095
2 changed files with 28 additions and 8 deletions

View 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;

View 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