7

I want to configure CapsLock to switch always to the English keyboard layout (input source), while Shift+CapsLock switches always to Russian [18.04]

I've been using the setup described in the title successfully on Linux Mint 15, based on Cinnamon and Ubuntu 16.04.

I just went to keyboard configuration and set up combinations for each keyboard layout (input source).

I've migrated to Ubuntu 18.04 Desktop via a clean install and discovered that I can't do the same. I was gonna use this solution, but in 18.04 the CapsLock key can't be used as a hotkey:

Add Custom Shortcut window

In this dialog, the CapsLock key either does nothing or reveals the Cancel button. The Save button becomes visible only when I press a combination of a modifier and a character key.

So how do I configure CapsLock to switch to English (regardless of how many times it's pressed) and Shift+CapsLock to switch to Russian?

PS: Note that gnome-tweaks is irrelevant here because it has no per-language configuration options.

abu_bua
  • 10,783
  • @DavidFoerster, thank you for your comment! Please post an answer to this question, describing the way to disable the default function of CapsLock. – lolmaus - Andrey Mikhaylov Sep 20 '18 at 07:06
  • I tried the CapsLock is disabled option of gnome-tweaks. This results in CapsLock keypress to be captured as 0xff in the Add Custom Shortcut dialog. Unfortunately, the shortcut still won't work! – lolmaus - Andrey Mikhaylov Sep 20 '18 at 07:14
  • Here is the solution that finally worked for me for Unbuntu 18.04 and 20.04 https://askubuntu.com/questions/1123163/modeless-stateless-layout-language-switching-with-caps-lock-again-18-04-lts-bi – Viktor Kruglikov Jan 09 '21 at 16:15

2 Answers2

4
  1. Install Gnome Tweaks:

    sudo apt install gnome-tweaks
    
  2. Run Gnome Tweaks: Press the Super (aka Windows) key, type Tweaks, press Enter.

  3. Go to Keyboard & Mouse section in the left list.

  4. Click the Additional Layout Options button in the main area on the right.

  5. Expand the Caps Lock Behavior section.

  6. Select Make Caps Lock an additional Menu key. This seems to be the only option available to expose Caps Lock as a regular, non-modifier, unused key.

  7. Close both windows.

You can now use Caps Lock in hot keys – both standalone and with modifiers.


As for switching to a specific keyboard layout, the gsettings set org.gnome.desktop.input-sources current 0 option is deprecated and ignored.

This command works:

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()"
David Foerster
  • 36,264
  • 56
  • 94
  • 147
1

The gdbus call … org.gnome.Shell.Eval … mentioned in the other answer is not working anymore as of 2024.

So, I've create my own GNOME Shell Extention just for that, that shares the same principle of working via D-Bus, but doesn't rely on any other interfaces, instead, implementing the solution itself:

Shyriiwook (also available @ GitHub: madhead/shyriiwook).

This is a very simple, minimalist extension. It doesn't have any GUI. After installing it, a new D-Bus interface would be exposed in your GNOME Shell session. You could query it for the current configuration or call a method to activate the desired layout:

$ gdbus introspect \
    --session \
    --dest org.gnome.Shell \
    --object-path /me/madhead/Shyriiwook \
    --only-properties

node /me/madhead/Shyriiwook { interface me.madhead.Shyriiwook { properties: readonly as availableLayouts = ['us', 'de', 'jp']; readonly s currentLayout = 'us'; }; };

$ gdbus call
--session
--dest org.gnome.Shell
--object-path /me/madhead/Shyriiwook
--method me.madhead.Shyriiwook.activate "de"

This is easily scriptable, and you can even put this command raw into a custom shortcut under the "Settings" → "Keyboard" → "Keyboard Shortcuts" → "View and Customise Shortcuts" → "Custom Shortcuts".

madhead
  • 702
  • 3
  • 10