Commit e2d268eb authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

xsettings: Adopt code to look up GTK IM module

Right now, gsd-keyboard and gsd-xsettings have a strange relation
where the first sets the gtk-im-module dconf setting for the latter
to read the setting and forward it through XSettings.

Since this detection is highly X11 specific, make it happen in the
Xsettings daemon itself, from the relevant setting and device presence.

This makes users still able to shoot themselves in the foot by changing
the setting, X11 clients able to be told to switch to ibus if it turns
out necessary, and Wayland clients unaffected otherwise.

Related: gtk#4443
parent 24501cc4
Pipeline #365487 passed with stages
in 5 minutes and 10 seconds
......@@ -57,10 +57,6 @@
#define GNOME_DESKTOP_INTERFACE_DIR "org.gnome.desktop.interface"
#define KEY_GTK_IM_MODULE "gtk-im-module"
#define GTK_IM_MODULE_SIMPLE "gtk-im-context-simple"
#define GTK_IM_MODULE_IBUS "ibus"
#define GNOME_DESKTOP_INPUT_SOURCES_DIR "org.gnome.desktop.input-sources"
#define KEY_INPUT_SOURCES "sources"
......@@ -71,9 +67,6 @@
#define DEFAULT_LAYOUT "us"
#define GNOME_A11Y_APPLICATIONS_INTERFACE_DIR "org.gnome.desktop.a11y.applications"
#define KEY_OSK_ENABLED "screen-keyboard-enabled"
struct _GsdKeyboardManager
{
GObject parent;
......@@ -81,21 +74,14 @@ struct _GsdKeyboardManager
guint start_idle_id;
GSettings *settings;
GSettings *input_sources_settings;
GSettings *a11y_settings;
GDBusProxy *localed;
GCancellable *cancellable;
GdkSeat *user_seat;
guint device_added_id;
guint device_removed_id;
};
static void gsd_keyboard_manager_class_init (GsdKeyboardManagerClass *klass);
static void gsd_keyboard_manager_init (GsdKeyboardManager *keyboard_manager);
static void gsd_keyboard_manager_finalize (GObject *object);
static void update_gtk_im_module (GsdKeyboardManager *manager);
G_DEFINE_TYPE (GsdKeyboardManager, gsd_keyboard_manager, G_TYPE_OBJECT)
static gpointer manager_object = NULL;
......@@ -218,121 +204,6 @@ settings_changed (GSettings *settings,
}
static void
device_added_cb (GdkSeat *user_seat,
GdkDevice *device,
GsdKeyboardManager *manager)
{
GdkInputSource source;
source = gdk_device_get_source (device);
if (source == GDK_SOURCE_TOUCHSCREEN) {
update_gtk_im_module (manager);
}
}
static void
device_removed_cb (GdkSeat *user_seat,
GdkDevice *device,
GsdKeyboardManager *manager)
{
GdkInputSource source;
source = gdk_device_get_source (device);
if (source == GDK_SOURCE_TOUCHSCREEN)
update_gtk_im_module (manager);
}
static void
set_devicepresence_handler (GsdKeyboardManager *manager)
{
GdkSeat *user_seat;
if (gnome_settings_is_wayland ())
return;
user_seat = gdk_display_get_default_seat (gdk_display_get_default ());
manager->device_added_id = g_signal_connect (G_OBJECT (user_seat), "device-added",
G_CALLBACK (device_added_cb), manager);
manager->device_removed_id = g_signal_connect (G_OBJECT (user_seat), "device-removed",
G_CALLBACK (device_removed_cb), manager);
manager->user_seat = user_seat;
}
static gboolean
need_ibus (GVariant *sources)
{
GVariantIter iter;
const gchar *type;
g_variant_iter_init (&iter, sources);
while (g_variant_iter_next (&iter, "(&s&s)", &type, NULL))
if (g_str_equal (type, INPUT_SOURCE_TYPE_IBUS))
return TRUE;
return FALSE;
}
static gboolean
need_osk (GsdKeyboardManager *manager)
{
gboolean has_touchscreen = FALSE;
GList *devices;
GdkSeat *seat;
if (g_settings_get_boolean (manager->a11y_settings,
KEY_OSK_ENABLED))
return TRUE;
seat = gdk_display_get_default_seat (gdk_display_get_default ());
devices = gdk_seat_get_slaves (seat, GDK_SEAT_CAPABILITY_TOUCH);
has_touchscreen = devices != NULL;
g_list_free (devices);
return has_touchscreen;
}
static void
set_gtk_im_module (GsdKeyboardManager *manager,
GSettings *settings,
GVariant *sources)
{
const gchar *new_module;
gchar *current_module;
if (need_ibus (sources) || need_osk (manager))
new_module = GTK_IM_MODULE_IBUS;
else
new_module = GTK_IM_MODULE_SIMPLE;
current_module = g_settings_get_string (settings, KEY_GTK_IM_MODULE);
if (!g_str_equal (current_module, new_module))
g_settings_set_string (settings, KEY_GTK_IM_MODULE, new_module);
g_free (current_module);
}
static void
update_gtk_im_module (GsdKeyboardManager *manager)
{
GSettings *interface_settings;
GVariant *sources;
/* Gtk+ uses the IM module advertised in XSETTINGS so, if we
* have IBus input sources, we want it to load that
* module. Otherwise we can use the default "simple" module
* which is builtin gtk+
*/
interface_settings = g_settings_new (GNOME_DESKTOP_INTERFACE_DIR);
sources = g_settings_get_value (manager->input_sources_settings,
KEY_INPUT_SOURCES);
set_gtk_im_module (manager, interface_settings, sources);
g_object_unref (interface_settings);
g_variant_unref (sources);
}
static void
get_sources_from_xkb_config (GsdKeyboardManager *manager)
{
......@@ -580,18 +451,7 @@ start_keyboard_idle_cb (GsdKeyboardManager *manager)
manager->settings = g_settings_new (GSD_KEYBOARD_DIR);
set_devicepresence_handler (manager);
manager->input_sources_settings = g_settings_new (GNOME_DESKTOP_INPUT_SOURCES_DIR);
g_signal_connect_swapped (manager->input_sources_settings,
"changed::" KEY_INPUT_SOURCES,
G_CALLBACK (update_gtk_im_module), manager);
manager->a11y_settings = g_settings_new (GNOME_A11Y_APPLICATIONS_INTERFACE_DIR);
g_signal_connect_swapped (manager->a11y_settings,
"changed::" KEY_OSK_ENABLED,
G_CALLBACK (update_gtk_im_module), manager);
update_gtk_im_module (manager);
manager->cancellable = g_cancellable_new ();
......@@ -645,14 +505,7 @@ gsd_keyboard_manager_stop (GsdKeyboardManager *manager)
g_clear_object (&manager->settings);
g_clear_object (&manager->input_sources_settings);
g_clear_object (&manager->a11y_settings);
g_clear_object (&manager->localed);
if (manager->user_seat != NULL) {
g_signal_handler_disconnect (manager->user_seat, manager->device_added_id);
g_signal_handler_disconnect (manager->user_seat, manager->device_removed_id);
manager->user_seat = NULL;
}
}
static void
......
......@@ -57,6 +57,8 @@
#define WM_SETTINGS_SCHEMA "org.gnome.desktop.wm.preferences"
#define A11Y_SCHEMA "org.gnome.desktop.a11y"
#define A11Y_INTERFACE_SCHEMA "org.gnome.desktop.a11y.interface"
#define A11Y_APPLICATIONS_SCHEMA "org.gnome.desktop.a11y.applications"
#define INPUT_SOURCES_SCHEMA "org.gnome.desktop.input-sources"
#define CLASSIC_WM_SETTINGS_SCHEMA "org.gnome.shell.extensions.classic-overrides"
#define XSETTINGS_PLUGIN_SCHEMA "org.gnome.settings-daemon.plugins.xsettings"
......@@ -75,9 +77,18 @@
#define HIGH_CONTRAST_KEY "high-contrast"
#define INPUT_SOURCES_KEY "sources"
#define OSK_ENABLED_KEY "screen-keyboard-enabled"
#define GTK_IM_MODULE_KEY "gtk-im-module"
#define GTK_SETTINGS_DBUS_PATH "/org/gtk/Settings"
#define GTK_SETTINGS_DBUS_NAME "org.gtk.Settings"
#define INPUT_SOURCE_TYPE_IBUS "ibus"
#define GTK_IM_MODULE_SIMPLE "gtk-im-context-simple"
#define GTK_IM_MODULE_IBUS "ibus"
static const gchar introspection_xml[] =
"<node name='/org/gtk/Settings'>"
" <interface name='org.gtk.Settings'>"
......@@ -280,6 +291,11 @@ struct _GsdXSettingsManager
FcMonitor *fontconfig_monitor;
gint64 fontconfig_timestamp;
GSettings *interface_settings;
GSettings *input_sources_settings;
GSettings *a11y_settings;
GdkSeat *user_seat;
GsdXSettingsGtk *gtk;
guint introspect_properties_changed_id;
......@@ -289,6 +305,9 @@ struct _GsdXSettingsManager
guint display_config_watch_id;
guint monitors_changed_id;
guint device_added_id;
guint device_removed_id;
guint shell_name_watch_id;
gboolean have_shell;
......@@ -1323,6 +1342,112 @@ migrate_settings (void)
mouse_entries, G_N_ELEMENTS (mouse_entries));
}
static gboolean
need_ibus (GsdXSettingsManager *manager)
{
GVariant *sources;
GVariantIter iter;
const gchar *type;
gboolean needs_ibus = FALSE;
sources = g_settings_get_value (manager->input_sources_settings,
INPUT_SOURCES_KEY);
g_variant_iter_init (&iter, sources);
while (g_variant_iter_next (&iter, "(&s&s)", &type, NULL)) {
if (g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) {
needs_ibus = TRUE;
break;
}
}
g_variant_unref (sources);
return needs_ibus;
}
static gboolean
need_osk (GsdXSettingsManager *manager)
{
gboolean has_touchscreen = FALSE;
GList *devices;
GdkSeat *seat;
if (g_settings_get_boolean (manager->a11y_settings,
OSK_ENABLED_KEY))
return TRUE;
seat = gdk_display_get_default_seat (gdk_display_get_default ());
devices = gdk_seat_get_slaves (seat, GDK_SEAT_CAPABILITY_TOUCH);
has_touchscreen = devices != NULL;
g_list_free (devices);
return has_touchscreen;
}
static void
update_gtk_im_module (GsdXSettingsManager *manager)
{
const gchar *module;
gchar *setting;
setting = g_settings_get_string (manager->interface_settings,
GTK_IM_MODULE_KEY);
if (setting && *setting)
module = setting;
else if (need_ibus (manager) || need_osk (manager))
module = GTK_IM_MODULE_IBUS;
else
module = GTK_IM_MODULE_SIMPLE;
xsettings_manager_set_string (manager->manager, "Gtk/IMModule", module);
g_free (setting);
}
static void
device_added_cb (GdkSeat *user_seat,
GdkDevice *device,
GsdXSettingsManager *manager)
{
GdkInputSource source;
source = gdk_device_get_source (device);
if (source == GDK_SOURCE_TOUCHSCREEN) {
update_gtk_im_module (manager);
}
}
static void
device_removed_cb (GdkSeat *user_seat,
GdkDevice *device,
GsdXSettingsManager *manager)
{
GdkInputSource source;
source = gdk_device_get_source (device);
if (source == GDK_SOURCE_TOUCHSCREEN)
update_gtk_im_module (manager);
}
static void
set_devicepresence_handler (GsdXSettingsManager *manager)
{
GdkSeat *user_seat;
if (gnome_settings_is_wayland ())
return;
user_seat = gdk_display_get_default_seat (gdk_display_get_default ());
manager->device_added_id = g_signal_connect (G_OBJECT (user_seat), "device-added",
G_CALLBACK (device_added_cb), manager);
manager->device_removed_id = g_signal_connect (G_OBJECT (user_seat), "device-removed",
G_CALLBACK (device_removed_cb), manager);
manager->user_seat = user_seat;
}
gboolean
gsd_xsettings_manager_start (GsdXSettingsManager *manager,
GError **error)
......@@ -1344,6 +1469,23 @@ gsd_xsettings_manager_start (GsdXSettingsManager *manager,
return FALSE;
}
set_devicepresence_handler (manager);
manager->interface_settings = g_settings_new (INTERFACE_SETTINGS_SCHEMA);
g_signal_connect_swapped (manager->interface_settings,
"changed::" GTK_IM_MODULE_KEY,
G_CALLBACK (update_gtk_im_module), manager);
manager->input_sources_settings = g_settings_new (INPUT_SOURCES_SCHEMA);
g_signal_connect_swapped (manager->input_sources_settings,
"changed::" INPUT_SOURCES_KEY,
G_CALLBACK (update_gtk_im_module), manager);
manager->a11y_settings = g_settings_new (A11Y_APPLICATIONS_SCHEMA);
g_signal_connect_swapped (manager->a11y_settings,
"changed::" OSK_ENABLED_KEY,
G_CALLBACK (update_gtk_im_module), manager);
update_gtk_im_module (manager);
manager->monitors_changed_id =
g_dbus_connection_signal_subscribe (manager->dbus_connection,
"org.gnome.Mutter.DisplayConfig",
......@@ -1541,6 +1683,16 @@ gsd_xsettings_manager_stop (GsdXSettingsManager *manager)
g_object_unref (manager->gtk);
manager->gtk = NULL;
}
if (manager->user_seat != NULL) {
g_signal_handler_disconnect (manager->user_seat, manager->device_added_id);
g_signal_handler_disconnect (manager->user_seat, manager->device_removed_id);
manager->user_seat = NULL;
}
g_clear_object (&manager->a11y_settings);
g_clear_object (&manager->input_sources_settings);
g_clear_object (&manager->interface_settings);
}
static void
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment