Complete guide to Sway: the Wayland compositor inspired by i3

Introduction

Sway has become one of the most popular options for those seeking a tiling desktop environment under Wayland. Directly inspired by i3, Sway inherits its philosophy of simplicity and productivity, but leverages the modern advantages of the Wayland protocol, such as better screen management, reduced tearing, and greater security. In this article we will explore everything from installation to advanced customization, showing why Sway can be the ideal companion for both new users and system administrators who want a lightweight desktop fully controllable via keyboard.

What is Sway?

Sway is a tiling window compositor for Wayland that works as a direct replacement for i3 in X11 environments. By operating under Wayland, Sway eliminates the need for an X server and provides a safer, more efficient path for rendering graphics on the desktop. Its configuration is based on a simple text file where shortcuts, application rules, and the appearance of status bars are defined. Thanks to its modular design, it is possible to combine Sway with tools like Waybar, dunst, and swaylock to create a fully customized environment without sacrificing performance.

Installation

The simplest way to install Sway depends on the distribution you use. On Ubuntu and Debian, the package is in the official repositories and can be installed with sudo apt install sway. On Arch Linux, the package is in the core repository and installed with sudo pacman -S sway. Fedora users can run sudo dnf install sway. If you prefer to compile from source, just clone the official repository, install the dependencies (meson, ninja, wayland-protocols, pcre, json-c), and run meson setup build && ninja -C build && sudo ninja -C build install. After installation, starting Sway from a tty is as simple as running sway or adding an entry in your login manager.

Basic Configuration

When running Sway for the first time, it looks for the default configuration file at /etc/sway/config and copies it to your home directory with mkdir -p ~/.config/sway && cp /etc/sway/config ~/.config/sway/config. This file is where you will define your modifier key (Mod), normally set to the Windows or Alt key, and keyboard shortcuts for launching terminals, changing focus, resizing windows, and exiting the session. After editing the file, you can reload the configuration without exiting Sway using the shortcut Mod+Shift+c. Additionally, it is useful to define variables for the color theme, font, and border behavior, all via simple lines like set $mod Mod4 or font pango:Monospace 10.

Keyboard Shortcuts

  • Mod+Enter: opens a terminal (default alacritty or foot).
  • Mod+Shift+q: closes the focused window.
  • Mod+Shift+e: shows the exit menu to power off, reboot, or log out.
  • Mod+j / Mod+k: moves focus between windows in the left/right direction (depending on the layout).
  • Mod+Shift+j / Mod+Shift+k: moves the focused window in that direction.
  • Mod+f: toggles fullscreen mode for the current window.
  • Mod+Shift+space: switches between tiling and floating layouts.
  • Mod+Shift+r: reloads Sway’s configuration.
  • Mod+p: launches an application launcher like dmenu or rofi.
  • Mod+Shift+c: cleanly exits Sway (alternative to exiting via the menu).

These shortcuts form the core of productivity in Sway; you can adapt them or add new ones according to your workflow, binding custom scripts or system commands directly from the configuration file.

Status Bar with Waybar

Waybar is a highly configurable information bar that integrates perfectly with Sway. To install it, on Ubuntu use sudo apt install waybar, on Arch sudo pacman -S waybar, and on Fedora sudo dnf install waybar. Once installed, copy the default configuration file to ~/.config/waybar/config and the style file to ~/.config/waybar/style.css. In the config you can define modules such as the clock, CPU load, memory usage, battery status, and Sway workspaces. Each module can be shown or hidden, change its alignment, and apply custom CSS styles. After editing, restart Waybar with pkill waybar && waybar & or simply reload Sway so it starts automatically.

Advantages Over Other Compositors

  • Lightweight and fast: being written in C and using Wayland, it consumes little RAM and CPU.
  • Fully controllable by keyboard: ideal for users who prefer not to depend on the mouse.
  • Inherent Wayland security: client isolation and better input permission handling.
  • Compatibility with the same configuration files as i3, making migration easy.
  • A rich ecosystem of companion tools (swayidle, swaylock, grim, slurp, wl-clipboard).

These features make Sway an attractive option both for development workstations and older machines where maximizing performance is desired.

Comparison with i3

Although Sway and i3 share an almost identical configuration syntax, the fundamental difference lies in the underlying display server. i3 depends on X11, which entails certain limitations regarding tearing, HiDPI screen scaling, and secure peripheral handling. Sway, by running directly on Wayland, eliminates those limitations and offers a smoother experience on high‑resolution monitors and multi‑monitor setups. Additionally, Sway includes native improvements for handling window borders and integration with desktop protocols like xdg-desktop-portal, something i3 can only achieve via external extensions. In terms of performance, both are comparable in lightweight environments, but Sway tends to have a slight edge in intensive graphics usage due to Wayland’s more modern architecture.

Tips to Get the Most Out of Sway

  • Use swayidle and swaylock to lock the screen automatically after a period of inactivity.
  • Integrate a notification daemon like dunst to receive alerts without breaking your workflow.
  • Take advantage of screenshot protocols with grim and slurp to capture the whole screen or specific regions.
  • Set up a reliable clipboard with wl-clipboard for copying and pasting between Wayland and X11 applications via xwayland when needed.
  • Explore custom tiling layouts using the layout toggler command or by creating your own layouts in the configuration file.
  • Keep a backup of your configuration in a Git repository so you can reproduce your environment on any machine.

With these tricks, Sway transforms from a simple window manager into a desktop fully tailored to your needs, maintaining the minimalism and efficiency philosophy that made it popular.

Conclusion

Sway represents a natural evolution of i3’s tiling model toward the future of Wayland. Its easy installation, familiar configuration, and low resource consumption make it a viable option for both newcomers wanting to try an advanced productivity environment and veterans seeking a safe, modern replacement for X11. By combining Sway with tools like Waybar, dunst, and swaylock, you can create a desktop that is not only fast and lightweight but also aesthetically pleasing and fully controllable from the keyboard. If you haven’t tried it yet, now is the time to give it a chance and discover how Sway can transform your way of working on Linux.