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

How to Change Keyboard Layout Using Alt+Shift in Ubuntu

The main official Ubuntu image uses the GNOME desktop environment, and the support for keyboard layout switching methods is quite complicated here. By default, the keyboard layout switching is done using Super+Space and Shift+Super+Space key combinations. The first one switches to the next layout, and the second one switches to the previous layout, similar to Windows.

However, for users who are used to using Alt+Shift and have multiple keyboard layouts, this might not be very convenient. In this article, we'll look at how to configure keyboard layout switching in Ubuntu so that you can use Alt+Shift and have it work just like before.


Table of Contents

How does it work by default?

Let's first look at how all this works in GNOME by default. A quick press of Shift+Space allows you to switch between the two most recently used layouts. If you hold down Alt and press Shift several times, a list of available layouts will appear on the screen, and you can select the one you need.

The keyboard shortcut Shift+Super+Space always switches to the previous layout without binding to recently used ones. In Windows, layout switching works in a similar way, with the main emphasis on users selecting the layout through the graphical interface.

However, if you have more than two keyboard layouts and want to switch between them quickly, like it was with Alt+Shift, it becomes quite challenging. It's impossible to constantly remember which layout was active before, and if you switch quickly without waiting for the graphical interface to open, it feels like the layout selection becomes random.

GNOME developers decided to implement the switching this way back in 2016, in this discussion. However, at that time, not many people were concerned about it because previously, you could enable Alt+Shift in Gnome Tweak Tool, and everything remained as before. But recently, the situation changed because after switching to Wayland, the keyboard layout switching method that could be enabled in Gnome Tweak Tool stopped working. Or if it did work, it wasn't functioning correctly.

How to Switch Keyboard Layout Using Alt+Shift in Ubuntu

Now let's look at how to configure all of this in Xorg and Wayland to make everything work properly.

1. Two Keyboard Layouts in Wayland

If you have only two layouts, everything is quite simple. You can reassign Alt+Shift instead of the default Super+Space combination. You will always switch between two layouts, and since there are only two of them, there won't be any inconvenience. You can still see the layout selection panel by holding down Alt. However, this cannot be configured through the graphical interface, so you'll need to use a terminal command:

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

2. Three or More Keyboard Layouts in Wayland

If you have more layouts, you can configure the use of Alt+Shift instead of Shift+Super+Space. Then you'll be able to switch through all layouts sequentially. And Super+Space can still be used to toggle between the last two layouts. To configure this, execute the command:

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

The only drawback of this approach is that layouts will switch in reverse order compared to how they are arranged in settings. Also note that setting up Shift+Alt for switching between two layouts is not recommended because during quick switching you might accidentally press the key combination in the wrong sequence.

3. GNOME Extensions

In my opinion, the easiest way change layout using Alt+Shift is to use a GNOME extension. The most popular extension for solving this task is RX Input Layout Switcher. You can download it here. Initially, I used my own extension SwitchLayoutAltShift, but since the first extension is more popular and works better, I think there's no point in maintaining it further.

The extension monitors the state of modifier keys, so it can accurately determine whether only Alt+Shift was pressed or some other combination. Therefore, layout switching should not conflict with other hotkeys. Simply when you press that keybinding, the input source is changed to the next in the list.

The extension will work in both X11 and Wayland. And it simply switches the keyboard layout without displaying the layout panel.

Since GNOME policies prevent extensions from accessing the keyboard on the lock screen, you may need the Primary Input on LockScreen extension to automatically change the keyboard layout to the primary one on the lock screen.

4. Method for Xorg

If you are still using Xorg, you can execute the following command to enable keyboard layout switching with Alt+Shift:

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

As for Wayland, this method still doesn't work correctly there. There is already a bug report about the same keyboard layout being displayed multiple times, but this issue hasn't been fixed yet.

Wrapping Up

This article demonstrated how to set Alt Shift shortcut to change input language in Ubuntu. These methods will also work in other Linux distributions that use GNOME. As you can see, there are some complexities involved, but overall everything can be configured.

Creative Commons License
The article is distributed under Creative Commons ShareAlike 4.0 license. Link to the source is required.

Leave a Comment