From ArchWiki
Revision as of 22:46, 28 December 2018 by Cjbassi (talk | contribs) (Combine application launcher issues into one section)
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 drop-in replacement for the i3 window manager, but for Wayland instead of X11. It works with your existing i3 configuration and supports most of i3's features, and a few extras.


Sway is a work-in-progress so caution is advised. However, the project's creator, Drew DeVault (aka SirCmpwn) has deemed it ready for regular use.

A detailed accounting of what features have been implemented and what features are still outstanding can be found at the following links:


sway can be installed with the sway package. This will install the stable (but abandoned) 0.15 version which is based on the (also abandoned) wlc library.

At the time of writing, sway 1.0-beta (based on the new wlroots library) is under active development and quite stable. Install the following two Arch User Repository packages instead: wlroots-gitAUR and sway-gitAUR.

It's advisable to always update wlroots when you update sway, due to tight dependencies.


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.


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. You can override this behaviour by starting sway with:

$ export XKB_DEFAULT_LAYOUT=gb; export XKB_DEFAULT_VARIANT=colemak; export XKB_DEFAULT_MODEL=pc101; sway

This will launch sway with the keyboard set to the Colemak variant of the British keymap with the 101-key keyboard model.

See alias to simplify starting from a tty and Desktop entries#Modify environment variables to start #From a display manager.

If none of the above worked, you could add:

export XKB_DEFAULT_LAYOUT=gb; export XKB_DEFAULT_VARIANT=colemak; export XKB_DEFAULT_MODEL=pc101

to either your .bash_profile or .zprofile (or similar).

If you want multiple keyboard layouts at startup edit .bash_profile and add, for example US English and German layouts, switchable by Mod+Space:

if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
  export XKB_DEFAULT_LAYOUT=us,de
  export XKB_DEFAULT_OPTIONS=grp:win_space_toggle
  exec sway

Another option for switching keyboard layout is Alt+Shift: grp:alt_shift_toggle.


Installing the program i3status is an easy way to get a practical, default statusbar. 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.


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 must be an integer, and 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 $(pacmd list-sinks |awk '/* index:/{print $3}') +5%
 bindsym XF86AudioLowerVolume exec pactl set-sink-volume $(pacmd list-sinks |awk '/* index:/{print $3}') -5%
 bindsym XF86AudioMute exec pactl set-sink-mute $(pacmd list-sinks |awk '/* index:/{print $3}') toggle
 bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
 bindsym XF86MonBrightnessUp exec brightnessctl set +5%

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


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

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

Known issues

Application launchers

i3-dmenu-desktop, j4-dmenu-desktopAUR, dmenu, and rofi all function relatively well in Sway, but all run under XWayland and suffer from the safe issue where they can become unresponsive if the cursor is moved to a native Wayland window. Moving the cursor to an XWayland window and pressing Escape should fix the issue, and sometimes pkill does too.

One alternative is bemenu, which is a native Wayland dmenu replacement.


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 the first available sway socket, and retrying your command:

$ export SWAYSOCK=$(ls /run/user/*/sway-ipc.*.sock | head -n 1)

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

Incorrect Monitor Resolution

Config options such as output "HDMI-A-1" res 1280x1024 may not successfully change the resolution. The compositor wlc is responsible for setting the resolution, and attempts to figure out monitor resolution from the TTY.

You may be able to alter your TTY resolution (thus also altering the WLC and Sway resolution) by passing a kernel parameter such as video=HDMI-A-1:1280x1024:e or with with custom edid binaries (see Kernel Mode Setting).

See also