x11-display: Set the correct default Xcursor theme size

Under Xorg the cursor size preference was pre-scaled originating from
gtk, while with Wayland it came directly from GSettings remaining
unscaled. Under Xwayland this caused the X11 display code to set the
wrong size with HiDPI configurations, which was often later overridden
by the equivalent code in gtk, but not always.

Fix this by always having the cursor size preference unscaled, scaling
the size correctly where it's used, depending on how it's used.

https://bugzilla.gnome.org/show_bug.cgi?id=759538
This commit is contained in:
Jonas Ådahl 2018-07-06 19:22:26 +02:00
parent 81c1c70c0a
commit e2464660bc
3 changed files with 30 additions and 75 deletions

View File

@ -676,6 +676,13 @@ on_startup_notification_changed (MetaStartupNotification *sn,
g_signal_emit_by_name (display, "startup-sequence-changed", sequence);
}
static void
on_ui_scaling_factor_changed (MetaSettings *settings,
MetaDisplay *display)
{
meta_display_reload_cursor (display);
}
/**
* meta_display_open:
*
@ -697,6 +704,7 @@ meta_display_open (void)
Window old_active_xwindow = None;
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager;
MetaSettings *settings;
g_assert (the_display == NULL);
display = the_display = g_object_new (META_TYPE_DISPLAY, NULL);
@ -755,6 +763,10 @@ meta_display_open (void)
g_signal_connect (monitor_manager, "monitors-changed-internal",
G_CALLBACK (on_monitors_changed_internal), display);
settings = meta_backend_get_settings (backend);
g_signal_connect (settings, "ui-scaling-factor-changed",
G_CALLBACK (on_ui_scaling_factor_changed), display);
meta_display_set_cursor (display, META_CURSOR_DEFAULT);
display->stack = meta_stack_new (display);

View File

@ -36,6 +36,7 @@
#include <stdlib.h>
#include "keybindings-private.h"
#include "meta-accel-parse.h"
#include "x11/meta-x11-display-private.h"
/* If you add a key, it needs updating in init() and in the gsettings
* notify listener and of course in the .schemas file.
@ -52,6 +53,7 @@
#define KEY_GNOME_ACCESSIBILITY "toolkit-accessibility"
#define KEY_GNOME_ANIMATIONS "enable-animations"
#define KEY_GNOME_CURSOR_THEME "cursor-theme"
#define KEY_GNOME_CURSOR_SIZE "cursor-size"
#define KEY_XKB_OPTIONS "xkb-options"
#define KEY_OVERLAY_KEY "overlay-key"
@ -127,9 +129,6 @@ static gboolean update_binding (MetaKeyPref *binding,
static gboolean update_key_binding (const char *key,
gchar **strokes);
static void wayland_settings_changed (GSettings *settings,
gchar *key,
gpointer data);
static void settings_changed (GSettings *settings,
gchar *key,
gpointer data);
@ -137,11 +136,6 @@ static void bindings_changed (GSettings *settings,
gchar *key,
gpointer data);
static void update_cursor_size_from_gtk (GtkSettings *settings,
GParamSpec *pspec,
gpointer data);
static void update_cursor_size (void);
static void queue_changed (MetaPreference pref);
static void maybe_give_disable_workarounds_warning (void);
@ -156,7 +150,6 @@ static void do_override (char *key, char *schema);
static void init_bindings (void);
typedef struct
{
MetaPrefsChangedFunc func;
@ -489,6 +482,13 @@ static MetaIntPreference preferences_int[] =
},
&drag_threshold
},
{
{ "cursor-size",
SCHEMA_INTERFACE,
META_PREF_CURSOR_SIZE,
},
&cursor_size
},
{ { NULL, 0, 0 }, NULL },
};
@ -965,15 +965,10 @@ meta_prefs_init (void)
G_CALLBACK (settings_changed), NULL);
g_signal_connect (settings, "changed::" KEY_GNOME_CURSOR_THEME,
G_CALLBACK (settings_changed), NULL);
if (meta_is_wayland_compositor ())
g_signal_connect (settings, "changed::cursor-size",
G_CALLBACK (wayland_settings_changed), NULL);
g_signal_connect (settings, "changed::" KEY_GNOME_CURSOR_SIZE,
G_CALLBACK (settings_changed), NULL);
g_hash_table_insert (settings_schemas, g_strdup (SCHEMA_INTERFACE), settings);
if (!meta_is_wayland_compositor ())
g_signal_connect (gtk_settings_get_default (), "notify::gtk-cursor-theme-size",
G_CALLBACK (update_cursor_size_from_gtk), NULL);
settings = g_settings_new (SCHEMA_INPUT_SOURCES);
g_signal_connect (settings, "changed::" KEY_XKB_OPTIONS,
G_CALLBACK (settings_changed), NULL);
@ -994,8 +989,6 @@ meta_prefs_init (void)
handle_preference_init_string_array ();
handle_preference_init_int ();
update_cursor_size ();
init_bindings ();
}
@ -1134,20 +1127,6 @@ meta_prefs_override_preference_schema (const char *key, const char *schema)
/****************************************************************************/
static void
wayland_settings_changed (GSettings *settings,
gchar *key,
gpointer data)
{
GVariant *value = g_settings_get_value (settings, key);
const GVariantType *type = g_variant_get_type (value);
g_return_if_fail (g_variant_type_equal (type, G_VARIANT_TYPE_INT32));
g_return_if_fail (g_str_equal (key, "cursor-size"));
update_cursor_size ();
}
static void
settings_changed (GSettings *settings,
gchar *key,
@ -1209,48 +1188,6 @@ bindings_changed (GSettings *settings,
g_strfreev (strokes);
}
static void
update_cursor_size (void)
{
if (meta_is_wayland_compositor ())
{
/* When running as a Wayland compositor, since we size of the cursor
* depends on what output it is on, we cannot use the GTK+
* "gtk-cursor-theme-size" setting because it has already been multiplied
* by the primary monitor scale. So, instead get the non-premultiplied
* cursor size value directly from gsettings instead.
*/
cursor_size =
g_settings_get_int (SETTINGS (SCHEMA_INTERFACE), "cursor-size");
}
else
{
update_cursor_size_from_gtk (gtk_settings_get_default (), NULL, NULL);
}
}
static void
update_cursor_size_from_gtk (GtkSettings *settings,
GParamSpec *pspec,
gpointer data)
{
GdkScreen *screen = gdk_screen_get_default ();
GValue value = G_VALUE_INIT;
int xsettings_cursor_size = 24;
g_value_init (&value, G_TYPE_INT);
if (gdk_screen_get_setting (screen, "gtk-cursor-theme-size", &value))
{
xsettings_cursor_size = g_value_get_int (&value);
}
if (xsettings_cursor_size != cursor_size)
{
cursor_size = xsettings_cursor_size;
queue_changed (META_PREF_CURSOR_SIZE);
}
}
/**
* maybe_give_disable_workaround_warning:
*

View File

@ -53,6 +53,7 @@
#include "backends/meta-backend-private.h"
#include "backends/meta-logical-monitor.h"
#include "backends/meta-settings-private.h"
#include "backends/x11/meta-backend-x11.h"
#include "core/frame.h"
#include "core/meta-workspace-manager-private.h"
@ -1462,8 +1463,13 @@ meta_x11_display_reload_cursor (MetaX11Display *x11_display)
static void
set_cursor_theme (Display *xdisplay)
{
MetaBackend *backend = meta_get_backend ();
MetaSettings *settings = meta_backend_get_settings (backend);
int scale;
scale = meta_settings_get_ui_scaling_factor (settings);
XcursorSetTheme (xdisplay, meta_prefs_get_cursor_theme ());
XcursorSetDefaultSize (xdisplay, meta_prefs_get_cursor_size ());
XcursorSetDefaultSize (xdisplay, meta_prefs_get_cursor_size () * scale);
}
static void