Software & AppsOperating SystemLinux

How To Set Keyboard Layout in Sway on Ubuntu 20.4

Ubuntu 12

In this comprehensive guide, we will walk you through the process of setting the keyboard layout in Sway on Ubuntu 20.4. Sway is a tiling Wayland compositor and a drop-in replacement for the i3 window manager for X11. It works with your existing i3 configuration and supports most of i3’s features, and a few extras.

Quick Answer

To set the keyboard layout in Sway on Ubuntu 20.4, you can modify the Sway configuration file ~/.config/i3/config and add the appropriate lines for your desired layout and variant. Alternatively, you can use the swaymsg command or the localectl command for setting the keyboard layout.

Understanding Sway and Keyboard Layouts

Before we delve into the steps, it’s important to understand the concept of keyboard layouts and how they work in the context of Sway. A keyboard layout maps the physical keys of a keyboard to elements of a linguistic or functional system. In simpler terms, it’s the arrangement of keys and their functions on your keyboard.

Locating Your Sway Configuration File

The first step in setting your keyboard layout in Sway is to locate your sway configuration file. This file is usually located at ~/.config/i3/config. If you can’t find it there, you may need to create it.

Modifying Your Sway Configuration File

Once you’ve located your configuration file, you can modify it to set your preferred keyboard layout. For instance, if you want to permanently switch from the us X11 layout to the cz layout with the coder variant, you can do so by adding the following lines to your configuration file:

input * {
 xkb_layout "cz"
 xkb_variant "coder"

In this code, input * indicates that the following settings apply to all input devices. xkb_layout "cz" sets the keyboard layout to Czech, and xkb_variant "coder" sets the variant to coder.

After adding these lines, save the file and restart Sway for the changes to take effect.

Alternative Methods

If the above method doesn’t work for you, there are alternative methods you can try:

Using the swaymsg Command

You can use the swaymsg command to set the keyboard layout. Open a terminal and run the following command:

swaymsg input keyboard xkb_layout cz xkb_variant coder

This command should immediately apply the Czech layout with the coder variant. If it works, you can add this command to your sway configuration file to make it permanent.

Using localectl Command

If you’re using a distro like Fedora, you can use the localectl command to set the keyboard layout:

localectl set-x11-keymap cz coder

This command sets the X11 keymap, which should also affect Wayland sessions.


Setting the keyboard layout in Sway on Ubuntu 20.4 is a straightforward process once you understand how to modify your configuration file. If you encounter any issues, it’s likely due to distro-specific differences or other configuration or compatibility issues specific to your setup. In such cases, trying out the alternative methods mentioned above can be helpful.

Remember, the key to mastering Sway, like any other window manager, lies in understanding and effectively modifying its configuration file. Happy tweaking!

What is Sway?

Sway is a tiling Wayland compositor and a drop-in replacement for the i3 window manager for X11. It allows you to arrange and manage your windows in a tiled layout, improving productivity and efficiency.

How does Sway differ from i3?

Sway is built specifically for the Wayland display protocol, while i3 is designed for the X11 windowing system. Sway aims to provide a similar user experience and feature set as i3, but with native Wayland support.

Can I use my existing i3 configuration with Sway?

Yes, Sway is compatible with most of i3’s features and supports the majority of i3 configuration options. You can simply copy your existing i3 configuration file to the Sway configuration file location and make any necessary adjustments.

How do I locate my Sway configuration file?

The Sway configuration file is typically located at ~/.config/sway/config. If it doesn’t exist, you can create it manually.

Can I set different keyboard layouts for different applications in Sway?

Yes, you can set different keyboard layouts for different applications in Sway. This can be achieved by using tools like xkb-switch or xkbcomp to change the layout on the fly based on the currently focused window.

How do I restart Sway to apply the changes to the keyboard layout?

To restart Sway and apply the changes to the keyboard layout, you can use the swaymsg command with the --reload option. Simply run swaymsg --reload in a terminal, and Sway will reload the configuration file.

What should I do if I encounter issues with setting the keyboard layout in Sway?

If you encounter issues, double-check that you have correctly modified your Sway configuration file and saved the changes. Additionally, ensure that you are using the correct syntax for specifying the keyboard layout and variant. If problems persist, you can try the alternative methods mentioned in the guide or seek assistance from the Sway community.

Leave a Comment

Your email address will not be published. Required fields are marked *