From ArchWiki
Revision as of 01:54, 30 May 2019 by Glats (talk | contribs) (I added another way to start sway)
Jump to navigation Jump to search

sway is a compositor for Wayland designed to be fully compatible with i3. According to the official website:

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, plus a few extras.


sway can be installed with the sway package. The development version can be installed using wlroots-gitAUR and sway-gitAUR. It's advisable to always update wlroots when you update sway, due to tight dependencies.

You may also install swaylock and swayidle to lock your screen and set up an idle manager.


Tip: See Wayland#GUI libraries for appropriate environment variables to set for window decoration libraries.

From a TTY

To start Sway, simply type sway from a TTY.

From a display manager

Note: Sway does not support display managers officially.

The sway session is located at /usr/share/wayland-sessions/sway.desktop. It is automatically recognized by modern display managers like GDM and SDDM.

Also you can use text's based session manager Display manager#Console


If you already use i3, then copy your i3 configuration to ~/.config/sway/config and it should work out of the box. Otherwise, copy the sample configuration file to ~/.config/sway/config. It is located at /etc/sway/config, unless the DFALLBACK_CONFIG_DIR flag has been set. See sway(5) for information on the configuration.


By default, sway starts with the US QWERTY keymap. To configure per-input:

 input * xkb_layout us,de,ru"
 input * xkb_variant "colemak,,typewriter"
 input * xkb_options "grp:win_space_toggle"
 input "MANUFACTURER1 Keyboard" xkb_model "pc101"
 input "MANUFACTURER2 Keyboard" xkb_model "jp106"

More details are available in xkeyboard-config(7) and sway-input(5).

The keymap can also be configured using environment variables (XKB_DEFAULT_LAYOUT, XKB_DEFAULT_VARIANT, etc.) when starting sway.


Installing the program i3status is an easy way to get a practical, default statusline. All one has to do is add following snippet at the end of your sway config:

 bar {
  status_command i3status

If you want to achieve colored output of i3status, you can adjust following part in the i3status configuration:

general {
        colors = true
        interval = 5

In both examples, the system-wide installed configuration files has been copied over to the user directory and then modified.

Tip: waybar is an alternative to the bar included with sway (swaybar).


This line, which can be appended at the end of your sway configuration, sets a background image on all displays (output matches all with name "*"):

 output "*" background /home/onny/pictures/fredwang_norway.jpg fill

Of course you have to replace the file name and path according to your wallpaper.

Input devices

Its possible to tweak specific input device configurations. For example to enable tap-to-click and natural scolling for a touchpad, add an input block:

input "2:14:ETPS/2_Elantech_Touchpad" {
    tap enabled
    natural_scroll enabled

Where as the device identifier can be queried with:

$ swaymsg -t get_inputs

The output from the command, sometimes has a "\" to escape symbols like "/" (ie "2:14:ETPS\/2_Elantech_Touchpad") and it needs to be removed.

More documentation and options like acceleration profiles can be found in sway-input(5).


Set your displays scale factor with the output command in your config file. The scale factor can be fractional, but it is usually 2 for HiDPI screens.

output <name> scale <factor>

You can find your display name with the following command:

$ swaymsg -t get_outputs

Custom keybindings

Special keys on your keyboard can be used to execute commands, for example to control your volume or your monitor brightness:

 bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
 bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
 bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
 bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
 bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
 bindsym XF86MonBrightnessUp exec brightnessctl set +5%

To control brightness you can use brightnessctlAUR or light. For a list of utilities to control brightness and color correction see Backlight.


Copy ~/.Xresources to ~/.Xdefaults to use them in Sway.

Run programs natively under Wayland (without Xwayland support)

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: xwayland disable is not necessary to run programs natively under Wayland, configuring the GUI libraries appropriately is enough. Keeping XWayland enabled is good for programs that don't work otherwise. (Discuss in Talk:Sway#)

First, be sure the toolkit or library of every program that is and will be installed support Wayland. Then append the following line to your sway configuration file to disable Xwayland support:

xwayland disable
Note: Some programs, like Firefox, bemenu or Qt5 based programs, also need specific environment variables set for them to run natively under Wayland.
Note: In a fresh Sway install, you need to change the default menu and terminal applications because they depend on Xwayland.

Tips and tricks

Autostart on login

To start sway from tty1 on login with default US keyboard, edit:

if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
  XKB_DEFAULT_LAYOUT=us exec sway

Backlight toggle

To turn off (and on) your displays with a key (e.g. Pause) bind the following in your Sway config:

read lcd < /tmp/lcd
    if [ "$lcd" -eq "0" ]; then
        swaymsg "output * dpms on"
        echo 1 > /tmp/lcd
        swaymsg "output * dpms off"
        echo 0 > /tmp/lcd

Screen capture

Capturing the screen can be done using grim or swayshotAUR for screenshots and wf-recorder-gitAUR for video. Optionally, slurp can be used to select the part of the screen to capture.

Take a screenshot of the whole screen:

$ grim screenshot.png

Take a screenshot of a part of the screen:

$ grim -g "$(slurp)" screenshot.png

Capture a video of the whole screen:

$ wf-recorder -o recording.mp4

Capture a video of a part of the screen:

$ wf-recorder -g "$(slurp)"

Example of usage with grim, slurp and wl-clipboard, screenshot directly with Print button to clipboard.

bindsym --release Print exec grim -g \"$(slurp)" - | wl-copy


Application launchers

i3-dmenu-desktop, dmenu, and rofi all function relatively well in Sway, but all run under XWayland and suffer from the same issue where they can become unresponsive if the cursor is moved to a native Wayland window. The reason for this issue is that Wayland clients/windows do not have access to input devices unless they have focus of the screen. The XWayland server is itself a client to the Wayland compositor, so one of its XWayland clients must have focus for it to access user input. However, once one of its clients has focus, it can gather input and make it available to all XWayland clients through the X11 protocol. Hence, moving the cursor to an XWayland window and pressing Escape should fix the issue, and sometimes running pkill does too.

bemenu is a native Wayland dmenu replacement which can optionally be combined with j4-dmenu-desktopAUR to provide a Wayland-native combination for launching desktop files (as i3-dmenu-desktop does):

j4-dmenu-desktop --dmenu='bemenu -i --nb "#3f3f3f" --nf "#dcdccc" --fn "pango:DejaVu Sans Mono 12"' --term='termite'

You may need to set BEMENU_BACKEND environment variable to "wayland" if you choose not to disable XWayland.

You can also build your own with a floating terminal and fzf as discussed in a GitHub issue.


Sway doesn't work well (or at all) under VirtualBox.

Sway socket not detected

Using a swaymsg argument, such as swaymsg -t get_outputs, will sometimes return the message:

sway socket not detected.
ERROR: Unable to connect to

when run inside a terminal multiplexer (such as gnu screen or tmux). This means swaymsg could not connect to the socket provided in your SWAYSOCK.

To view what the current value of SWAYSOCK is, type:

$ env | fgrep SWAYSOCK

To work around this problem, you may try attaching to a socket based on the running sway process:

$ export SWAYSOCK=/run/user/$(id -u)/sway-ipc.$(id -u).$(pgrep -x sway).sock

To avoid this error, run the command outside of a multiplexer.

Unable to retrieve socket path

Requesting messages from swaymsg -t on a tty may return the following message:

Unable to retrieve socket path

SWAYSOCK environment variable is set after launching Sway, therefore a workaround to this error is to request swaymsg -t [message] in a terminal inside Sway.

See also