Modeless/stateless layout language switching with Caps Lock, again (18.04 LTS Bionic Beaver)
There is a bug report you can subscribe to:
- keyboard panel does not allow to set up Caps as input switch
The bug report reads:
Keyboard panel has options for input switching, but it does not allow to use Caps as language switch.
Steps to reproduce:
- gnome-control-center keyboard
- Scroll down to 'Typing' section
- Click on Switch to next input source
- Press Caps
Expected result: Caps Lock key is accepted as switch key Actual results: Caps key is ignored in the selection window.
P.S. Same goes for 'Switch to previous input source' and Shift-Caps key combination.
Bug Workarounds
The bug is currently on the "Wishlist". These workarounds are proposed:
Workaround 1
Found a workaround for this bug:
- Install dconf-editor (sudo apt-get install dconf-editor)
- Go to /org/gnome/desktop/wm/keybindings/
- Select key switch-input-source, turn off "Use default value" and set "Custom value" to ['Caps_Lock']
- (Optional) You can also change value for switch-input-source-backward to something like ['Caps_Lock'] (again, turning off "Use default value")
Workaround 2
Another way to do this: 1. Install GNOME Tweaks (gnome-tweak-tool) 2. Open the Tweaks app 3. Switch to the Keyboard & Mouse panel 4. Click Additional Layout Options 5. Use the "Switching to another layout" section
Subscribe to bug report
I would recommend subscribing to the bug report and adding your own experiences. The more people subscribing to the bug report, the faster the solution comes (usually).
In Ubuntu 18.04, by default there is a option to choose Caps_Lock and Shift+Caps_Lock to achieve the behavior we are looking for, is in gnome-tweaks
. But this is not working and could not get the reason why.
I could manage to achieve this behavior by the below workaround.
See this link for a 20Sec Video. https://imgur.com/QNdrVqa
first check the below commands in terminal whether they are changing the input language.
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources[1].activate()"
and
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources[0].activate()"
well, they are working.
we need to bind these commands to key presses of Caps_Lock and Shift+Caps_Lock
can achieve this with xbindkeys
if xbindkeys is not yet installed install it by sudo apt install xbindkeys
- create a file
.xbindkeysrc
in $HOME folder
touch ~/.xbindkeysrc
- to know the keycode/id what ever it is called
runxbindkeys --key
once the white box appears press the Caps_Lock button, do it for Shift button also and copy the keycodes/ids as show below
- this step is Optional.. Disable the Caps Lock. See below gif. If caps lock is not disabled.. when you hit the key multiple times it will toggle while you try to change the language. I have Disabled it. but it is based on your interest.
- Open the file
.xbindkeysrc
gedit ~/.xbindkeysrc
and edit the file like below based on the results of above steps
Change the values in below content according to the results you got in step 2 above. Content:
"gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources[0].activate()""
m:0x10 + c:66
"gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources[1].activate()""
Shift+Mod2 + Shift_L+m:0x10 + c:66
- Save the file, Close & Reboot..