[gnome-control-center] keyboard: Refactor finding of conflicting items
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] keyboard: Refactor finding of conflicting items
- Date: Mon, 10 Jul 2017 17:42:12 +0000 (UTC)
commit ab353591f81b23b50bce22897b529150bcfb79e9
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Aug 27 01:57:41 2013 +0200
keyboard: Refactor finding of conflicting items
When comparing keys for uniqueness, we currently apply various tests to
check whether shortcuts are different, until we decide that we found a
conflict if none of the tests passed. That approach is a bit weird for
shortcuts that have a reverse item - when comparing a binding to two
different shortcuts, it should always be different from at least one of
them, so there should never be a conflict for any reversible shortcuts.
The reason it does work anyway is that reverse items usually only differ
in modifiers, which is_shortcut_different() currently doesn't consider at
all. We are about to change that however, so refactor the code to set the
conflicting item as soon as we find a match rather than as fall-through.
https://bugzilla.gnome.org/show_bug.cgi?id=673078
panels/keyboard/cc-keyboard-manager.c | 34 ++++++++++++++------------------
1 files changed, 15 insertions(+), 19 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-manager.c b/panels/keyboard/cc-keyboard-manager.c
index bea9719..aff1908 100644
--- a/panels/keyboard/cc-keyboard-manager.c
+++ b/panels/keyboard/cc-keyboard-manager.c
@@ -102,25 +102,24 @@ get_binding_from_variant (GVariant *variant)
}
static gboolean
-is_shortcut_different (CcUniquenessData *data,
- CcKeyboardItem *item)
+find_conflict (CcUniquenessData *data,
+ CcKeyboardItem *item)
{
CcKeyCombo *combo = item->primary_combo;
+ gboolean is_conflict = FALSE;
if (data->orig_item && cc_keyboard_item_equal (data->orig_item, item))
return FALSE;
if (data->new_keyval != 0)
- {
- if (data->new_keyval != combo->keyval)
- return TRUE;
- }
- else if (combo->keyval != 0 || data->new_keycode != combo->keycode)
- {
- return TRUE;
- }
+ is_conflict = data->new_keyval == combo->keyval;
+ else
+ is_conflict = combo->keyval == 0 && data->new_keycode == combo->keycode;
- return FALSE;
+ if (is_conflict)
+ data->conflict_item = item;
+
+ return is_conflict;
}
static gboolean
@@ -143,17 +142,14 @@ compare_keys_for_uniqueness (CcKeyboardItem *current_item,
if (reverse_item && cc_keyboard_item_is_hidden (current_item))
return FALSE;
- if (is_shortcut_different (data, current_item))
- return FALSE;
+ if (find_conflict (data, current_item))
+ return TRUE;
/* 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;
+ if (reverse_item && find_conflict (data, reverse_item))
+ return TRUE;
- return TRUE;
+ return FALSE;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]