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 686613 - Caps Lock can't be set as keyboard layout switch shortcut
Caps Lock can't be set as keyboard layout switch shortcut
Status: RESOLVED FIXED
Product: gnome-settings-daemon
Classification: Core
Component: keyboard
3.6.x
Other Linux
: Normal normal
: ---
Assigned To: gnome-settings-daemon-maint
gnome-settings-daemon-maint
: 687929 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2012-10-22 08:56 UTC by Dmitry Shachnev
Modified: 2012-11-15 13:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
keyboard: Add combos with Caps Lock to the input sources switcher (5.20 KB, patch)
2012-11-02 19:22 UTC, Rui Matos
needs-work Details | Review

Description Dmitry Shachnev 2012-10-22 08:56:04 UTC
Many users prefer to use CapsLock to switch their keyboard layouts, and that worked in GNOME up to 3.4 (and Shift+CapsLock did original CapsLock function). But starting with 3.6, the setting has been moved, and it's no longer possible to set CapsLock as the layout switch shortcut.

The only possible values for org.gnome.settings-daemon.peripherals.keyboard input-sources-switcher are combinations of alt, control and shift keys.
Comment 1 Vít Ondruch 2012-10-24 10:29:06 UTC
Not only that ... there is not possible to use common combinations such as just Ctrl+Shift, LShift+RShift or Shift+Capslock I was used to. That is pretty annoying.
Comment 2 Vít Ondruch 2012-10-24 10:30:20 UTC
May be the Configuration in Input Sources tab should allow that? But it is disabled all the time :/
Comment 3 Rui Matos 2012-10-24 14:30:16 UTC
(In reply to comment #0)
> Many users prefer to use CapsLock to switch their keyboard layouts, and that
> worked in GNOME up to 3.4 (and Shift+CapsLock did original CapsLock function).
> But starting with 3.6, the setting has been moved, and it's no longer possible
> to set CapsLock as the layout switch shortcut.

AFAICT, it's not possible to do this currently from an X client without also triggering Caps Lock itself, that's why I didn't add combinations with CapsLock.

A work around, if you don't need the CapsLock key functionality, is to set the ctrl:nocaps XKB option[1] and then choosing one the combinations that includes ctrl.

To fix this properly we'd need to hook into the X server's internal key event handling. Wayland should allow us to that.

[1] org.gnome.desktop.input-sources xkb-options

(In reply to comment #1)
> Not only that ... there is not possible to use common combinations such as just
> Ctrl+Shift, LShift+RShift or Shift+Capslock I was used to. That is pretty
> annoying.

Those are not configurable in the official UI at the moment. You can still use some of them by setting the gsettings key org.gnome.settings-daemon.peripherals.keyboard input-sources-switcher . gnome-tweak-tool gives you a UI for that key.
Comment 4 Dmitry Shachnev 2012-10-24 14:32:43 UTC
> AFAICT, it's not possible to do this currently from an X client without also
triggering Caps Lock itself, that's why I didn't add combinations with
CapsLock.

If so, how was it possible to do that in 3.4?
Comment 5 Rui Matos 2012-10-24 14:46:34 UTC
(In reply to comment #4)
> > AFAICT, it's not possible to do this currently from an X client without also
> triggering Caps Lock itself, that's why I didn't add combinations with
> CapsLock.
> 
> If so, how was it possible to do that in 3.4?

It was the X server switching among XKB group indexes. We don't use that anymore in GNOME, see http://git.gnome.org/browse/gnome-settings-daemon/commit/?id=b6e011ad16311e2985aa523cf9bceef74168f95e for the rationale.
Comment 6 Dmitry Shachnev 2012-10-24 15:00:19 UTC
Maybe you could add CapsLock to possible shortcuts and set ctrl:nocaps automatically when it's selected?
Comment 7 Rui Matos 2012-10-24 15:04:10 UTC
(In reply to comment #6)
> Maybe you could add CapsLock to possible shortcuts and set ctrl:nocaps
> automatically when it's selected?

And then deal with confused users that can't enable CapsLock any more? No thank you. You better know what you're getting into if you want to use that key.
Comment 8 gmRUQ7I8 2012-10-30 18:54:44 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > Maybe you could add CapsLock to possible shortcuts and set ctrl:nocaps
> > automatically when it's selected?
> 
> And then deal with confused users that can't enable CapsLock any more? No thank
> you. You better know what you're getting into if you want to use that key.

Who need this anyway? Caps lock, in its original meaning, is useless now days. It should been set as layout switcher by default long time ago, like a specific gnome feature.
Comment 9 Nikolay Bryskin 2012-10-30 22:33:13 UTC
(In reply to comment #3)
> A work around, if you don't need the CapsLock key functionality, is to set the
> ctrl:nocaps XKB option[1] and then choosing one the combinations that includes
> ctrl.
> 

This workaround doesn't allow to use capslock as a single key to switch layouts.
I confirm that this issue is a regression.
Comment 10 Rui Matos 2012-10-30 22:39:53 UTC
(In reply to comment #9)
> This workaround doesn't allow to use capslock as a single key to switch
> layouts.

It does. Run these commands:

$ gsettings set org.gnome.desktop.input-sources xkb-options "['ctrl:nocaps']"
$ gsettings set org.gnome.settings-daemon.peripherals.keyboard input-sources-switcher ctrl-l
Comment 11 Nikolay Bryskin 2012-10-30 23:02:05 UTC
Yep, you are right, but it also affects Ctrl key behavior that's annoying.
Comment 12 Valery Kharitonov 2012-10-31 08:08:28 UTC
(In reply to comment #11)
> Yep, you are right, but it also affects Ctrl key behavior that's annoying.

Yes, I confirm that.

Is it possible to use Capslock for switching layouts without affecting Ctrl key?
Comment 13 Rui Matos 2012-11-02 19:22:31 UTC
Created attachment 227922 [details] [review]
keyboard: Add combos with Caps Lock to the input sources switcher

--

There's a window of time where the lock is in effect: between when the
X server activates it on Caps Lock key press and we undo it on the
first key release. Can't see how to get rid of that.

Anyway, it works fine in practice. Please review.
Comment 14 Nikolay Bryskin 2012-11-02 21:02:48 UTC
(In reply to comment #13)
> Created an attachment (id=227922) [details] [review]
> keyboard: Add combos with Caps Lock to the input sources switcher
> 
> --
> 
> There's a window of time where the lock is in effect: between when the
> X server activates it on Caps Lock key press and we undo it on the
> first key release. Can't see how to get rid of that.
> 
> Anyway, it works fine in practice. Please review.

Hi, thanks, I'm already using it.

BTW, here is feature request: is it possible to switch layout when some other non-functional key (letter/digit/space/backspace) pressed?
It's a very common case for me (and, I think, many others) when you press layout switching combo/key for a moment before releasing the key for the last typed symbol. Or for a moment before releasing backspace after deleting a text typed in a wrong layout.
Comment 15 Dmitry Shachnev 2012-11-03 05:50:25 UTC
Patch works fine (I've applied it to g-s-d 3.6.1), thanks.
Comment 16 Rui Matos 2012-11-08 15:51:26 UTC
*** Bug 687929 has been marked as a duplicate of this bug. ***
Comment 17 Amir Hedayaty 2012-11-11 22:30:02 UTC
I am using the gnome 3.6.1 and can not set the CapsLock as a layout switcher!

This is so far the most annoying bugs in gnome for me! :(
Utilizing a useless key for switching layouts was so great!
Comment 18 Bastien Nocera 2012-11-12 09:38:52 UTC
Review of attachment 227922 [details] [review]:

::: plugins/keyboard/gsd-input-sources-switcher.c
@@ +382,3 @@
+      /* When the grab is established with Caps Lock as the modifier
+         (i.e. key.state == GDK_LOCK_MASK) we can't use
+         match_xi2_key() as this modifier is black listed there, so we

I'd rather we found a way to fix this instead of working around it.
It should be blacklisted when used as a modifier, not as a stand-alone key.

@@ +469,3 @@
                           1,
                           &mods);
+          if (includes_caps && caps_press_time < switch_time)

Is xev->time completely monotonic?
Comment 19 Rui Matos 2012-11-12 10:39:47 UTC
(In reply to comment #18)
> Review of attachment 227922 [details] [review]:
> 
> ::: plugins/keyboard/gsd-input-sources-switcher.c
> @@ +382,3 @@
> +      /* When the grab is established with Caps Lock as the modifier
> +         (i.e. key.state == GDK_LOCK_MASK) we can't use
> +         match_xi2_key() as this modifier is black listed there, so we
> 
> I'd rather we found a way to fix this instead of working around it.
> It should be blacklisted when used as a modifier, not as a stand-alone key.

For the record:

10:40 < rtcm> hadess, right, let me explain a bit more what's going on there, we establish 2 grabs
10:41 < rtcm> one for shifted caps lock, and another one for caps locked shift, so that the shortcut works both ways (i.e. 
              independently of which key you actually pressed first)
10:41 < rtcm> that workaround is for the caps locked shift case

> @@ +469,3 @@
>                            1,
>                            &mods);
> +          if (includes_caps && caps_press_time < switch_time)
> 
> Is xev->time completely monotonic?

It's like all X timestamps so I'm almost sure it is monotonic although I can't actually find any specific mention to that in the x11 or XI2 protocol documents.

Anyway, if it's not monotonic there's no way to properly do this. I.e. if the time goes back between the key press and the release what can we do? If it goes back at any other point it shouldn't matter since we always set caps_press_time on the key press that triggers the grab.
Comment 20 Rui Matos 2012-11-12 17:33:45 UTC
Ups, I forgot to use git bz. I pushed a revised version of this patch to both master and gnome-3-6:

http://git.gnome.org/browse/gnome-settings-daemon/commit/?id=bd1d5fbe09c76131276db6289f1f5f26ff5a3b6d
Comment 21 Dmitry Shachnev 2012-11-14 08:44:34 UTC
@Rui: thanks a lot! Will there be 3.6.3 release?
Comment 22 Dmitry Shachnev 2012-11-14 15:45:28 UTC
And I think it's expected behaviour, but I'll still leave it here: there is some timeout before the layout change is actually performed: if you press CapsLock and immediately start typing something, you may get first one or two letters typed in previous layout, like: йцertyui. This is a bit annoying :(
Comment 23 Valeriy L. 2012-11-15 13:53:11 UTC
Just my 2 cents: this delay happens with another key combinations as well.
Comment 24 Rui Matos 2012-11-15 13:56:44 UTC
(In reply to comment #22)
> And I think it's expected behaviour, but I'll still leave it here: there is
> some timeout before the layout change is actually performed: if you press
> CapsLock and immediately start typing something, you may get first one or two
> letters typed in previous layout, like: йцertyui. This is a bit annoying :(

I just pushed a patch which should make this better for shortcuts using Caps Lock. See bug 688350.

(In reply to comment #23)
> Just my 2 cents: this delay happens with another key combinations as well.

For other keys we can't really shorten the delay without disturbing applications, see the above mentioned bug for a more detailed explanation.