Sway

Sway is a tiling Wayland compositor and a drop-in replacement for the i3 window manager. It works with your existing i3 configuration and supports most of i3's features, plus a few extras.
Install appropriate video drivers for your hardware before you can launch sway. Without graphics drivers errors may occur. 
== Manual Installation ==
The below installation step allows you to pick and choose various componenents for your Sway Desktop.
=== Add a normal user ===
Use setup-user to add a non-system normal user for running Sway.
=== Set up eudev ===
=== Install Graphics Drivers ===
Install graphics driver for your video hardware. Without proper driver, Sway will fail to start.
=== Setup up a seat manager ===
Wayland compositors need raw access to input and output devices. This is mediated by a seat manager. 
Configure either seatd or elogind as both are supported. However using both may lead to conflicts.
=== Install fonts ===
Install DejaVu fonts, which has good Unicode coverage:
 
 
=== Install Sway ===
 
For complimentary software alternatives, see sway wiki or Gentoo Wiki.
== Starting sway ==
=== Manually launch sway ===
You can launch <Code>sway</Code> by issuing the command sway from TTY. 
=== Automatically launch sway on TTY login ===
Adding the following lines to your will launch Sway automatically with D-Bus only in tty1 
=== Use Wrapper script to launch sway ===
Instead of using for environment variables, a wrapper script <Code>sway-run</Code> can be used to launch <Code>sway</Code> from both TTY and greetd, a lightweight display manager. Here is a sample wrapper script: 
Make the file executable: 
== Configuration ==
===Sway config file ===
Copy default sway configuration file to so that it can be customized per user:
Read through it to learn the default keybindings.
Sway configuration is mostly backwards-compatible with that of i3 and if you are looking for a solution for a specific issue, you may also try checking if it hasn't been provided for i3WM.
For additional information, start at man 5 sway and read the upstream wiki.
=== PipeWire and Screensharing ===
For audio playback, install PipeWire. The sway compositor has no involvement in audio playback.
For screen sharing, applications are split into two categories:
* Those which use the native wayland protocol, </code>wlr-screencopy</code>
* Those which use the API from Flatpak's xdg-desktop-portal (this portal is also used by native non-Flatpak applications).
Applications in the first group require no additional setup. Applications in the second group (which includes Firefox and Chromium) require setting up xdg portals in addition to PipeWire.
 
Launch PipeWire with Sway by adding the following to sway config file: 
 exec /usr/libexec/pipewire-launcher
If you are using dbus-run-session wrapper to launch sway, you also need to set D-Bus variables for the portal and screensharing features to work by adding the following to sway config file:
 exec dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
=== Screen lock and suspend-to-RAM ===
Putting the system to sleep with elogind requires elevated privileges or additional configuration.
For details on configuring doas with elogind, see Elogind#Doas
To put the system to sleep after 600 seconds, use:
 exec swayidle -w timeout 600 'doas /bin/loginctl suspend'
loginctl suspend command will trigger the screenlock, as mentioned in the section Install elogind (optional) above.
Do not lock the screen if program is running in full screen:
 for_window [app_id="^.*"] inhibit_idle fullscreen
=== Elogind and swayidle ===
swayidle has integration with elogind and can handle before-sleep events.
If using swayidle before-sleep, there will be a race condition, so that when you resume the computer from suspend, the screen shows the contents of the unlocked screen for a second before showing the actual lock screen. This can be a privacy concern.
To solve this issue, do the following:
Create this file /etc/elogind/system-sleep/10-swaylock.sh, then add the following script to this file:
 #!/bin/sh
 if [ "${1}" == "pre" ]; then
 touch /tmp/swaylock-sleep
 sleep 1
 fi
Then set it to executable.
Later, once sway is installed, add the following line to sway config file:
 exec touch /tmp/swaylock-sleep && inotifyd swaylock /tmp/swaylock-sleep
With this line, the screen will be promptly locked before suspend-to-RAM starts.
=== Brightness control ===
Refer Backlight for information on brightness control utilities including the popular brightnessctl utility.
=== Output scaling for high resolution displays ===
Without further configuration, program interfaces might be too small to use on high resolution displays.
Sway supports the per-display configuration of
* fractional (e.g., 1.5x), and
* integer scaling (e.g., 2x) 
However, fractional scaling is discouraged due to both the performance impact and the blurry output it produces. In this case, where 1x scaling is too small and 2x scaling is too large, program-specific GTK/QT based scaling is recommended. See below.
To enable Sway scaling, the user can first preview different scaling factors with wdisplays package. Note the output name (eDP-1, LVDS-1) and try apply scaling factors such as 1 and 2. To make changes permanent, add below to sway config file.
output <name> scale <factor>
To use toolkit scaling, use
=== Screenshots ===
A simple tool that works well under Wayland is Grimshot. Example keybindings:
bindsym Print exec grimshot copy area
bindsym Shift+Print exec grimshot copy screen
bindsym Control+Print exec grimshot save area ~/Pictures/$(date +%d-%m-%Y-%H-%M-%S).png
bindsym Control+Shift+Print exec grimshot save screen ~/Pictures/$(date +%d-%m-%Y-%H-%M-%S).png
See the sway wiki's article for a list of screenshot tools.
=== Make clipboard content persistent ===
By default the clipboard content does not persist after terminating the program: you copy some text from Firefox and then exit Firefox, the copied text is also lost.
Install from testing repo and add the following to sway config file:
exec wl-paste --type text/plain --watch clipman store --histpath="~/.local/state/clipman-primary.json"
bindsym $mod+h exec clipman pick --tool wofi --histpath="~/.local/state/clipman-primary.json"
=== Firefox picture-in-picture mode/floating windows ===
Add this to your sway config file (modify the numeric values to suit your needs and your display):
for_window [app_id="firefox" title="^Picture-in-Picture$"] floating enable, move position 877 450, sticky enable, border none
=== Start with NumLock enabled ===
Add this to your sway config file:
 input type:keyboard xkb_numlock enabled
=== Change mouse cursor theme and size ===
Add to your sway config file:
 seat seat0 xcursor_theme my_cursor_theme my_cursor_size
For example, set a mouse cursor, using GNOME Adwaita theme:
 seat seat0 xcursor_theme Adwaita 16
You can inspect their values with echo $XCURSOR_SIZE and echo $XCURSOR_THEME. If reloading your config does not result in change, try logging out and in.
=== Custom keyboard layout ===
To use custom keyboard layout, just use
input type:keyboard {
 xkb_file /path/to/my/custom/layout
}
== Troubleshooting ==
If you encounter any issues, try running sway -Vc /etc/sway/config. It will run sway with the default config file and set the output to be more verbose. It is generally a good idea to track your config files with git (when and if at all you use a remote repository for them, keep it private for security reasons). 
To capture the sway error log in a file for troubleshooting, replace sway in your startup file by 
sway -d 2> ~/sway_error.log. 
Alternately, you can also issue the below command from TTY.
 
=== Video Driver Issues === 
After installing sway, while launching it for the first time, lack of proper video drivers causes various error messages such as:
* "unable to create backend"
* "Failed to create renderer"
Do install necessary drivers for your graphics card for sway to work. 
=== Flatpaks ===
Due to their sandboxing, flatpaks require the use of a portal frontend (xdg-desktop-portal) and backends (such as xdg-desktop-portal-wlr, xdg-desktop-portal-gtk, xdg-desktop-portal-gnome) that implement the methods. When in doubt, install multiple backends. For more information on backends, see flatpak's page on the subject. In addition to the steps under the "Firefox Screensharing" section, it may also be necessary to launch additional backends in your Sway config file. Otherwise, you may run into GDBus errors as your flatpak fails to interface with the portal. This can cause issues such as with opening your file directories from a flatpak application.
After installing different backends, you might need to add the relevant backends to your sway config file similarly to in the "Firefox Screensharing" section above. For example, an autostart section of your sway config file may include:
exec /usr/libexec/xdg-desktop-portal-gtk
exec /usr/libexec/xdg-desktop-portal-wlr
exec /usr/libexec/xdg-desktop-portal-gnome
This is only needed if they are not started automatically via other means.
=== Firefox (Flatpak) and/or GTK apps ===
==== Disappearing cursor ====
You may need to get an icon pack and possibly a theme from Pling store and set GTK_THEME environmental variable. Alternatively you can install a theme for all users (search Alpine Linux Packages for *-icon-theme) using apk add.
==== Missing file picker/cannot download ====
Go to about:config and set widget.use-xdg-desktop-portal.file-picker to 0.
=== Nvidia Issues ===
As of Dec 31 2022, Nvidia still doesn't fully support Wayland. Therefore, the possible solutions are as outlined in the link, or setting your WLR_BACKENDS environmental variables to drm,libinput or x11 (add libinput here as well if you cannot use your mouse and keyboard after starting Sway). The latter also works for AMD/ATI cards (make sure to install libinput first).
== See also ==
* Sway Wiki
* Archwiki
* Gentoo Wiki
* PostmarketOS Wiki
Category:Compositor
Category:Desktop
Category:Window Managers
Category:Wayland