After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 731618 - Handle 'reverse' shortcuts in the keyboard panel
Handle 'reverse' shortcuts in the keyboard panel
Status: RESOLVED FIXED
Product: gnome-control-center
Classification: Core
Component: Keyboard
unspecified
Other All
: Normal normal
: ---
Assigned To: Rui Matos
Control-Center Maintainers
Depends on: 732293 732295 732296 732385
Blocks:
 
 
Reported: 2014-06-13 13:53 UTC by Christophe Fergeau
Modified: 2014-08-17 18:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
keyboard: Split accel_edit_callback (10.11 KB, patch)
2014-06-13 13:53 UTC, Christophe Fergeau
committed Details | Review
keyboard: Add 'reverse' helpers to CcKeyboardItem (3.52 KB, patch)
2014-06-13 13:53 UTC, Christophe Fergeau
reviewed Details | Review
keyboard: Parse 'reverse' and 'is-reversed' (3.76 KB, patch)
2014-06-13 13:53 UTC, Christophe Fergeau
accepted-commit_now Details | Review
keyboard: Suggest to automatically set reverse bindings (4.84 KB, patch)
2014-06-13 13:54 UTC, Christophe Fergeau
needs-work Details | Review
keyboard: Add 'reverse' metadata to switch-input-source shortcuts (1.60 KB, patch)
2014-06-13 13:54 UTC, Christophe Fergeau
committed Details | Review
region: Remove "Shift" hack from region panel (1.11 KB, patch)
2014-06-13 13:54 UTC, Christophe Fergeau
committed Details | Review
For reference, gsettings-desktop-schemas patch (1.56 KB, patch)
2014-06-13 13:56 UTC, Christophe Fergeau
reviewed Details | Review
For reference, mutter patch which will be used to let gnome-control-center manage switch-input-source-backwards (2.45 KB, patch)
2014-06-13 13:57 UTC, Christophe Fergeau
reviewed Details | Review
For reference, gnome-shell patches to let gnome-control-center handle switch-input-source-backwards shortcut (4.46 KB, patch)
2014-06-13 13:59 UTC, Christophe Fergeau
reviewed Details | Review
keyboard: Add 'reverse' helpers to CcKeyboardItem (2.94 KB, patch)
2014-06-17 12:24 UTC, Christophe Fergeau
accepted-commit_now Details | Review
keyboard: Parse 'reverse' and 'is-reversed' (4.75 KB, patch)
2014-06-17 12:24 UTC, Christophe Fergeau
committed Details | Review
keyboard: Add 'reverse' helpers to CcKeyboardItem (3.01 KB, patch)
2014-06-25 14:43 UTC, Christophe Fergeau
committed Details | Review
fixup! keyboard: Suggest to automatically set reverse bindings (1.53 KB, patch)
2014-06-25 14:50 UTC, Christophe Fergeau
none Details | Review
keyboard: Suggest to automatically set reverse bindings (5.18 KB, patch)
2014-06-25 14:50 UTC, Christophe Fergeau
accepted-commit_now Details | Review
keyboard: Suggest to automatically set reverse bindings (5.83 KB, patch)
2014-06-28 10:15 UTC, Christophe Fergeau
none Details | Review
keyboard: Add support for hidden keybinding XML data (5.28 KB, patch)
2014-06-28 12:01 UTC, Christophe Fergeau
reviewed Details | Review
keyboard: Add support for hidden keybinding XML data (5.27 KB, patch)
2014-07-29 09:01 UTC, Christophe Fergeau
committed Details | Review
keyboard: Suggest to automatically set reverse bindings (6.32 KB, patch)
2014-07-29 09:04 UTC, Christophe Fergeau
committed Details | Review

Description Christophe Fergeau 2014-06-13 13:53:31 UTC
Some shortcuts (alt-tab, switch-input-source, ...) have implicit 'reverse'
actions to move the selector in the opposite direction (alt-shift-tab for example). At the moment this tends to be hardcoded/hidden in other places.

This series add some metadata to the .xml files used by the keyboard panel
so that it knows that such 'reverse' shortcuts are related, and so that it
can suggest to change the associated binding when changing alt-tab (for example).

The last patches in this series enable this for the 'switch-input-source'
shortcut, but this can be changed for more shortcuts. For this to work with swit-input-source, additional patches in other places in the stack are needed.
Comment 1 Christophe Fergeau 2014-06-13 13:53:38 UTC
Created attachment 278401 [details] [review]
keyboard: Split accel_edit_callback

This function is getting a bit big, and the next commits will add more
code to it.
Comment 2 Christophe Fergeau 2014-06-13 13:53:45 UTC
Created attachment 278402 [details] [review]
keyboard: Add 'reverse' helpers to CcKeyboardItem

In order to handle shortcuts which can be reversed (for example,
super-space and shift-super-space to switch input methods
forward/backward), we are going to add new attributes to the xml files
describing the keyboard shortcuts to show in the panel.

This commit is a first step towards that and adds the notion of
'reverse' items to CcKeyboardItem.

We will then indicate in the xml description files that
'switch-input-source' is reversed by 'switch-input-source-backward' and
that 'switch-input-source-backward' reverses 'switch-input-source'.
Comment 3 Christophe Fergeau 2014-06-13 13:53:53 UTC
Created attachment 278403 [details] [review]
keyboard: Parse 'reverse' and 'is-reversed'

This commit adds support for 'reverse' and 'is-reversed' attributes when
parsing the KeyListEntry XML node.
Comment 4 Christophe Fergeau 2014-06-13 13:54:03 UTC
Created attachment 278404 [details] [review]
keyboard: Suggest to automatically set reverse bindings

Since we now know when a binding has a 'reverse' binding, we can now
suggest to update the 'reverse' shortcut when the user set a shortcut
for one of them.
Comment 5 Christophe Fergeau 2014-06-13 13:54:11 UTC
Created attachment 278405 [details] [review]
keyboard: Add 'reverse' metadata to switch-input-source shortcuts

Now that the keyboard panel knows how to handle reverse shortcuts, we
can start annotating the existing ones with the needed XML attributes.
This commit does that with switch-input-source{-backward}.
Note that some changes in some modules are needed for this to work
correctly.
In this case, a default value needs to be set for
switch-input-source-backward in gsettings-desktop-schemas, and the
Meta.KeyBindingFlags.REVERSED flag needs to be removed from the
shortcuts defined in gnome-shell source. Instead of having
mutter handle the reversion with 'shift' by itself, it's now handled
explicitly through gsettings keys.
Comment 6 Christophe Fergeau 2014-06-13 13:54:19 UTC
Created attachment 278406 [details] [review]
region: Remove "Shift" hack from region panel

The region panel hardcodes that to switch input source backward, one
uses the shift modfier with the shortcut to switch input source forward.
Comment 7 Christophe Fergeau 2014-06-13 13:56:02 UTC
Created attachment 278407 [details] [review]
For reference, gsettings-desktop-schemas patch

Add default binding for switch-input-source-backward

Currently mutter/gnome-shell make sure switch-input-source-backward
shortcut is set to <Shift> + switch-input-source shortcut, but this
is being moved to gnome-control-center, which needs the default value to
be set.
Comment 8 Christophe Fergeau 2014-06-13 13:57:28 UTC
Created attachment 278408 [details] [review]
For reference, mutter patch which will be used to let gnome-control-center manage switch-input-source-backwards

Add meta_key_binding_is_reversed()

MetaKeyBinding can be marked as being reversed
(META_KEY_BINDING_IS_REVERSED), but MetaKeyHandlerFunc callbacks
cannot check whether this flag was set or not on the MetaKeyBinding
which triggered the callback.
Comment 9 Christophe Fergeau 2014-06-13 13:59:19 UTC
Created attachment 278409 [details] [review]
For reference, gnome-shell patches to let gnome-control-center handle switch-input-source-backwards shortcut
Comment 10 Rui Matos 2014-06-15 18:02:47 UTC
Review of attachment 278405 [details] [review]:

ok
Comment 11 Rui Matos 2014-06-15 18:03:19 UTC
Review of attachment 278404 [details] [review]:

other than the style nits

::: panels/keyboard/keyboard-shortcuts.c
@@ +1553,3 @@
+  if (reverse_item != NULL)
+    {
+       handle_reverse_item(item, reverse_item, keyval, mask, keycode, view);

no braces, space before parentheses
Comment 12 Rui Matos 2014-06-15 18:03:47 UTC
Review of attachment 278403 [details] [review]:

Mostly fine

::: panels/keyboard/keyboard-shortcuts.c
@@ +429,3 @@
             context = *attr_values;
+	} else if (g_str_equal (*attr_names, "reverse-entry")) {
+	    reverse_entry = *attr_values;

This lets zero length strings through. Any reason for that?

@@ +431,3 @@
+	    reverse_entry = *attr_values;
+	} else if (g_str_equal (*attr_names, "is-reversed")) {
+	    if (g_str_equal (*attr_values, "true")) {

no curlies
Comment 13 Rui Matos 2014-06-15 18:04:16 UTC
Review of attachment 278402 [details] [review]:

::: panels/keyboard/cc-keyboard-item.c
@@ +40,3 @@
   /* internal */
+  char *reverse_item_name;
+  gboolean is_reversed;

Couldn't we just link to another CcKeyboardItem directly with a pointer?

@@ +473,3 @@
 }
 
+static GHashTable *reverse_items = NULL;

... would allow us to avoid this table that never gets freed.

@@ +485,3 @@
+    {
+      reverse_items = g_hash_table_new_full (g_str_hash, g_str_equal,
+	                                       NULL, g_object_unref);

strange indentation

@@ +493,3 @@
+
+  g_hash_table_insert(reverse_items, item->key,
+                      g_object_ref(G_OBJECT(item)));

lack of spaces before opening parentheses

@@ +496,3 @@
+}
+
+CcKeyboardItem * cc_keyboard_item_get_reverse_item (CcKeyboardItem *item)

the return type should go in a different line

@@ +498,3 @@
+CcKeyboardItem * cc_keyboard_item_get_reverse_item (CcKeyboardItem *item)
+{
+  if (item->priv->reverse_item_name == NULL) {

no need for curly braces here, and please never on the same line as the condition
Comment 14 Rui Matos 2014-06-15 18:04:27 UTC
Review of attachment 278401 [details] [review]:

Nice
Comment 15 Rui Matos 2014-06-15 18:04:45 UTC
Review of attachment 278406 [details] [review]:

yep
Comment 16 Rui Matos 2014-06-15 18:06:24 UTC
I generally like this. Do you plan to submit patches for gsettings-desktop-schemas, mutter and gnome-shell porting all the keybindinds? If you do please mark those bugs as blocking this one. Thanks!
Comment 17 Christophe Fergeau 2014-06-16 08:45:26 UTC
(In reply to comment #16)
> I generally like this. Do you plan to submit patches for
> gsettings-desktop-schemas, mutter and gnome-shell porting all the keybindinds?
> If you do please mark those bugs as blocking this one. Thanks!

I definitely will open bugs for the other patches now that I got an ok on the sanity of  this series.
I did not open them at the same time as this bug to avoid bug-spamming multiple components if a different approach was suggested during the review of these control center patches.
Comment 18 Christophe Fergeau 2014-06-17 12:13:28 UTC
Review of attachment 278403 [details] [review]:

::: panels/keyboard/keyboard-shortcuts.c
@@ +429,3 @@
             context = *attr_values;
+	} else if (g_str_equal (*attr_names, "reverse-entry")) {
+	    reverse_entry = *attr_values;

No particular reason, changed.
Comment 19 Christophe Fergeau 2014-06-17 12:18:44 UTC
Review of attachment 278402 [details] [review]:

::: panels/keyboard/cc-keyboard-item.c
@@ +40,3 @@
   /* internal */
+  char *reverse_item_name;
+  gboolean is_reversed;

Hmm yes that's doable, however this requires a bit more smartness in the parser if we don't want to require that one item and its reversed item always come in a given order. This also forces one item and its reversed item to be defined in the same xml file, but that's probably a reasonable assumption to make.
Comment 20 Christophe Fergeau 2014-06-17 12:21:40 UTC
2 minor things which don't work perfectly yet:

- setting switch-im-source to 'shift-space' suggests setting the reverse action to 'space' which is definitely not what we want ;)
- if switch-im-source-backwards is set to 'shift-alt-space', trying to set switch-im-source to this shortcut will result in gnome-control-center reporting conflicting shortcuts rather than suggesting to change switch-im-source-backwards to 'alt-space'
Comment 21 Christophe Fergeau 2014-06-17 12:24:36 UTC
Created attachment 278595 [details] [review]
keyboard: Add 'reverse' helpers to CcKeyboardItem

In order to handle shortcuts which can be reversed (for example,
super-space and shift-super-space to switch input methods
forward/backward), we are going to add new attributes to the xml files
describing the keyboard shortcuts to show in the panel.

This commit is a first step towards that and adds the notion of
'reverse' items to CcKeyboardItem.

We will then indicate in the xml description files that
'switch-input-source' is reversed by 'switch-input-source-backward' and
that 'switch-input-source-backward' reverses 'switch-input-source'.
Comment 22 Christophe Fergeau 2014-06-17 12:24:42 UTC
Created attachment 278596 [details] [review]
keyboard: Parse 'reverse' and 'is-reversed'

This commit adds support for 'reverse' and 'is-reversed' attributes when
parsing the KeyListEntry XML node.
Comment 23 Rui Matos 2014-06-17 14:32:37 UTC
(In reply to comment #20)
> 2 minor things which don't work perfectly yet:

Right, both can be handled in handle_reverse_item() I think:

> - setting switch-im-source to 'shift-space' suggests setting the reverse action
> to 'space' which is definitely not what we want ;)

We should call is_valid_binding() with the reversed mask at the beginning of handle_reverse_item() and bail out if it's not allowed.

> - if switch-im-source-backwards is set to 'shift-alt-space', trying to set
> switch-im-source to this shortcut will result in gnome-control-center reporting
> conflicting shortcuts rather than suggesting to change
> switch-im-source-backwards to 'alt-space'

Should be a matter of checking if (reverse_conflict_item == item) .
Comment 24 Rui Matos 2014-06-17 14:33:03 UTC
Comment on attachment 278404 [details] [review]
keyboard: Suggest to automatically set reverse bindings

According to the previous comment
Comment 25 Rui Matos 2014-06-17 15:03:47 UTC
Review of attachment 278595 [details] [review]:

ok
Comment 26 Rui Matos 2014-06-17 15:09:08 UTC
Review of attachment 278596 [details] [review]:

looks fine
Comment 27 Rui Matos 2014-06-17 15:10:41 UTC
Review of attachment 278595 [details] [review]:

::: panels/keyboard/cc-keyboard-item.c
@@ +481,3 @@
+  item->priv->reverse_item = reverse_item;
+  if (reverse_item->priv->reverse_item == NULL)
+    reverse_item->priv->reverse_item = item;

We should be setting reverse_item->priv->is_reversed here as well.
Comment 28 Christophe Fergeau 2014-06-25 14:43:24 UTC
Created attachment 279225 [details] [review]
keyboard: Add 'reverse' helpers to CcKeyboardItem

In order to handle shortcuts which can be reversed (for example,
super-space and shift-super-space to switch input methods
forward/backward), we are going to add new attributes to the xml files
describing the keyboard shortcuts to show in the panel.

This commit is a first step towards that and adds the notion of
'reverse' items to CcKeyboardItem.

We will then indicate in the xml description files that
'switch-input-source' is reversed by 'switch-input-source-backward' and
that 'switch-input-source-backward' reverses 'switch-input-source'.
Comment 29 Christophe Fergeau 2014-06-25 14:50:13 UTC
Created attachment 279226 [details] [review]
fixup! keyboard: Suggest to automatically set reverse bindings

This goes on top of the patch of the same name and should fix the pecularities in it
Comment 30 Christophe Fergeau 2014-06-25 14:50:43 UTC
Created attachment 279227 [details] [review]
keyboard: Suggest to automatically set reverse bindings

Since we now know when a binding has a 'reverse' binding, we can now
suggest to update the 'reverse' shortcut when the user set a shortcut
for one of them.
Comment 31 Rui Matos 2014-06-25 18:52:48 UTC
Review of attachment 279225 [details] [review]:

looks fine
Comment 32 Rui Matos 2014-06-25 18:57:28 UTC
Review of attachment 279227 [details] [review]:

ok
Comment 33 Christophe Fergeau 2014-06-27 09:09:26 UTC
(In reply to comment #16)
> I generally like this. Do you plan to submit patches for
> gsettings-desktop-schemas, mutter and gnome-shell porting all the keybindinds?
> If you do please mark those bugs as blocking this one. Thanks!

For the record, switch-input-source-backward is the only '-backward' keybinding that we currently show in gnome-control-center UI. In order to handle the other keybindings, a little bit more work will be needed here so that we can mark some KeyListEntry as not showing up in the UI. We need the KeyListEntry for all the -backward keybindings so that gnome-control-center can detect the duplicates, and so that it has a human-readable name for the binding.
Comment 34 Christophe Fergeau 2014-06-28 10:15:29 UTC
Created attachment 279469 [details] [review]
keyboard: Suggest to automatically set reverse bindings

Since we now know when a binding has a 'reverse' binding, we can now
suggest to update the 'reverse' shortcut when the user set a shortcut
for one of them.

--

Yet another iteration to fix another bug in a corner case:
- set switch-input-source to ctrl + space
- try to set switch-input-source-backward to ctrl + space
-> a dialog is displayed asking if you want to set switch-input-source to shift + ctrl + space
- press 'cancel'
-> both switch-input-source and switch-input-source-backward are set to ctrl + space

I've added a final check for duplicate at the end of show_reverse_item_dialog, and silently unset the conflicting binding. This seemed better than popping another dialog notifying of the conflict.
Comment 35 Christophe Fergeau 2014-06-28 10:17:55 UTC
(In reply to comment #34)
> 
> I've added a final check for duplicate at the end of show_reverse_item_dialog,

s/show_reverse_item_dialog/handle_reverse_item

> and silently unset the conflicting binding. This seemed better than popping
> another dialog notifying of the conflict.
Comment 36 Christophe Fergeau 2014-06-28 11:11:34 UTC
Hrm, still one more thing which is missing
- unset switch-input-source and switch-input-source-backward
- set any other keybinding to super+space
- set switch-input-source to super+space
-> the 'conflict dialog' shows up but there is no suggestion/attempt to set switch-input-source-backward to super+shift+space
Comment 37 Christophe Fergeau 2014-06-28 12:01:56 UTC
Created attachment 279477 [details] [review]
keyboard: Add support for hidden keybinding XML data

If a KeyListEntry has a hidden="true" attribute, then the corresponding
binding information will be loaded as usual, but the binding won't be
displayed in the user interface.

This is useful as the keyboard panel will take into account hidden
keybindings when detecting conflicting shortcuts, or to suggest to set a
reverse shortcut.

For now, this will be used for the various reverse mutter keybindings
({switch,cycle}.*-backward) as they should not be shown in the UI, but
we still want the keyboard panel to know about them.
Comment 38 Rui Matos 2014-06-29 15:52:53 UTC
Review of attachment 279477 [details] [review]:

Code looks fine but why is the CcKeyboardItem variable and methods called "visible" instead of "hidden" ? I think this is just added cognitive overhead for no good reason.
Comment 39 Rui Matos 2014-06-29 16:18:18 UTC
(In reply to comment #36)
> Hrm, still one more thing which is missing
> - unset switch-input-source and switch-input-source-backward
> - set any other keybinding to super+space
> - set switch-input-source to super+space
> -> the 'conflict dialog' shows up but there is no suggestion/attempt to set
> switch-input-source-backward to super+shift+space

Ugh. Will you fix that and attach a new patch?
Comment 40 Christophe Fergeau 2014-07-02 17:10:05 UTC
Review of attachment 279477 [details] [review]:

No very good reason, just some remnants of how this patch evolved during development, I'll change it.
Comment 41 Bastien Nocera 2014-07-18 15:58:09 UTC
Comment on attachment 278407 [details] [review]
For reference, gsettings-desktop-schemas patch

Marking as review, as this is handled in bug 732293.
Comment 42 Bastien Nocera 2014-07-18 15:58:54 UTC
Comment on attachment 278408 [details] [review]
For reference, mutter patch which will be used to let gnome-control-center manage switch-input-source-backwards

Marking as reviewed, handled in bug 732295
Comment 43 Bastien Nocera 2014-07-18 15:59:40 UTC
Comment on attachment 278409 [details] [review]
For reference, gnome-shell patches to let gnome-control-center handle switch-input-source-backwards shortcut

Marking as reviewed, handled in bug 732295
Comment 44 Christophe Fergeau 2014-07-29 09:01:02 UTC
Created attachment 281920 [details] [review]
keyboard: Add support for hidden keybinding XML data

If a KeyListEntry has a hidden="true" attribute, then the corresponding
binding information will be loaded as usual, but the binding won't be
displayed in the user interface.

This is useful as the keyboard panel will take into account hidden
keybindings when detecting conflicting shortcuts, or to suggest to set a
reverse shortcut.

For now, this will be used for the various reverse mutter keybindings
({switch,cycle}.*-backward) as they should not be shown in the UI, but
we still want the keyboard panel to know about them.
Comment 45 Christophe Fergeau 2014-07-29 09:04:26 UTC
(In reply to comment #39)
> (In reply to comment #36)
> > Hrm, still one more thing which is missing
> > - unset switch-input-source and switch-input-source-backward
> > - set any other keybinding to super+space
> > - set switch-input-source to super+space
> > -> the 'conflict dialog' shows up but there is no suggestion/attempt to set
> > switch-input-source-backward to super+shift+space
> 
> Ugh. Will you fix that and attach a new patch?

Should be fixed with the patch below added to "keyboard: Suggest to automatically set reverse bindings". This causes the 'conflict' dialog to show first, and if the user agrees to move forward and disable the conflicting shortcut, then a second dialog will popup and suggest setting the 'reverse' shortcut.

diff --git a/panels/keyboard/keyboard-shortcuts.c b/panels/keyboard/keyboard-sho
index 3820893..1023bf0 100644
--- a/panels/keyboard/keyboard-shortcuts.c
+++ b/panels/keyboard/keyboard-shortcuts.c
@@ -1564,6 +1564,8 @@ accel_edited_callback (GtkCellRendererText   *cell,
           g_object_set (G_OBJECT (item), "binding", str, NULL);
 
           g_free (str);
+          if (reverse_item == NULL)
+            return;
         }
       else
         {
@@ -1573,9 +1575,9 @@ accel_edited_callback (GtkCellRendererText   *cell,
                         "keycode", item->keycode,
                         "accel-mods", item->mask,
                         NULL);
+          return;
         }
 
-      return;
     }
 
   str = binding_name (keyval, keycode, mask, FALSE);
Comment 46 Christophe Fergeau 2014-07-29 09:04:53 UTC
Created attachment 281921 [details] [review]
keyboard: Suggest to automatically set reverse bindings

Since we now know when a binding has a 'reverse' binding, we can now
suggest to update the 'reverse' shortcut when the user set a shortcut
for one of them.
Comment 47 Rui Matos 2014-08-02 16:43:36 UTC
Review of attachment 281920 [details] [review]:

looks fine
Comment 48 Rui Matos 2014-08-02 16:47:45 UTC
Review of attachment 281921 [details] [review]:

Please push this.
Comment 49 Christophe Fergeau 2014-08-17 18:21:07 UTC
Attachment 278401 [details] pushed as 10fd199 - keyboard: Split accel_edit_callback
Attachment 278405 [details] pushed as c77d164 - keyboard: Add 'reverse' metadata to switch-input-source shortcuts
Attachment 278406 [details] pushed as 5572fb9 - region: Remove "Shift" hack from region panel
Attachment 278596 [details] pushed as f7c095b - keyboard: Parse 'reverse' and 'is-reversed'
Attachment 279225 [details] pushed as f059f42 - keyboard: Add 'reverse' helpers to CcKeyboardItem
Attachment 281920 [details] pushed as ba9a8bc - keyboard: Add support for hidden keybinding XML data
Attachment 281921 [details] pushed as 5147cf2 - keyboard: Suggest to automatically set reverse bindings