Sway
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.
Installation
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.
Starting
From a TTY
To start Sway, simply type sway from a TTY.
From a display manager
The sway session is located at /usr/share/wayland-sessions/sway.desktop
. It is automatically recognized by modern display managers like GDM and SDDM.
Configuration
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.
Keymap
By default, sway starts with the US QWERTY keymap. To configure per-input:
~/.config/sway/config
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.
Statusbar
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:
~/.config/sway/config
bar { status_command i3status }
If you want to achieve colored output of i3status, you can adjust following part in the i3status configuration:
~/.config/i3status/config
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.
Wallpaper
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 "*"
):
~/.config/sway/config
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:
~/.config/sway/config
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).
HiDPI
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:
~/.config/sway/config
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.
Xresources
Copy ~/.Xresources
to ~/.Xdefaults
to use them in Sway.
Run programs natively under Wayland (without Xwayland support)
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:
~/.config/sway/config
xwayland disable
Tips and tricks
Autostart on login
To start sway from tty1 on login with default US keyboard, edit:
~/.bash_profile
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then XKB_DEFAULT_LAYOUT=us exec sway fi
Backlight toggle
To turn off (and on) your displays with a key (e.g. Pause
) bind the following in your Sway config
:
#!/usr/bin/dash read lcd < /tmp/lcd if [ "$lcd" -eq "0" ]; then swaymsg "output * dpms on" echo 1 > /tmp/lcd else swaymsg "output * dpms off" echo 0 > /tmp/lcd fi
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.
~/.config/sway/config
bindsym --release Print exec grim -g \"$(slurp)" - | wl-copy
Troubleshooting
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.
VirtualBox
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 SWAYSOCK=/run/user/1000/sway-ipc.1000.4981.sock
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.