[gnome-control-center] Add the input-source-switcher to the shortcuts
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] Add the input-source-switcher to the shortcuts
- Date: Mon, 14 Jan 2013 11:12:27 +0000 (UTC)
commit 77b7569c3ddb83db9cb866f7f9d87e6f6d1dd5ad
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jan 13 19:48:22 2013 -0500
Add the input-source-switcher to the shortcuts
This setting was relegated to gnome-tweak-tool in 3.6 for timing
reasons, but it really belongs in the keyboard panel.
https://bugzilla.gnome.org/show_bug.cgi?id=687910
panels/keyboard/cc-keyboard-option.c | 222 ++++++++++++++++++++++++++++------
1 files changed, 182 insertions(+), 40 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-option.c b/panels/keyboard/cc-keyboard-option.c
index 229ceae..a8ff9a0 100644
--- a/panels/keyboard/cc-keyboard-option.c
+++ b/panels/keyboard/cc-keyboard-option.c
@@ -39,6 +39,9 @@
#define XKB_OPTION_GROUP_LVL3 "lv3"
#define XKB_OPTION_GROUP_COMP "Compose key"
+#define INPUT_SWITCHER_SCHEMA "org.gnome.settings-daemon.peripherals.keyboard"
+#define INPUT_SWITCHER_KEY "input-sources-switcher"
+
enum
{
PROP_0,
@@ -62,6 +65,10 @@ struct _CcKeyboardOption
GtkListStore *store;
const gchar * const *whitelist;
+
+ gboolean is_xkb;
+
+ gchar *current_description;
};
typedef struct _CcKeyboardOptionClass CcKeyboardOptionClass;
@@ -74,6 +81,7 @@ static guint keyboard_option_signals[LAST_SIGNAL] = { 0 };
static GnomeXkbInfo *xkb_info = NULL;
static GSettings *input_sources_settings = NULL;
+static GSettings *input_switcher_settings = NULL;
static gchar **current_xkb_options = NULL;
static const gchar *xkb_option_lvl3_whitelist[] = {
@@ -119,6 +127,9 @@ reload_setting (CcKeyboardOption *self)
{
gchar **iter;
+ if (!self->is_xkb)
+ return;
+
for (iter = current_xkb_options; *iter; ++iter)
if (strv_contains (self->whitelist, *iter))
{
@@ -153,6 +164,21 @@ xkb_options_changed (GSettings *settings,
}
static void
+input_switcher_changed (GSettings *settings,
+ gchar *key,
+ gpointer data)
+{
+ CcKeyboardOption *option = data;
+
+ g_free (option->current_value);
+ g_free (option->current_description);
+ option->current_value = g_settings_get_string (settings, key);
+ option->current_description = NULL;
+
+ g_signal_emit (option, keyboard_option_signals[CHANGED_SIGNAL], 0);
+}
+
+static void
cc_keyboard_option_get_property (GObject *object,
guint prop_id,
GValue *value,
@@ -213,11 +239,42 @@ cc_keyboard_option_finalize (GObject *object)
g_clear_pointer (&self->group, g_free);
g_clear_pointer (&self->description, g_free);
g_clear_pointer (&self->current_value, g_free);
+ g_clear_pointer (&self->current_description, g_free);
g_clear_object (&self->store);
G_OBJECT_CLASS (cc_keyboard_option_parent_class)->finalize (object);
}
+static struct
+{
+ const gchar *value;
+ const gchar *description;
+} input_switcher_options[] =
+{
+ { "off", N_("Disabled") },
+ { "shift-l", N_("Left Shift") },
+ { "alt-l", N_("Left Alt") },
+ { "ctrl-l", N_("Left Ctrl") },
+ { "shift-r", N_("Right Shift") },
+ { "alt-r", N_("Right Alt") },
+ { "ctrl-r", N_("Right Ctrl") },
+ { "alt-shift-l", N_("Left Alt+Shift") },
+ { "alt-shift-r", N_("Right Alt+Shift") },
+ { "ctrl-shift-l", N_("Left Ctrl+Shift") },
+ { "ctrl-shift-r", N_("Right Ctrl+Shift") },
+ { "shift-l-shift-r", N_("Left+Right Shift") },
+ { "alt-l-alt-r", N_("Left+Right Alt") },
+ { "ctrl-l-ctrl-r", N_("Left+Right Ctrl") },
+ { "alt-shift", N_("Alt+Shift") },
+ { "ctrl-shift", N_("Ctrl+Shift") },
+ { "alt-ctrl", N_("Alt+Ctrl") },
+ { "caps", N_("Caps") },
+ { "shift-caps", N_("Shift+Caps") },
+ { "alt-caps", N_("Alt+Caps") },
+ { "ctrl-caps", N_("Ctrl+Caps") },
+ { NULL, NULL }
+};
+
static void
cc_keyboard_option_constructed (GObject *object)
{
@@ -228,7 +285,11 @@ cc_keyboard_option_constructed (GObject *object)
G_OBJECT_CLASS (cc_keyboard_option_parent_class)->constructed (object);
- if (g_str_equal (self->group, XKB_OPTION_GROUP_LVL3))
+ self->is_xkb = TRUE;
+
+ if (self->group == NULL)
+ self->is_xkb = FALSE;
+ else if (g_str_equal (self->group, XKB_OPTION_GROUP_LVL3))
self->whitelist = xkb_option_lvl3_whitelist;
else if (g_str_equal (self->group, XKB_OPTION_GROUP_COMP))
self->whitelist = xkb_option_comp_whitelist;
@@ -236,29 +297,41 @@ cc_keyboard_option_constructed (GObject *object)
g_assert_not_reached ();
self->store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
- gtk_list_store_append (self->store, &iter);
- gtk_list_store_set (self->store, &iter,
- XKB_OPTION_DESCRIPTION_COLUMN, _("Disabled"),
- XKB_OPTION_ID_COLUMN, NULL,
- -1);
- options = gnome_xkb_info_get_options_for_group (xkb_info, self->group);
- for (l = options; l; l = l->next)
+
+ if (self->is_xkb)
{
- option_id = l->data;
- if (strv_contains (self->whitelist, option_id))
+ gtk_list_store_insert_with_values (self->store, &iter, -1,
+ XKB_OPTION_DESCRIPTION_COLUMN, _("Disabled"),
+ XKB_OPTION_ID_COLUMN, NULL,
+ -1);
+ options = gnome_xkb_info_get_options_for_group (xkb_info, self->group);
+ for (l = options; l; l = l->next)
{
- gtk_list_store_append (self->store, &iter);
- gtk_list_store_set (self->store, &iter,
- XKB_OPTION_DESCRIPTION_COLUMN,
- gnome_xkb_info_description_for_option (xkb_info, self->group, option_id),
- XKB_OPTION_ID_COLUMN,
- option_id,
- -1);
+ option_id = l->data;
+ if (strv_contains (self->whitelist, option_id))
+ {
+ gtk_list_store_insert_with_values (self->store, &iter, -1,
+ XKB_OPTION_DESCRIPTION_COLUMN,
+ gnome_xkb_info_description_for_option (xkb_info, self->group, option_id),
+ XKB_OPTION_ID_COLUMN, option_id,
+ -1);
+ }
}
- }
- g_list_free (options);
+ g_list_free (options);
- reload_setting (self);
+ reload_setting (self);
+ }
+ else
+ {
+ gint i;
+ for (i = 0; input_switcher_options[i].value; i++)
+ {
+ gtk_list_store_insert_with_values (self->store, NULL, -1,
+ XKB_OPTION_DESCRIPTION_COLUMN, input_switcher_options[i].description,
+ XKB_OPTION_ID_COLUMN, input_switcher_options[i].value,
+ -1);
+ }
+ }
}
static void
@@ -297,6 +370,8 @@ cc_keyboard_option_class_init (CcKeyboardOptionClass *klass)
GList *
cc_keyboard_option_get_all (void)
{
+ CcKeyboardOption *option;
+
if (objects_list)
return objects_list;
@@ -319,6 +394,18 @@ cc_keyboard_option_get_all (void)
"group", XKB_OPTION_GROUP_COMP,
"description", _("Compose Key"),
NULL));
+
+ option = g_object_new (CC_TYPE_KEYBOARD_OPTION,
+ "description", _("Modifiers-only switch to next source"),
+ NULL);
+
+ input_switcher_settings = g_settings_new (INPUT_SWITCHER_SCHEMA);
+ g_signal_connect (input_switcher_settings, "changed::" INPUT_SWITCHER_KEY,
+ G_CALLBACK (input_switcher_changed), option);
+ input_switcher_changed (input_switcher_settings, INPUT_SWITCHER_KEY, option);
+
+ objects_list = g_list_prepend (objects_list, option);
+
return objects_list;
}
@@ -343,10 +430,44 @@ cc_keyboard_option_get_current_value_description (CcKeyboardOption *self)
{
g_return_val_if_fail (CC_IS_KEYBOARD_OPTION (self), NULL);
- if (!self->current_value)
- return _("Disabled");
+ if (self->is_xkb)
+ {
+ if (!self->current_value)
+ return _("Disabled");
+
+ return gnome_xkb_info_description_for_option (xkb_info, self->group, self->current_value);
+ }
+ else
+ {
+ GtkTreeIter iter;
+ gboolean ret;
+ gchar *desc;
+ gchar *id;
+
+ if (self->current_description)
+ return self->current_description;
- return gnome_xkb_info_description_for_option (xkb_info, self->group, self->current_value);
+ ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), &iter);
+ while (ret)
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter,
+ XKB_OPTION_DESCRIPTION_COLUMN, &desc,
+ XKB_OPTION_ID_COLUMN, &id,
+ -1);
+ if (g_strcmp0 (self->current_value, id) == 0)
+ {
+ g_free (id);
+ g_free (self->current_description);
+ self->current_description = desc;
+ break;
+ }
+ g_free (id);
+ g_free (desc);
+ ret = gtk_tree_model_iter_next (GTK_TREE_MODEL (self->store), &iter);
+ }
+
+ return self->current_description;
+ }
}
static void
@@ -407,31 +528,51 @@ void
cc_keyboard_option_set_selection (CcKeyboardOption *self,
GtkTreeIter *iter)
{
- gchar *new_value = NULL;
-
g_return_if_fail (CC_IS_KEYBOARD_OPTION (self));
- gtk_tree_model_get (GTK_TREE_MODEL (self->store), iter,
- XKB_OPTION_ID_COLUMN, &new_value,
- -1);
-
- if (!new_value)
+ if (self->is_xkb)
{
- if (self->current_value)
- remove_value (self->current_value);
+ gchar *new_value = NULL;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (self->store), iter,
+ XKB_OPTION_ID_COLUMN, &new_value,
+ -1);
+
+ if (!new_value)
+ {
+ if (self->current_value)
+ remove_value (self->current_value);
+ }
+ else
+ {
+ if (self->current_value)
+ replace_value (self->current_value, new_value);
+ else
+ add_value (new_value);
+ }
+
+ g_settings_set_strv (input_sources_settings, XKB_OPTIONS_KEY,
+ (const gchar * const *) current_xkb_options);
+
+ g_free (new_value);
}
else
{
- if (self->current_value)
- replace_value (self->current_value, new_value);
- else
- add_value (new_value);
- }
+ gchar *value = NULL;
+ gchar *description = NULL;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (self->store), iter,
+ XKB_OPTION_ID_COLUMN, &value,
+ XKB_OPTION_DESCRIPTION_COLUMN, &description,
+ -1);
- g_settings_set_strv (input_sources_settings, XKB_OPTIONS_KEY,
- (const gchar * const *) current_xkb_options);
+ g_free (self->current_value);
+ g_free (self->current_description);
+ self->current_value = value;
+ self->current_description = description;
- g_free (new_value);
+ g_settings_set_string (input_switcher_settings, INPUT_SWITCHER_KEY, self->current_value);
+ }
}
void
@@ -445,5 +586,6 @@ cc_keyboard_option_clear_all (void)
g_clear_pointer (&objects_list, g_list_free);
g_clear_pointer (¤t_xkb_options, g_strfreev);
g_clear_object (&input_sources_settings);
+ g_clear_object (&input_switcher_settings);
g_clear_object (&xkb_info);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]