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 697002 - Grab and emit a signal when XK_ISO_Next_Group is pressed
Grab and emit a signal when XK_ISO_Next_Group is pressed
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: mutter-maint
mutter-maint
: 692017 693747 695238 698185 (view as bug list)
Depends on:
Blocks: 697008 700346
 
 
Reported: 2013-03-31 21:52 UTC by Rui Matos
Modified: 2013-05-24 23:24 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Grab and emit a signal when XK_ISO_Next_Group is pressed (16.11 KB, patch)
2013-03-31 21:52 UTC, Rui Matos
none Details | Review
Grab and emit a signal when XK_ISO_Next_Group is pressed (16.30 KB, patch)
2013-04-04 10:03 UTC, Rui Matos
none Details | Review
display: Add signal 'modifiers-accelerator-activated' (2.33 KB, patch)
2013-04-10 11:40 UTC, Rui Matos
none Details | Review
prefs: Track the XKB 'grp:' option in gsettings as a keybinding pref (5.39 KB, patch)
2013-04-10 11:40 UTC, Rui Matos
none Details | Review
keybindings: Grab and emit a signal when XK_ISO_Next_Group is pressed (9.63 KB, patch)
2013-04-10 11:41 UTC, Rui Matos
none Details | Review
display: Add signal 'modifiers-accelerator-activated' (3.56 KB, patch)
2013-05-04 19:44 UTC, Rui Matos
reviewed Details | Review
prefs: Track the XKB 'grp:' option in gsettings as a keybinding pref (5.39 KB, patch)
2013-05-04 19:44 UTC, Rui Matos
needs-work Details | Review
keybindings: Grab and emit a signal when XK_ISO_Next_Group is pressed (9.80 KB, patch)
2013-05-04 19:45 UTC, Rui Matos
reviewed Details | Review
prefs: Track the XKB 'grp:' option in gsettings as a keybinding pref (4.79 KB, patch)
2013-05-13 21:10 UTC, Rui Matos
committed Details | Review
keybindings: Grab and emit a signal when XK_ISO_Next_Group is pressed (12.17 KB, patch)
2013-05-13 21:21 UTC, Rui Matos
committed Details | Review

Description Rui Matos 2013-03-31 21:52:24 UTC
This is what I finally ended up doing to tackle the modifiers-only
keybinding problem.

Capturing XK_ISO_Next_Group was Ray's suggestion some time ago but it
couldn't be done outside mutter/gnome-shell because then the capturing
wouldn't work in the overview but the actual XKB group index switch
would be performed on the X server.

For the setting itself I'm using the xkb-options key we already have
in org.gnome.desktop.input-sources.
Comment 1 Rui Matos 2013-03-31 21:52:26 UTC
Created attachment 240262 [details] [review]
Grab and emit a signal when XK_ISO_Next_Group is pressed

This will make it possible to implement input source switching in
gnome-shell using the popular modifiers-only keybinding that's
implemented on the X server through an XKB option.
Comment 2 Rui Matos 2013-04-02 07:21:48 UTC
*** Bug 693747 has been marked as a duplicate of this bug. ***
Comment 3 Rui Matos 2013-04-02 08:04:09 UTC
*** Bug 695238 has been marked as a duplicate of this bug. ***
Comment 4 Rui Matos 2013-04-02 23:00:29 UTC
*** Bug 692017 has been marked as a duplicate of this bug. ***
Comment 5 Rui Matos 2013-04-04 10:03:45 UTC
Created attachment 240576 [details] [review]
Grab and emit a signal when XK_ISO_Next_Group is pressed

--

* Added "shifts_toggle" for both shifts
* Fixed disabling the option
Comment 6 Rui Matos 2013-04-09 11:37:56 UTC
I realized I should perhaps post the pros and cons of using XK_ISO_Next_Group instead of defining our own combos.

Pros:

a) being the compositor we can actually now grab that everywhere
unlike a 3rd process like the g-s-d helper in 3.6;

b) we don't have to play tricks for the CapsLock key (having to undo
the caps lock...) because the X server handles it already;

c) the users wanting this feature are already used to that specific
set of options and the way it works;

d) since I'm targeting 3.8.1, I didn't want to add a gsettings
dependency on the org.gnome.settings-daemon.peripherals.keyboard
schema where the 3.6 setting lives (and I always intended that one to
be temporary);

e) it just works if people have it configured in their xorg.conf since g-s-d already has code to set the gsettings key from that.


Cons:

a) no flexibility in which combos exist;

b) less future proof, i.e. will have to be totally re-done for wayland, but then, so many other things are.
Comment 7 Rui Matos 2013-04-10 11:40:21 UTC
Created attachment 241136 [details] [review]
display: Add signal 'modifiers-accelerator-activated'

We'll trigger this on a special modifiers-only keybinding.
Comment 8 Rui Matos 2013-04-10 11:40:28 UTC
Created attachment 241137 [details] [review]
prefs: Track the XKB 'grp:' option in gsettings as a keybinding pref

We'll use the value of this option to establish a passive grab on the
keycode/modifier combos generating XK_ISO_Next_Group.
Comment 9 Rui Matos 2013-04-10 11:41:12 UTC
Created attachment 241138 [details] [review]
keybindings: Grab and emit a signal when XK_ISO_Next_Group is pressed

--

I've splitted this patch.
Comment 10 Rui Matos 2013-04-17 12:18:11 UTC
*** Bug 698185 has been marked as a duplicate of this bug. ***
Comment 11 Jens Petersen 2013-04-18 01:45:24 UTC
Will this be in 3.8?
Comment 12 Rui Matos 2013-05-04 19:44:24 UTC
Created attachment 243309 [details] [review]
display: Add signal 'modifiers-accelerator-activated'

--

Florian pointed on IRC that freezing the keyboard by default breaks
stand-alone mutter and other libmutter users so I've changed the
signal to have a return value so that handlers can request freezing
explicitly but by default we unfreeze.
Comment 13 Rui Matos 2013-05-04 19:44:41 UTC
Created attachment 243310 [details] [review]
prefs: Track the XKB 'grp:' option in gsettings as a keybinding pref

--
Rebased.
Comment 14 Rui Matos 2013-05-04 19:45:54 UTC
Created attachment 243311 [details] [review]
keybindings: Grab and emit a signal when XK_ISO_Next_Group is pressed

--
Rebased.
Comment 15 Florian Müllner 2013-05-13 13:16:20 UTC
Review of attachment 243309 [details] [review]:

I'm not sure the patch makes a lot of sense on its own (signal return value?), maybe just squash it with the main patch ...

::: src/core/display.c
@@ +290,3 @@
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  meta_display_boolean_accumulator, NULL, NULL,

Is there really a use case for more than one signal connection? I think g_signal_accumulator_first_wins() should work just fine here ...
Comment 16 Florian Müllner 2013-05-13 13:16:33 UTC
Review of attachment 243310 [details] [review]:

::: src/core/prefs.c
@@ +1054,3 @@
     handle_preference_update_int (settings, key);
+  else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING) ||
+           g_variant_type_equal (type, G_VARIANT_TYPE_STRING_ARRAY))

No. handle_preference_update_string() happens to work for other types when using a handler, but that's no excuse for ignoring that it will fail horribly when using the target branch.
Either add proper support for string arrays (basically copy the handler branch of string properties and generalize the workspace-names stuff for the target branch) or handle KEY_XKB_OPTIONS explicitly in settings_changed (as is currently the case for workspace-names).
I'll file a bug for the former ...

@@ +1574,3 @@
 
+static void
+set_iso_next_group_option (const char *option)

This is an odd function to have - I'd prefer this in iso_next_group_handler(), along the lines of:

char *value = NULL;
...
for (p = xkb_options; p && *p; ++p)
  if (g_str_has_prefix (*p, "grp:"))
    {
      value = g_strdup (*p + 4);
      break
    }

changed = g_strcmp0 (iso_next_group_option, value) != 0;

if (iso_next_group_option)
  g_free (iso_next_group_option);
iso_next_group_option = value;

if (changed)
  queue_changed (META_PREF_KEYBINDINGS);

@@ +2158,3 @@
+meta_prefs_get_iso_next_group_option (void)
+{
+  return g_strdup (iso_next_group_option);

This is the first and only preference that transfers ownership; please don't, unless there's a very good reason for that which I missed.
Comment 17 Florian Müllner 2013-05-13 13:16:46 UTC
Review of attachment 243311 [details] [review]:

::: src/core/keybindings.c
@@ +155,3 @@
 static GHashTable *external_grabs;
 
+static char         *iso_next_group_option;

Odd to cache this both in prefs.c and here - without the strdup (see earlier review), you can just use the prefs getter directly ...

@@ +157,3 @@
+static char         *iso_next_group_option;
+static MetaKeyCombo *iso_next_group_combos;
+static int           n_iso_next_group_combos;

Maybe put those two into MetaDisplay (as overlay_combo)?

@@ +308,3 @@
 
+static int
+get_keycodes_for_keysym (MetaDisplay  *display,

This is basically gdk_keymap_get_entries_for_keyval(), no?
Comment 18 Rui Matos 2013-05-13 21:10:22 UTC
Created attachment 244112 [details] [review]
prefs: Track the XKB 'grp:' option in gsettings as a keybinding pref

--
(In reply to comment #16)
> ::: src/core/prefs.c
> @@ +1054,3 @@
>      handle_preference_update_int (settings, key);
> +  else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING) ||
> +           g_variant_type_equal (type, G_VARIANT_TYPE_STRING_ARRAY))
>
> No. handle_preference_update_string() happens to work for other types when
> using a handler, but that's no excuse for ignoring that it will fail horribly
> when using the target branch.
> Either add proper support for string arrays (basically copy the handler branch
> of string properties and generalize the workspace-names stuff for the target
> branch) or handle KEY_XKB_OPTIONS explicitly in settings_changed (as is
> currently the case for workspace-names).
> I'll file a bug for the former ...

Yes, I feared you'd say that :-) Thanks for doing that, this is
rebased on your patch.

> @@ +1574,3 @@
>
> +static void
> +set_iso_next_group_option (const char *option)
>
> This is an odd function to have - I'd prefer this in iso_next_group_handler(),
> along the lines of:

[snip]

Agreed. I did something like that.

> @@ +2158,3 @@
> +meta_prefs_get_iso_next_group_option (void)
> +{
> +  return g_strdup (iso_next_group_option);
>
> This is the first and only preference that transfers ownership; please don't,
> unless there's a very good reason for that which I missed.

No good reason, just overlooked the fact we didn't need the copy. Fixed
Comment 19 Rui Matos 2013-05-13 21:21:57 UTC
Created attachment 244113 [details] [review]
keybindings: Grab and emit a signal when XK_ISO_Next_Group is pressed

--
(In reply to comment #15)
> I'm not sure the patch makes a lot of sense on its own (signal return value?),
> maybe just squash it with the main patch ...

Ok, squashed it.

> ::: src/core/display.c
> @@ +290,3 @@
> +                  G_SIGNAL_RUN_LAST,
> +                  0,
> +                  meta_display_boolean_accumulator, NULL, NULL,
>
> Is there really a use case for more than one signal connection? I think
> g_signal_accumulator_first_wins() should work just fine here ...

No, that's fine. I didn't know about this predefined accumulator!

(In reply to comment #17)
> @@ +157,3 @@
> +static char         *iso_next_group_option;
> +static MetaKeyCombo *iso_next_group_combos;
> +static int           n_iso_next_group_combos;
>
> Maybe put those two into MetaDisplay (as overlay_combo)?

Ok.

> @@ +308,3 @@
>
> +static int
> +get_keycodes_for_keysym (MetaDisplay  *display,
>
> This is basically gdk_keymap_get_entries_for_keyval(), no?

Yes, it didn't feel right to access GDK here since mutter tracks the X
keymap itself already. I'm not even sure it would work, I didn't
investigate if mutter is passing the relevant events to GDK for it to
update its view of the keymap.

So I basically copied the non XKB version of
gdk_x11_keymap_get_entries_for_keyval() since it's simpler and we
don't really need to care about XKB groups for our purposes here. I
added a comment about where the code came from.
Comment 20 Florian Müllner 2013-05-13 21:36:57 UTC
Review of attachment 244112 [details] [review]:

OK
Comment 21 Florian Müllner 2013-05-13 21:45:22 UTC
Review of attachment 244113 [details] [review]:

(In reply to comment #19)
> Yes, it didn't feel right to access GDK here since mutter tracks the X
> keymap itself already.

Yes, it's not immediately suitable - also the hacking guide still mentions that gdk/gtk+ shouldn't be used outside ui/ (though some symbols have been sneaked in). This was just a drive-by comment to see if I got the source right :-)


> I added a comment about where the code came from.

That's definitively a good idea, yeah.
Comment 22 Rui Matos 2013-05-24 21:53:03 UTC
Attachment 244112 [details] pushed as d664cfc - prefs: Track the XKB 'grp:' option in gsettings as a keybinding pref
Attachment 244113 [details] pushed as 7186ddf - keybindings: Grab and emit a signal when XK_ISO_Next_Group is pressed
Comment 23 Florian Müllner 2013-05-24 23:14:03 UTC
Why aren't those patches on master?
Comment 24 Rui Matos 2013-05-24 23:23:12 UTC
(In reply to comment #23)
> Why aren't those patches on master?

Basically just because I haven't been running master branches for a while and I want to test this stuff there before pushing. And as it takes a while to switch everything I'm thinking of doing it tomorrow instead of now :-)
Comment 25 Florian Müllner 2013-05-24 23:24:38 UTC
OK - I was just wondering :-)