Sway
Sway (contracted from SirCmpwn's Wayland compositor ) 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 sway-gitAUR. It is advisable to always update wlroots when you update sway, due to tight dependencies.
--unsupported-gpu
.You may also install swaylock, swayidle and swaybg to lock your screen, set up an idle manager and set wallpapers respectively.
The default application launcher is dmenu and the default terminal emulator is foot. Before starting sway it is advisable to either install them or set a new launcher and terminal in the configuration.
Starting
Before Sway can be started, it needs access to your hardware devices such as your keyboard, mouse, and graphics card. The collection of these hardware devices is called a seat, as mentioned in .
On Arch Linux, Sway can get access to your seat using either
- and , or
- , which will be installed alongside Sway as a dependency of wlroots
If polkit
is already installed on your system, Sway should automatically get access to your seat.
Alternatively, if polkit
is not installed on your system and you want to use instead, add yourself to the user group and enable/start , re-log and pick one of the following methods to start Sway.
Manually
To start Sway, simply type in the Linux console.
Automatically on TTY login
Similarly to X, Sway can be started by adding the following to your shell initialization file (see Command-line shell#Login shell):
For more details, see Xinit#Autostart X at login
From a display manager
The sway session is located at . It is automatically recognized by modern display managers like GDM and SDDM.
It is also possible to start sway as a systemd user service through the display manager.
Also you can use text-based session manager, see Display manager#Console.
Configuration
If you already use i3, you may copy your i3 configuration to and it should work out of the box. Otherwise, copy the sample configuration file located at /etc/sway/config
to . See 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" xkb_variant "colemak,,typewriter" xkb_options "grp:win_space_toggle" } input <identifier> xkb_model "pc101"
More details are available in and .
The keymap can also be configured using environment variables (, , etc.) when starting . The configuration options take precedence over environment variables.
Typematic delay and rate
To change typematic delay and rate, you can add the following lines to your section:
Statusbar
Sway ships with a default status bar in the form of swaybar which runs in a pure Wayland environment. swaybar can call a shell script or other program to show information in the status bar. See and swaybar-protocol(7) for details.
Installing i3status is an option to obtain a practical, default status bar under Wayland. All you have to do is add the following snippet at the end of your sway config:
~/.config/sway/config
bar { status_command i3status }
If you want to enable colored output for i3status, you need to adjust the following part in the i3status configuration:
Wallpaper
The displaying of a wallpaper in sway is handled by a dedicated program which is packaged separately as swaybg. It is needed in order to run the output command.
The following line, which can be appended at the end of your sway configuration, sets a background image on all displays (output matches all with name ):
Of course you have to replace the file name and path according to your wallpaper.
Solid colors may be set as follows:
output * bg #000000 solid_color
You may use as the GTK3 frontend to swaybg.
Input devices
It is possible to tweak specific input device configurations. For example, to enable tap-to-click and natural scrolling for all touchpads:
To set the configuration for a particular touchpad, use to obtain a device identifier and use it instead of .
swaymsg -t get_inputs
command may contain "\" to escape symbols like "/" (e.g. "2:14:ETPS\/2_Elantech_Touchpad"
). These need to be removed.More documentation and options like acceleration profiles or disabling input entirely can be found in .
HiDPI
Set your displays scale factor with the command in your configuration file. The scale factor can be fractional, but it is usually 2 for HiDPI screens.
~/.config/sway/config
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 volume, monitor brightness or media players:
See PulseAudio#Keyboard volume control, Advanced Linux Sound Architecture#Keyboard volume control, Backlight#Backlight utilities and MPRIS for details and alternative utilities.
To allow a keybinding to be executed while the lockscreen is active add the parameter to bindsym.
bindsym --locked XF86AudioPlay exec playerctl play-pause
Graphical indicator bars
It is often desirable to have the current level of some percentage-valued setting, such as brightness or volume, be indicated by a graphical bar when it is adjusted. A good option for providing this facility in Sway is (alternatively ), which provides a subset of the functionality of the popular X tool but as a native Wayland utility implementing the layer-shell protocol. See the project website for usage examples.
Overview of workspaces
If you are using a lot of workspaces with a lot of windows and cannot follow what is where any more, then sovAUR can come in handy. It is an overlay that shows schemas for all workspaces to make navigation in sway easier. It shows program names, window titles, supports multi-output setup. See the project page for more information.
Idle
Sway has a dedicated idle management daemon named to handle idling sessions. There are different ways to start and parameterize the daemon. The simplest is to use the configuration of sway itself. accepts a multitude of arguments to configure events like timeout
(a.k.a. idling), (resume from sleep), etc. See for more details and further explanations of the events. Each event can then be assigned an action. To assign multiple actions to an event simply repeat the trigger.
The following instructs to lock the screen after 30 minutes and turn it off five seconds after:
To turn off a locked screen much sooner e.g. after 10 seconds, grep the process list for your locking manager and execute accordingly like so:
timeout 10 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi'
In order to lock the screen before suspending and pause any playing media, amend the following instructions to the swayidle command:
before-sleep 'playerctl pause' before-sleep 'swaylock'
Floating windows
To enable floating windows or window assignments, open the application and then use the app_id
, the , the and the attributes to enable floating windows/window assignments. The following command will list the properties of all the open windows.
$ swaymsg -t get_tree
To get only the app_id
's of all open windows use:
$ swaymsg -t get_tree | grep "app_id"
To get the app_id
of the focused window use:
$ swaymsg -t get_tree | jq -r '..|try select(.focused == true)'
If the app_id
happens to be null for some windows, you might have to use the and/or the attributes to enable floating mode/window assignments. You can search the output and create fine grained rules for your windows.
This is similar to using to find the or wm_name
attributes in X11.
When using multiple monitors, the floating scratchpad window can get too large, covering more than one monitor. This command centers and resizes the floating window to 80% of the current monitor's size:
$ swaymsg move position center; swaymsg resize set 80ppt 80ppt
Clipboard
By default, the clipboard is emptied whenever a window is closed. This can be a surprising default behaviour.
A "clipboard manager" must be installed to make the clipboard's content shared amongst windows.
One example of a clipboard manager, designed for Wayland, is clipman, which can be installed from or .
To start clipman with Sway, add the following line to your configuration file:
~/.config/sway/config
exec wl-paste -t text --watch clipman store --no-persist
Xresources
Copy to to use them in Sway.
XWayland
See Wayland#XWayland for details and an overview of available packages.
The use of XWayland is enabled by default.
If you would like to disable XWayland entirely and run a "pure" Wayland session, set the following to deactivate the use of XWayland:
Use another wlroots renderer
You can use another wlroots renderer by specifying the environment variable. The list of available ones is on the wlroots documentation.
Tips and tricks
Initially enable CapsLock/NumLock
By default, sway initially disables the CapsLock
and keys on startup. To instead enable them on startup, set the and/or input configurations to for your keyboards. For example, to do so on all keyboards, add the following lines to your sway configuration:
In either case, the CapsLock
and keys may be toggled by pressing the relevant keys on a keyboard.
Current keyboard layout
The current keyboard layout can be retrieved as follows, where needs to be replaced with your keyboard's identifier:
$ swaymsg -t get_inputs | jq -r '.[] | select(.identifier == "kbd_identifier") | .xkb_active_layout_name'
Compose key
To set up as the compose key:
$ swaymsg 'input * xkb_options compose:prsc'
The available key combinations can be looked up as shown in Xorg/Keyboard configuration#Configuring compose key. The combinations for the compose key can also be configured in the XCompose file. Applications need to be restarted for this change to take effect.
Backlight toggle
To turn off (and on) your displays with a key (e.g. ) bind the following script in your Sway :
Or you can use the toggle option directly, but you need to specify an output explicitly if you have multiple monitors:
$ swaymsg "output output_name dpms toggle"
Screen capture and screen sharing
Color temperature adjustment
See Backlight#Wayland.
Control swaynag with the keyboard
Swaynag, the default warning/prompt program shipped with sway, only supports user interaction with the mouse. A helper program such as may be used to enable interaction via keyboard shortcuts.
Swaynagmode works by first launching swaynag, then listening for signals which trigger actions such as selecting the next button, dismissing the prompt, or accepting the selected button. These signals are sent by launching another instance of the swaynagmode script itself with a control argument, such as swaynagmode --select right
or .
Swaynagmode by default triggers the sway mode upon initialization, followed by default
on exit. This makes it easy to define keybindings in your sway configuration:
Note that, beginning in sway version 1.2, mode names are case-sensitive.
You can configure sway to use swaynagmode with the configuration command .
Change cursor theme and size
To set the cursor theme and size:
Where can be set to or replaced by a specific value like default
, or , and my_cursor_size
a value like .
You can inspect their values with and .
Note that you need to restart the application to see the changes.
Manage Sway-specific daemons with systemd
Systemd provides a which is a user unit which is active whenever any graphical session is running, whether Xorg or Wayland. User services which should run in all graphical environments can be bound to that target. It also allows for a window-manager-specific target to be bound to to start and stop services which should run only under that window manager. See systemd.special(7)
Users may want to start some services/daemons (such as swayidle or ) only when the current window manager is Sway, and they may also want these services to stop when Sway stops. Additionally, users who are running may want to have the services be in separate cgroups so that a single memory-hungry service does not take down the whole Sway session (see the Fedora bug report).
Some or all of this functionality is provided by Arch Sway packages. For example, the sway package in community provides the file and both sway and sway-gitAUR provide a 50-systemd-user.conf
drop-in file for the directory. This file imports required environment variables into the systemd user session and dbus if the Sway file contains .
If you intend to provide functionality using the roll-your-own method described below or by using a specialist package such as or you should consider removing files that provide the same functionality.
This functionality can be provided on a roll-your-own basis by creating a and let those daemons/services wanted by . This systemd target should be a user target (see systemd/User). For example:
Then, add the following line to Sway's configuration file (for example, append the line to , or add a new file to ):
With the above line in the configuration file, whenever Sway starts, it also activates .
Finally, link the desired services to . For example, adding a (or ) service:
When this user unit is enabled, it is only activated when Sway is running and deactivated when Sway stops.
The creation of the file and the importing of the environment can also be accomplished by installing . In addition to separating services into cgroups, sway-systemd also places each GUI application in its own cgroup. This enables imposition of per-cgroup resource constraints on individual application. See the sway-systemd README.
Change screen resolution after start
You can use the graphical program wdisplaysAUR or the terminal program to change the resolution, rotate and arrange displays.
Create headless outputs
Create outputs not related to a physical video interface, HEADLESS-1, HEADLESS-2, etc.:
$ swaymsg create_output
Print a description of the new output:
$ swaymsg -pt get_outputs | grep -A 10 HEADLESS
Configure the new output with the command, for example:
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 does too.
is a native Wayland dmenu replacement which can optionally be combined with 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 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.
Also binary provided by plasma-workspace package can serve as launcher, offering both XWayland and native Wayland support.
is a fork of rofi that works in Wayland and also has an flag if you need to launch it in an X11 session.
is a command launcher, that provides some of the same features as rofi but running under Wayland. wofi lacks some features from rofi like an SSH mode and a window-switching mode. It is based on wlroots library and use GTK3 for rendering. It works pretty well with sway.
Virtualization
Sway works with both VirtualBox and VMware ESXi.
For Sway to work in QEMU, QEMU must be started with . See also QEMU#qxl.
Unable to start Sway from tty
For ESXi, you need to enable 3D support under the Hardware Configuration > Video card settings. See also VMware#Enable 3D graphics on Intel, Optimus and AMD.
No visible cursor
When using certain graphics drivers (e.g. the VMSVGA graphics controller or the proprietary NVIDIA driver), the cursor is invisible. This can be fixed by using software cursors as discussed in :
$ export WLR_NO_HARDWARE_CURSORS=1
Sway socket not detected
Using a 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 could not connect to the socket provided in your .
To view what the current value of is, type:
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.
Failed to connect to a Wayland server
Tmux creates local environment variables for each session (to see them type: ). Therefore, if you re-attach to a previous tmux session with tmux-resurrect or tmux-continuum, or your tmux server runs before sway starts, the environment variables are outdated.
You can use update-environment
to instruct tmux to update them whenever you attach to the session by adding the following to your :
set-option -g update-environment "DISPLAY WAYLAND_DISPLAY SWAYSOCK SSH_AUTH_SOCK"
Unable to retrieve socket path
Requesting messages from on a tty may return the following message:
Unable to retrieve socket path
environment variable is set after launching Sway, therefore a workaround to this error is to request in a terminal inside Sway.
Keybindings and keyboard layouts
By default, if you are using more than one keyboard layout, e.g. , bindings may become broken when you switch on some secondary layout.
Thanks to https://github.com/swaywm/sway/pull/3058, all you need is to add key to sensitive bindsym
lines like this:
Alternatively you can create a variable and then replace all instances of bindsym
with like so: $mybind $mod+w thing
Java applications
Some Java-based applications will display blank screen when opened, for example any JetBrains editor such as IntelliJ, CLion, or PyCharm. To mitigate this, the application can be started with the environment variable set to 1.
If you start the application from a launcher like rofi or dmenu, you might want to modify the application desktop entry as shown in Desktop entries#Modify environment variables.
Some issues with Java applications have been fixed in OpenJDK 11 and Sway 1.5. However, certain applications require additional configuration to use newer versions of OpenJDK, in the case of Android Studio you must set .
Scroll on border
If using the mouse scroll wheel on an application's border crashes sway, you could use for the app_id
(e.g. Firefox).
Program cannot open display
If a program crashes on start with the error message "cannot open display", it is likely that the program you are using is an X11 program. You can use the XWayland compatibility layer to run X11 programs under Wayland, see #XWayland for details.
Unable to open wayland socket
If sway won't launch and outputs the error message "Unable to open wayland socket", that may mean the `$XDG_RUNTIME_DIR` environment variable is set but the specified directory is missing.
Mouse not working in WINE applications
When running programs, WINE expects a primary monitor to be set, which can cause issues (such as clicks not registering) as Wayland has no concept of a primary monitor. Instead, you can specify a primary monitor for XWayland to use via xrandr by adding this line to your Sway configuration:
Note that XWAYLAND0 (or any XWAYLAND display name) may not represent your monitor, and may be susceptible to change in different sessions. Instead, you can specify the first XWAYLAND display using this line instead:
exec_always xrandr --output $(xrandr | grep -m 1 XWAYLAND | awk '{print $1;}') --primary
You may need to adjust these lines to suit your needs. You can find out which displays are mapped to what names by using the command with no arguments.