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
This commit is contained in:
parent
5e4fa7bd39
commit
ab353591f8
1 changed files with 15 additions and 19 deletions
|
@ -102,25 +102,24 @@ get_binding_from_variant (GVariant *variant)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_shortcut_different (CcUniquenessData *data,
|
find_conflict (CcUniquenessData *data,
|
||||||
CcKeyboardItem *item)
|
CcKeyboardItem *item)
|
||||||
{
|
{
|
||||||
CcKeyCombo *combo = item->primary_combo;
|
CcKeyCombo *combo = item->primary_combo;
|
||||||
|
gboolean is_conflict = FALSE;
|
||||||
|
|
||||||
if (data->orig_item && cc_keyboard_item_equal (data->orig_item, item))
|
if (data->orig_item && cc_keyboard_item_equal (data->orig_item, item))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (data->new_keyval != 0)
|
if (data->new_keyval != 0)
|
||||||
{
|
is_conflict = data->new_keyval == combo->keyval;
|
||||||
if (data->new_keyval != combo->keyval)
|
else
|
||||||
return TRUE;
|
is_conflict = combo->keyval == 0 && data->new_keycode == combo->keycode;
|
||||||
}
|
|
||||||
else if (combo->keyval != 0 || data->new_keycode != combo->keycode)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
if (is_conflict)
|
||||||
|
data->conflict_item = item;
|
||||||
|
|
||||||
|
return is_conflict;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -143,17 +142,14 @@ compare_keys_for_uniqueness (CcKeyboardItem *current_item,
|
||||||
if (reverse_item && cc_keyboard_item_is_hidden (current_item))
|
if (reverse_item && cc_keyboard_item_is_hidden (current_item))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (is_shortcut_different (data, current_item))
|
if (find_conflict (data, current_item))
|
||||||
return FALSE;
|
return TRUE;
|
||||||
|
|
||||||
/* Also check for the reverse item if any */
|
/* Also check for the reverse item if any */
|
||||||
if (reverse_item && is_shortcut_different (data, reverse_item))
|
if (reverse_item && find_conflict (data, reverse_item))
|
||||||
return FALSE;
|
return TRUE;
|
||||||
|
|
||||||
/* No tests failed and we found a conflict */
|
return FALSE;
|
||||||
data->conflict_item = current_item;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue