[gnome-control-center/wip/gbsneto/new-keyboard-panel: 7/8] keyboard: bring back reverse item management
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/gbsneto/new-keyboard-panel: 7/8] keyboard: bring back reverse item management
- Date: Thu, 28 Jul 2016 16:16:24 +0000 (UTC)
commit 2b2c63959790b77b4d43656267bbbefe874f1d95
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu Jul 21 18:32:28 2016 -0300
keyboard: bring back reverse item management
In order to simplify the porting to the new UI, the
reverse item functionality was removed. Now that all
the necessary code landed, it is time to bring it back.
This patch adds back the ability to manage reverse items.
https://bugzilla.gnome.org/show_bug.cgi?id=769063
panels/keyboard/cc-keyboard-item.c | 53 +++++++++++++++++++++++-
panels/keyboard/cc-keyboard-manager.c | 71 ++++++++++++++++++++------------
2 files changed, 94 insertions(+), 30 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-item.c b/panels/keyboard/cc-keyboard-item.c
index ff1b414..b432794 100644
--- a/panels/keyboard/cc-keyboard-item.c
+++ b/panels/keyboard/cc-keyboard-item.c
@@ -147,17 +147,54 @@ _set_binding (CcKeyboardItem *item,
const char *value,
gboolean set_backend)
{
- g_free (item->priv->binding);
- item->priv->binding = g_strdup (value);
+ CcKeyboardItem *reverse;
+ gboolean enabled;
+
+ reverse = item->priv->reverse_item;
+ enabled = value && strlen (value) > 0;
+
+ g_clear_pointer (&item->priv->binding, g_free);
+ if (enabled)
+ item->priv->binding = g_strdup (value);
+
binding_from_string (item->priv->binding, &item->keyval,
&item->keycode, &item->mask);
+ /*
+ * Always treat the pair (item, reverse) as a unit: setting one also
+ * disables the other, disabling one up also sets the other.
+ */
+ if (reverse)
+ {
+ GdkModifierType reverse_mask;
+
+ reverse_mask = enabled ? item->mask ^ GDK_SHIFT_MASK : item->mask;
+
+ g_clear_pointer (&reverse->priv->binding, g_free);
+ if (enabled)
+ reverse->priv->binding = gtk_accelerator_name_with_keycode (NULL,
+ item->keyval,
+ item->keycode,
+ reverse_mask);
+
+ binding_from_string (reverse->priv->binding,
+ &reverse->keyval,
+ &reverse->keycode,
+ &reverse->mask);
+ }
+
if (set_backend == FALSE)
return;
settings_set_binding (item->settings, item->key, item->priv->binding);
g_object_notify (G_OBJECT (item), "is-value-default");
+
+ if (reverse)
+ {
+ settings_set_binding (reverse->settings, reverse->key, reverse->priv->binding);
+ g_object_notify (G_OBJECT (reverse), "is-value-default");
+ }
}
static void
@@ -545,11 +582,21 @@ cc_keyboard_item_is_value_default (CcKeyboardItem *self)
void
cc_keyboard_item_reset (CcKeyboardItem *self)
{
+ CcKeyboardItem *reverse;
+
g_return_if_fail (CC_IS_KEYBOARD_ITEM (self));
- g_settings_reset (self->settings, self->key);
+ reverse = self->priv->reverse_item;
+ g_settings_reset (self->settings, self->key);
g_object_notify (G_OBJECT (self), "is-value-default");
+
+ /* Also reset the reverse item */
+ if (reverse)
+ {
+ g_settings_reset (reverse->settings, reverse->key);
+ g_object_notify (G_OBJECT (reverse), "is-value-default");
+ }
}
/*
diff --git a/panels/keyboard/cc-keyboard-manager.c b/panels/keyboard/cc-keyboard-manager.c
index eb5e831..7283395 100644
--- a/panels/keyboard/cc-keyboard-manager.c
+++ b/panels/keyboard/cc-keyboard-manager.c
@@ -96,35 +96,53 @@ get_binding_from_variant (GVariant *variant)
}
static gboolean
+is_shortcut_different (CcUniquenessData *data,
+ CcKeyboardItem *item)
+{
+ if (data->orig_item && cc_keyboard_item_equal (data->orig_item, item))
+ return FALSE;
+
+ if (data->new_keyval != 0)
+ {
+ if (data->new_keyval != item->keyval)
+ return TRUE;
+ }
+ else if (item->keyval != 0 || data->new_keycode != item->keycode)
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
compare_keys_for_uniqueness (CcKeyboardItem *current_item,
CcUniquenessData *data)
{
- CcKeyboardItem *item;
-
- item = data->orig_item;
+ CcKeyboardItem *reverse_item;
/* No conflict for: blanks, different modifiers or ourselves */
if (!current_item ||
- item == current_item ||
+ data->orig_item == current_item ||
data->new_mask != current_item->mask)
{
return FALSE;
}
- if (item && cc_keyboard_item_equal (item, current_item))
- goto out;
+ reverse_item = cc_keyboard_item_get_reverse_item (current_item);
- if (data->new_keyval != 0)
- {
- if (data->new_keyval != current_item->keyval)
- return FALSE;
- }
- else if (current_item->keyval != 0 || data->new_keycode != current_item->keycode)
- {
- return FALSE;
- }
+ /* When the current item is the reversed shortcut of a main item, simply ignore it */
+ if (reverse_item && cc_keyboard_item_is_hidden (current_item))
+ return FALSE;
+
+ if (is_shortcut_different (data, current_item))
+ return FALSE;
-out:
+ /* Also check for the reverse item if any */
+ if (reverse_item && is_shortcut_different (data, reverse_item))
+ return FALSE;
+
+ /* No tests failed and we found a conflict */
data->conflict_item = current_item;
return TRUE;
@@ -903,6 +921,7 @@ cc_keyboard_manager_get_collision (CcKeyboardManager *self,
gint keycode)
{
CcUniquenessData data;
+ BindingGroupType i;
g_return_val_if_fail (CC_IS_KEYBOARD_MANAGER (self), NULL);
@@ -913,21 +932,19 @@ cc_keyboard_manager_get_collision (CcKeyboardManager *self,
data.conflict_item = NULL;
/* Any number of shortcuts can be disabled */
- if (keyval != 0 || keycode != 0)
- {
- BindingGroupType i;
+ if (keyval == 0 && keycode == 0)
+ return NULL;
- for (i = BINDING_GROUP_SYSTEM; i <= BINDING_GROUP_USER && !data.conflict_item; i++)
- {
- GHashTable *table;
+ for (i = BINDING_GROUP_SYSTEM; i <= BINDING_GROUP_USER && !data.conflict_item; i++)
+ {
+ GHashTable *table;
- table = get_hash_for_group (self, i);
+ table = get_hash_for_group (self, i);
- if (!table)
- continue;
+ if (!table)
+ continue;
- g_hash_table_find (table, (GHRFunc) check_for_uniqueness, &data);
- }
+ g_hash_table_find (table, (GHRFunc) check_for_uniqueness, &data);
}
return data.conflict_item;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]