Home » How-to » How to Change Keyboard Layout Using Alt+Shift in Linux

How to Change Keyboard Layout Using Alt+Shift in Linux

In KDE, there is no issue configuring the hotkey you want to use for input switching. However, on the GNOME desktop, it is more complex. There the default keyboard shortcuts for switching layouts are Super+Space and Shift+Super+Space. The first switches to the next layout, and the second to the previous one.

For people who are used to the old way of switching and have a lot of layouts, this is not convenient. In this article, I will show how to customize the layout switching in Linux for GNOME and KDE to use Alt+Shift.


Table of Contents

How Does it Work by Default in GNOME?

Let's look at how everything works by default. A quick press of Super+Space allows you to switch between the last two layouts. If you hold down Alt and press Space key several times, a language switcher will appear where you can select the language you need. The keyboard shortcut Shift+Super+Space always switches to the previous layout without being tied to the last two.

On Windows, switching layouts works in much the same way, and the main bet is that the user will choose the language in the graphical interface. But suppose you have a lot of layouts and want to quickly switch between them, as it was when using Alt+Shift. In that case, it becomes very inconvenient because it is impossible to constantly remember which layout was the last one. When you switch quickly, it seems like the layout is selected randomly.

In GNOME, the decision to switch the layout in this way was made back in 2016 in this discussion. But this didn't bother many people, because everyone concerned enabled Alt+Shift in the Gnome Tweaks Tool and continued to use the usual method of switching. The situation has changed with the transition of many distributions to Wayland where the old way of switching does not work or does not work correctly either.

How to Switch Layout by Alt+Shift in GNOME

1. Two Layouts in Wayland

If you use only two different layouts, it's pretty simple. You can reassign the default keyboard shortcut Super+Space to Alt+Shift. Then you will always switch between the two layouts, and everything will be convenient. And if you want to see what language is currently selected, you can hold Super a little longer until the language bar opens. You can't set this up in the GUI keyboard settings, but you can in the command line using the following command:

gsettings set org.gnome.desktop.wm.keybindings switch-input-source "['<Shift>Alt_L']"

2. Three or More Layouts in Wayland

If there are more different input languages in your system, then switching becomes less convenient. Here you can configure Alt+Shift instead of Shift+Super+Space. Then you will switch sequentially between all layouts by key combination Alt+Shift, and Super+Shift can be used to switch between the last two. Use the following command to do this:

gsettings set org.gnome.desktop.wm.keybindings switch-input-source-backward "['<Alt>Shift_L']"

The only drawback of this approach is that the layouts are switched in the opposite direction than they are set in the settings.

Note that you should not set Alt+Shift to switch backward and Shift+Alt to switch forwards because if you are used to switching quickly and do not think that you have previously pressed Alt or Shift, then the layout may switch in the wrong direction, and the system will choose a random layout.

3. Old X11 Way

If you use X11, you can configure the layout switching with Alt+Shift by running the following command:

gsettings set org.gnome.desktop.input-sources.xkb-options "['grp:alt_shift_toggle']"

This method will not work correctly for Wayland. There's a bug with showing the same layout multiple times that has been known for a long time but hasn't been fixed yet.

4. Using an Extension

Additionally, you can use a simple Gnome extension to switch input sources. There are two extensions that can help with it:

  • SwitchLayoutAltShift - download here.
  • RX Input Layout Switcher - download here.

The first extension is mine, and it is very simple, it just registers a keybinding. When you press that keybinding, the input source is changed to the next in the list. If you have other keybindings that include Alt+Shift, they may conflict with the extension. I wrote this extension in a few hours when I moved to the new GNOME 43 and Wayland from X11. The second extension watches key modifier states to determine whether Alt+Shift is pressed or not. So that it will not conflict with other hot keys.

Both of these extensions switch the layout to the next one every time you press Alt+Shift, while the list of layouts remains static. They work in both Wayland and X11. There are no settings in the extension, and the language bar is also not shown.

However, the extensions can't switch keyboard input layout on the lock screen due to GNOME extensions policies. So you also need this extension to automatically change the keyboard layout on the lock screen to the primary one.

How to Switch Layout by Alt+Shift in KDE

KDE doesn't have a key combination configured to change the layout by default, but you can configure it in keyboard layout settings. Open Input Devices -> Keyboard and go to the Layouts tab:

Here, click on the button near Main Shortcuts item and select the desired keyboard shortcut. For example, Alt+Shift:

After that, you just need to click the Apply button and the input source switching will work.

Wrapping Up

In this article, we have seen how to switch the layout using Alt+Shift in Linux distributions that use GNOME, even with Wayland or KDE. As you can see, there are some difficulties here, but everything can still be customized.

Rate the Article

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...
Creative Commons License
The article is distributed under Creative Commons ShareAlike 4.0 license. Link to the source is required .

Leave a Comment