Sway: Difference between revisions

From Alpine Linux
(Continual editing to flesh out the installation process; format edits)
Tag: Reverted
(1.Added sample setup-desktop,dbus-run-session clis; 2.Added ext links DejaVu,Unicode,wlr-screencopy;int links PipeWire, user services; DBus link x1 only; 3.New tty1 block usefulness; 4.zzz now in community [since Alpine 3.18], not testing; 5.Added scaling subheadings; 6.Todo: update Nvidia passage; 7.Style amendments inc. title sentence headings (Help:Style); references to Sway compositor or desktop capitalised: cf. 'Output scaling for high resolution displays', etc; 8. sway_error line corrected)
 
(163 intermediate revisions by 14 users not shown)
Line 1: Line 1:
[http://swaywm.org Sway] is a tiling [[Wayland]] compositor. It's a drop-in replacement for the i3 window manager.
[https://swaywm.org Sway] is a tiling [[Wayland]] compositor and a drop-in replacement for the [[i3wm |i3 window manager]]. It works with your existing i3 configuration and supports most of i3's features, plus a few extras.


== Setup ==
== Prerequisites ==


Don't forget, you will need to add the community repository.
* Internet [[Configure_Networking#Connectivity_testing|connectivity]], unless the packages have been pre-fetched into a local cache.
* Install appropriate [[Graphics driver]] drivers for your hardware. Without graphics drivers [[#Video Driver Issues|errors]] are likely to occur.
* A [[Setting_up_a_new_user#Creating_a_new_user|non-root user account]].
* The [[Repositories#Managing_repositories|community repositories must be enabled]].
* Set up [[eudev]].
* Wayland compositors need raw access to input and output devices, typically mediated by a [[seat manager]]. Either [[seatd]] or [[elogind]] work fine, but installing both leads to conflicts.
{{Tip|Except for the first two [[#Prerequisites|prerequisites]], all of the others are automatically handled if the desktop is [[#Setup-desktop|installed using the following setup-desktop]] script.}}


<pre>
== Setup-desktop ==
$ whoami
 
user
The [[setup-desktop]] command automates the Sway desktop installation with [[eudev]] and [[elogind]].
$ su -
 
Password:
{{cmd|# setup-desktop sway}} 
# whoami
 
root
Proceed to the [[Sway#Starting Sway|Starting Sway]] section, as no [[Display manager|display manager]] is being installed nor configured by the script that would boot into a graphical login screen.
# cat /etc/apk/repositories
 
<snippet>
== Manual Installation ==
# # You can edit the files in vi and remove the comment '#' from the line that has <verson>/community
 
</pre>
The installation steps below allow you to pick and choose various components for your Sway desktop.
 
=== Install Fonts ===
 
Install [https://dejavu-fonts.github.io/ DejaVu] fonts ({{Pkg|font-dejavu}}), which have good [https://home.unicode.org/ Unicode] coverage:
 
{{cmd|# apk add font-dejavu}} 
=== Install Sway ===
 
{{cmd|# apk add sway \
    xwayland            \ # if you need the xserver
    foot                \ # default terminal emulator. Modify $term in config for a different one.
    wmenu                \ # default Wayland native menu for choosing program and screensharing monitor
    swaylock swaylockd  \ # lockscreen tool
    swaybg              \ # display wallpaper
    grim                \ # screenshot tool
    wl-clipboard        \ # clipboard management
    i3status            \ # simple status bar
    swayidle              # idle management (DPMS) daemon
}}
 
For complimentary software alternatives, see [https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway Sway's wiki] or [https://wiki.gentoo.org/wiki/List_of_software_for_Wayland Gentoo's wiki].
 
== Starting Sway ==
 
=== Manually Launch Sway ===
 
You can launch Sway manually by issuing the <Code>sway</Code> command from a TTY.


Once you have updated the file manually you can continue to the [[Installation|installation]] step
{{Cmd|$ sway}}


{{Tip| Or you can run something *ridiculous* like this:
{{Tip|When using [[Wayland]], for [[PipeWire]] and screensharing to work in Firefox and Chromium, a [[D-Bus]] is required. In the absence of a [[OpenRC#User_services|user service manager]], consider running <Code>sway</Code> with <code>dbus-run-session</code>, a convenient wrapper that will explicitly export the path of the session bus.{{Cmd|$ dbus-run-session sway}}
<pre>
# tFILE='/etc/apk/repositories'
# line="$(cat $tFILE | grep -E "^#.*alpine/v.*/community" | cut -f1 -d:)" # add the comments so that it doesn't run everytime
# awk -v line=$line 'FNR == line { sub("#",""); print } FNR != line { print }' $tFILE > $tFILE.upd
# cat $tFILE.upd # if everything is correct after inspection then we can move it over
<snippet>
# cp $tFILE $tFILE.bak # just in case the hairbrained idea doesn't work
# cat $tFILE.upd > $tFILE; rm $tFILE.upd # we want to keep the file permissions so don't use cp
</pre>
}}
}}
== Installation ==


eudev:
=== Automatically Launch Sway on tty1 ===
 
Adding the following lines to {{Path|~/.profile}} or to its equivalent will ensure that <Code>sway</Code> launches automatically, with a D-Bus, ''only'' from ''tty1''.  This is handy for troubleshooting, because if the Sway configuration ever falters, one could troubleshoot by logging into a different TTY (''tty2''-''tty6''), and your startup script then will not attempt to launch the faulty Sway environment from there also.
{{Cat| ~/.profile|<nowiki>
...
 
if [ "$(tty)" = "/dev/tty1" ]; then
    exec dbus-run-session sway
fi
...</nowiki>}}
 
=== Using a Wrapper Script to Launch Sway ===
 
Instead of using {{Path|~/.profile}} or its equivalent file, a [https://man.sr.ht/~kennylevinsen/greetd/#how-to-set-xdg_session_typewayland wrapper script] can be placed at {{Path|/usr/local/bin/sway-run}}. This script can be used to launch <Code>sway</Code> from either a TTY or by [[greetd]], a lightweight [[Display manager|display manager]], as follows: {{Cat|/usr/local/bin/sway-run|<nowiki>#!/bin/sh
# Session
export XDG_SESSION_TYPE=wayland
export XDG_SESSION_DESKTOP=sway
export XDG_CURRENT_DESKTOP=sway
 
# Wayland stuff
export MOZ_ENABLE_WAYLAND=1
export QT_QPA_PLATFORM=wayland
export SDL_VIDEODRIVER=wayland
export _JAVA_AWT_WM_NONREPARENTING=1
 
# Launch Sway with a D-Bus server
exec dbus-run-session sway "$@" </nowiki>}}
 
Make the file executable:
{{Cmd|# chmod +x /usr/local/bin/sway-run}}
 
== Configuration ==
 
===Sway config File ===
 
Copy the default Sway configuration file to {{Path|~/.config/sway/config}} so that it can be customized as per each user's choices:


<pre>
{{cmd|$ mkdir -p ~/.config/sway
# whoami
$ cp /etc/sway/config ~/.config/sway/}}
root
# rc-update # let's look at the services that are configured for each run-level
<snippet>
# apk add eudev
# setup-devd udev
# rc-update # we can now see the services that have been added by the setup script
<snippet>
</pre>


==== What if the services <var>hwdrivers</var> or <var>mdev</var> are not in the <var>sysinit</var> run-level? ====
Read through it to learn the default keybindings.
<blockquote>
Sway's configuration is mostly backward compatible with that of [[I3wm|i3]]'s, and if you are looking for a solution for a specific issue, you could try checking whether it hasn't been provided for the i3 window manager.
"udev performs its own hwdrivers module detection, it does not need the additional service. We delete the hwdrivers service when enabling udev, and add it when enabling mdev and mdevd."
<hr/>
<strong>Source: </strong>[https://gitlab-test.alpinelinux.org/alpine/alpine-conf/-/merge_requests/100 alpine-conf]
</blockquote>


For additional information, start at <code>man 5 sway</code> and read the [https://github.com/swaywm/sway/wiki upstream wiki].


=== PipeWire and Screensharing ===


Graphics drivers:
The Sway compositor has no involvement with audio playback. In order for screensharing to work, [[PipeWire]] is required. Therefore, installing [[PipeWire#Installation|PipeWire]] is recommended for audio playback too.


* [[Intel Video]]
Since v3.22, Alpine Linux provides the necessary scripts to start PipeWire as a [[OpenRC#user services|user service]] in OpenRC. Alternatively, PipeWire can be launched with Sway by adding the following line to Sway's {{Path|config}} file:  
* [[Radeon Video]]
exec /usr/libexec/pipewire-launcher
* [[Nvidia Video]]
Add user to the input and video groups:


<pre>
From a screensharing perspective, applications are split into two categories:-
# tmpUSER='<user>' # setting the tmpUSER variable instead of overriding an environment variable
# echo "Username set: $tmpUSER" # remember to replace <user> for the username that you have set on your machine
Username set: user
# adduser $tmpUSER input
# adduser $empUSER video
</pre>


* Those which use the native Wayland [https://wayland.app/protocols/wlr-screencopy-unstable-v1 wlr-screencopy] protocol
* Those which use the API from Flatpak's <code>xdg-desktop-portal</code> (this portal is also used by native non-Flatpak applications).


Install some TTF fonts:
Applications in the first group require no additional setup. Applications in the second group (which include Firefox and Chromium) require setting up ''xdg portals'' in addition to [[PipeWire#Installation|PipeWire]].


<pre>
{{Cmd|# apk add xdg-desktop-portal xdg-desktop-portal-wlr}}
# apk add ttf-dejavu
<snippet>
</pre>


seatd daemon:
If you are using a <code>dbus-run-session</code> wrapper to launch Sway, you will also need to set D-Bus variables in order for the portal and for [[#PipeWire and Screensharing|screensharing]] features to work;  add the following line to the beginning of Sway's {{Path|config}} file:


<pre>
exec dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
# # if we like we can look at the services again using rc-update
# apk add seatd
<snippet>
# rc-update add seatd
# # and then look again to compare
# rc-service seatd start
# adduser $tempUSER seat
</pre>


==== What does <var>seatd</var> do? ====
=== Screen Lock and suspend-to-RAM ===
<blockquote>
"Seat management takes care of mediating access to shared devices (graphics, input), without requiring the applications needing access to be root."
<hr/>
<strong>Source: </strong>[https://sr.ht/~kennylevinsen/seatd/ sourcehut]
</blockquote>


Install sway:
{{Tip| For a seat manager-agnostic and DE-/WM-agnostic tool, consider installing the {{Pkg|zzz}} utility, available in the [[Repositories#Community|community]] repository, or the {{Pkg|powerctl}} utility from the [[Repositories#Testing|testing]] repository, in order to manage suspend and hibernation.}}


<pre>
Putting the system to sleep with the <Code>loginctl suspend</Code> command from [[Elogind]] requires elevated privileges or additional configuration.  
# apk add sway sway-doc
<snippet>
# apk add                \ # Install optional dependencies:
    xwayland            \ # recommended for compatibility reasons
    foot                \ # default terminal emulator. Modify $term in config for a different one.
    bemenu              \ # wayland menu
    swaylock swaylockd  \ # lockscreen tool
    swaybg              \ # wallpaper daemon
    swayidle              # idle management (DPMS) daemon
</pre>


==== What if I run into a problem with sway? ====
To put the system to sleep after 600 seconds, use:
You can always check the version that you are running
<pre>
# sway --version
Error loading shared library libjson-c.so.5: I/O error (needed by /usr/bin/sway)
<snippet>
</pre>


When this error occurred I was experiencing trouble with the filesystem. The filesystem had *booped* itself into <var>read-only mode</var>. A reboot fixed this error.
exec swayidle -w timeout 600 'doas /bin/loginctl suspend'
<pre>
# sway --version
sway version 1.7
</pre>


Configure [[Wayland#XDG_RUNTIME_DIR|XDG_RUNTIME_DIR]].
Do not lock the screen if program is running in full screen:


== Usage ==
for_window [app_id="^.*"] inhibit_idle fullscreen


For inter-program communication and functionality such as screensharing, install and enable dbus and PipeWire, see [[PipeWire]] and set <code>SWAYSOCK</code> environmental variable to the value exported by <code>sway</code>. In order to ensure that Pipewire and related services inherit the right environment variables, it is recommended to start these services via a process that is a direct descendant of sway itself.
{{Todo|The option below, related to <Code>wayland-pipewire-idle-inhibit</Code>, needs to be tested. If you find the option below to be working, please remove this Todo.}}


Launch Sway with a D-Bus server available, use:
If you do not want to lock the screen while media is being played through [[PipeWire]], then install the {{pkg|wayland-pipewire-idle-inhibit}} package, and add the following to Sway's {{Path|config}} file:


<pre>
exec wayland-pipewire-idle-inhibit
dbus-run-session -- sway #prepend with exec in your login shell init script
</pre>


== Configuration ==
Make changes to the {{Path|~/.config/wayland-pipewire-idle-inhibit/config.toml}} configuration file or to whichever configuration file you may have referenced instead through the <Code> --config <PATH></Code>, if required, as per the [https://github.com/rafaelrc7/wayland-pipewire-idle-inhibit?tab=readme-ov-file#config project's website].


An example config is provided at <code>/etc/sway/config</code>. Copy it to <code>~/.config/sway/config</code> and read through it to learn the default keybindings.
=== Elogind and swayidle ===
Sway configuration is mostly backwards-compatible with that of [[I3wm|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 <code>man 5 sway</code> and read the [https://github.com/swaywm/sway/wiki upstream wiki].
<code>swayidle</code> has integration with <code>elogind</code>, and it can handle ''before-sleep'' events.


=== Firefox screensharing ===
If using <code>swayidle before-sleep</code>, then there will be a race condition, so that when you resume the computer from ''suspend'', the screen will show the contents of the unlocked screen for a second before showing the actual lock screen.  This can be a privacy concern.


For some programs, additional configuration is needed to launch them natively under Wayland and to support special features such as screen sharing.
To solve this issue, do the following.


To launch Firefox natively under Wayland and to enable support for screensharing, you need:
Create the <code>/etc/elogind/system-sleep/10-swaylock.sh</code> file, and then add the following script to this file:
{{Cat|/etc/elogind/system-sleep/10-swaylock.sh|<nowiki>
#!/bin/sh
if [ "${1}" == "pre" ]; then
  touch /tmp/swaylock-sleep
  sleep 1
fi
</nowiki>}}


* Install and configure [[PipeWire]]
Then set it to executable.
* Install xdg-desktop-portal and xdg-desktop-portal-wlr package
* Install wofi for screen selection
* Launch support programs on sway startup:
<pre>
exec /usr/libexec/pipewire-launcher #pipewire must be launched first
exec /usr/libexec/xdg-desktop-portal-wlr
</pre>
* Export the following variables:


<pre>
Later, once Sway is installed, add the following line to its {{Path|config}} file:
export MOZ_ENABLE_WAYLAND="1"
export XDG_CURRENT_DESKTOP=sway
export QT_QPA_PLATFORM="wayland-egl"
</pre>


=== Flatpaks ===
exec touch /tmp/swaylock-sleep && inotifyd swaylock /tmp/swaylock-sleep


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-gtk, xdg-desktop-portal-gnome) that implement the methods. When in doubt, install multiple backends. For more information on backends, see [https://github.com/flatpak/xdg-desktop-portal/#using-portals 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.
With this line, the screen will be promptly locked before ''suspend-to-RAM'' starts.


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:
=== Brightness Control ===
<pre>
exec /usr/libexec/xdg-desktop-portal-gtk
exec /usr/libexec/xdg-desktop-portal-wlr
exec /usr/libexec/xdg-desktop-portal-gnome
</pre>


This is only needed if they are not started automatically via other means.
Refer to [[Backlight]] for information on brightness control.


=== Scaling for high resolution screens ===
=== Output Scaling for High Resolution Displays ===


Without further configuration, program interfaces might be too small to use on high resolution screens.
Without further configuration, program interfaces may be too small to use on high resolution displays.


==== Via sway ====
Sway supports the per-display configuration of:-


Sway supports the per-display configuration of
* fractional (e.g. 1.5x);  and
* integer scaling (e.g. 2x)


* fractional (e.g., 1.5x), and
However, fractional scaling is discouraged due both to the performance impact and to 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 toolkit scaling is recommended. See [[Sway#Toolkit Scaling|See below]].
* 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.
==== Scaling with wdisplays ====


To enable Sway scaling, the user can first preview different scaling factors with <code>wdisplays</code> package.  Note the output name (eDP-1, LVDS-1) and try apply scaling factors such as 1 and 2.  To make changes permanent, add
To enable Sway scaling, the user can first preview different scaling factors with the {{Pkg|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 the following line, completed with your settings, to Sway's {{Path|config}} file.


<pre>
<pre>
Line 197: Line 191:
</pre>
</pre>


to ~/.config/sway/config.
==== Toolkit Scaling ====


==== Via GTK/Qt ====
To use toolkit scaling, say, at x2, add the following, for instance, to your {{Path|~/.profile}}:


<pre>
# for GTK-based programs such as firefox and emacs:
# for GTK-based programs such as firefox and emacs:
export GDK_DPI_SCALE{{=}}2
export GDK_DPI_SCALE=2


# for QT-based programs
# for QT-based programs
export QT_WAYLAND_FORCE_DPI="physical"
export QT_WAYLAND_FORCE_DPI{{=}}"physical"
# or if still too small, use a custom DPI
# or if still too small, use a custom DPI
export QT_WAYLAND_FORCE_DPI=192 # 2x scaling
export QT_WAYLAND_FORCE_DPI{{=}}192 # 2x scaling
export QT_QPA_PLATFORM="wayland-egl"
export QT_QPA_PLATFORM{{=}}"wayland-egl"
</pre>


=== Make clipboard content persistent ===
=== Notification Daemon ===
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 clipman from test repo and add the following to sway config:
[[mako]] is a lightweight notification daemon that works seamlessly with Sway.


<pre>
=== Screenshots ===
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"
</pre>


=== Firefox picture-in-picture mode/floating windows ===
A simple tool that works well under Wayland is {{pkg|grimshot}}. Example keybindings:-
Add this to your sway config file (modify the numeric values to suit your needs and your display):
<pre>
for_window [app_id="firefox" title="^Picture-in-Picture$"] floating enable, move position 877 450, sticky enable, border none
</pre>


=== Screenshots ===
A simple tool that works well under Wayland is Grimshot. Example keybindings:
<pre>
<pre>
bindsym Print exec grimshot copy area
bindsym Print exec grimshot copy area
Line 237: Line 219:
</pre>
</pre>


See [https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway the sway wiki's article] for a list of screenshot tools.
See Sway's [https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway wiki article] for a listing of further screenshot tools.
 
=== Make Clipboard Content Persistent ===
 
By default, the clipboard content does not persist after terminating the program: if you copy some text from Firefox and then exit Firefox, then the copied text is also lost.


=== Start with NumLock enabled ===
Install {{Pkg|clipman}} from the community repo, and then add the following to Sway's {{Path|config}} file:
Add this to your sway config file:
<code>input type:keyboard xkb_numlock enabled</code>


=== Change cursor theme and size ===
Add to your sway config:
<pre>
<pre>
seat seat0 xcursor_theme my_cursor_theme my_cursor_size
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"
</pre>
</pre>
You can inspect their values with <code>echo $XCURSOR_SIZE</code> and <code>echo $XCURSOR_THEME</code>. If reloading your config does not result in change, try logging out and in.
{{Note|Wayland uses client-side cursors. It is possible that applications do not evaluate the values of <code>$XCURSOR_SIZE</code> and <code>$XCURSOR_THEME</code>.}}


=== Start as a service ===
=== Firefox Picture-in-Picture Mode/Floating Windows ===
Although this is not necessary, you may write an init script like the following:
 
Add this to your Sway configuration file (modify the numeric values to suit your needs and your display):
 
<pre>
<pre>
{{/etc/init.d/sway|
for_window [app_id="firefox" title="^Picture-in-Picture$"] floating enable, move position 877 450, sticky enable, border none
#!/sbin/openrc-run
</pre>
 
=== Start with NumLock Enabled ===
 
Add the following to your Sway {{Path|config}} file:
 
input type:keyboard xkb_numlock enabled
 
=== Change mouse cursor theme and size ===
 
Add to your Sway {{Path|config}} file:
 
seat seat0 xcursor_theme my_cursor_theme my_cursor_size
 
For example, set a mouse cursor using the '''GNOME Adwaita''' theme:
 
seat seat0 xcursor_theme Adwaita 16


description="Sway Compositor"
You can inspect their values with <code>echo $XCURSOR_SIZE</code> and <code>echo $XCURSOR_THEME</code>. If reloading your configuration does not result in change, try logging out and in.


command="/usr/bin/sway"
{{Note|Wayland allows for client-side cursors. It is possible that applications do not evaluate the values of <code>$XCURSOR_SIZE</code> and <code>$XCURSOR_THEME</code>.}}
command_args=""


pidfile="/run/sway.pid"
=== Custom Keyboard Layout ===


start_stop_daemon_args="--background --pidfile ${pidfile}"
To use a custom keyboard layout, just use:


depend() {
<pre>
   need localmount
input type:keyboard {
  after elogind
   xkb_file /path/to/my/custom/layout
  use seatd dbus
}
}
</pre>
</pre>
Then as a root run <code>chmod +x /etc/init.d/seat</code> and <code>rc-update add sway default</code>. Make sure you have elogind installed or specify another service, like your display/login manager after which the sway service will run.


=== Custom keyboard layout ===
=== Flatpaks ===
 
{{main|Flatpak}}
Due to their sandboxing, flatpaks require the use of a portal frontend ({{Pkg|xdg-desktop-portal}}) and backends (such as {{Pkg|xdg-desktop-portal-wlr}}, {{Pkg|xdg-desktop-portal-gtk}}, {{Pkg|xdg-desktop-portal-gnome}}) that implement the methods. When in doubt, install multiple backends. For more information on backends, see [https://github.com/flatpak/xdg-desktop-portal/#using-portals flatpak's page on the subject]. In addition to the steps under the [[#PipeWire and Screensharing|screensharing]] section, it may also be necessary to launch additional backends in your Sway {{Path|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.


Since wayland does not support setxkbmap, you will also need to add similar content to your ''/usr/share/X11/xkb/rules/evdev.xml'', after <code></modelList></code> and after <code><layoutList></code>:
After installing different backends, you might need to add the relevant backends to your Sway {{Path|config}} file similar to those shown in the [[Sway#PipeWire and Screensharing|Firefox screensharing]] section above. For example, an ''autostart'' section in your Sway {{Path|config}} file may include:
<pre>
<pre>
<layout>
exec /usr/libexec/xdg-desktop-portal-gtk
      <configItem>
exec /usr/libexec/xdg-desktop-portal-wlr
        <name>[the name of your layout, same as the name of the file in /usr/share/X11/xkb/symbols]</name>
exec /usr/libexec/xdg-desktop-portal-gnome
        <shortDescription>[usually just two letters]</shortDescription>
        <description>[description of your layout]</description>
        <countryList>
          <iso3166Id>US</iso3166Id>
          <iso3166Id>NO</iso3166Id>
        </countryList>
        <languageList>
          <iso639Id>eng</iso639Id>
        </languageList>
      </configItem>
    </layout>
<!--[other layouts]-->
</pre>
</pre>
Then, to enable for all keyboards, navigate to the input section of ''~/.config/sway/config'' and modify it to
 
<pre>
These instructions are only needed if these backends are not started automatically via other means.
input * {
  xkb_layout "my_layout"
}
</pre>
If you have enabled <code>xkb_numlock</code>, include this setting inside those braces as well.


== Troubleshooting ==
== Troubleshooting ==


If you encounter any issues, try running <code>sway -Vc /etc/sway/config</code>. 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).  
If you encounter any issues, try running <Code>sway -Vc /etc/sway/config</Code>. It will run <Code>sway</Code> with the default config file and set the output to be more verbose. It is generally a good idea to track your configuration files with ''git'' (if and when 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 <code>sway</code> in your startup file by:
 
sway -d 2> ~/sway_error.log
 
Alternatively, you can also issue the below command from TTY.
 
{{Cmd|$ sway -d 2> ~/sway_error.log}}
 
=== Video Driver Issues ===
 
After installing Sway, and while launching it for the first time, a lack of appropriate [[#Install Graphics Drivers|video drivers]] may cause various error messages such as:
 
* "unable to create backend"
* "Failed to create renderer"
 
Install the necessary drivers in order for your [[#Install Graphics Drivers|graphics card]] to work with Sway.
 
=== XDG_RUNTIME_DIR is not set in the environment. Aborting ===
 
If [[seatd]] is used instead of [[elogind]], the error message '''XDG_RUNTIME_DIR is not set in the environment. Aborting''' might be encountered.
 
Ensure that the mandatory steps outlined in the [[Seatd]] wiki page are completed in order to set the [[XDG_RUNTIME_DIR]] variable.
 
=== No backend was able to open a seat ===
 
If no [[seat manager]] is available, then the error below will appear.
 
<Pre>
[libseat] [libseat/libseat.c:73] libseat_open_seat : No backend was able to open a seat
[backend/session/libseat.c:102] Unable to create seat : Function not implemented
[backend/backend.c:303] Failed to open any DRM device
[sway/server.c:49] Unable to create backend
</Pre>
 
Ensure that either [[Elogind]] or [[Seatd]] is properly configured and running.
 
=== Firefox (Flatpak) and/or GTK Apps ===
 
==== Disappearing Cursor ====


=== Firefox (Flatpak) and/or GTK apps ===
You may need to get an icon pack and possibly a theme from [https://www.pling.com/browse?cat=107&ord=latest Pling store] and set <code>GTK_THEME</code> environmental variable. Alternatively, one could install an [https://pkgs.alpinelinux.org/packages?name=*-icon-theme&branch=edge&repo=&arch=x86_64&origin=&flagged=&maintainer= icon theme] package for all users.
==== Disappearing cursor ====
You may need to get an icon pack and possibly a theme from [https://www.pling.com/browse?cat=107&ord=latest Pling store] and set <code>GTK_THEME</code> environmental variable. Alternatively you can install a theme      for all users (search [https://pkgs.alpinelinux.org/ Alpine Linux Packages] for ''*-icon-theme'') using <code>apk add</code>.


==== Missing file picker/cannot download ====
==== Missing file picker/cannot download ====
Line 314: Line 334:
Go to ''about:config'' and set <code>widget.use-xdg-desktop-portal.file-picker</code> to 0.
Go to ''about:config'' and set <code>widget.use-xdg-desktop-portal.file-picker</code> to 0.


=== Failing to start under certain graphics cards/multiple wlroots stacked windows spawning upon start ===
=== Nvidia Issues ===
As of Dec 31 2022, [https://developer.nvidia.com/docs/drive/drive-os/latest/linux/sdk/common/topics/window_system_stub/Gnome-WaylandDesktopShellSupport136.html 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 <code>drm,libinput</code> or <code>x11</code> (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''').


=== Sway socket not detected ===
{{Draft|This section is partly outdated and could benefit from contributions in view of Nvidia's [https://docs.nvidia.com/drive/drive-os-5.2.3.0L/drive-os/index.html#page/DRIVE_OS_Linux_SDK_Development_Guide/Windows%20Systems/window_system_wayland.html current support] of Wayland. Help is encouraged.}}
{{Main|NVIDIA}}
As of Dec 31 2022, [https://developer.nvidia.com/docs/drive/drive-os/latest/linux/sdk/common/topics/window_system_stub/Gnome-WaylandDesktopShellSupport136.html Nvidia still doesn't fully support Wayland]. Therefore, the possible solutions are as outlined in the link, or setting your <Code>WLR_BACKENDS</Code> environmental variables to <code>drm,libinput</code> or <code>x11</code> (add {{Pkg|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 {{Pkg|libinput}} first''').


See [[Sway#Installation|Installation]] for instructions on how to set this environmental variable. This issue may occur with terminal multiplexers, such as [[Tmux terminal multiplexer|tmux]]
== See also ==


=== Steam games launched via Proton crash before creating a window ===
* [https://github.com/swaywm/sway/wiki/ Sway Wiki]
* [https://wiki.archlinux.org/title/Sway Archwiki]
* [https://wiki.gentoo.org/wiki/Sway Gentoo Wiki]
* [https://wiki.postmarketos.org/wiki/Sway PostmarketOS Wiki]


Instead of just using the in-Steam menu to install and select a Proton version, try installing the flatpak community build for Proton onto your system. There are several versions, depending on your desired stability, and the experimental version available in Flathub is called "com.valvesoftware.Steam.CompatibilityTool.Proton-Exp". After you install your chosen version, go into Steam to specify compatibility tool for a game as usual. The installed community build will now be an option. Select that and try launching the game again.
[[Category:Compositor]]
[[Category:Desktop]]

Latest revision as of 01:40, 24 August 2025

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.

Prerequisites

Tip: Except for the first two prerequisites, all of the others are automatically handled if the desktop is installed using the following setup-desktop script.

Setup-desktop

The setup-desktop command automates the Sway desktop installation with eudev and elogind.

# setup-desktop sway

Proceed to the Starting Sway section, as no display manager is being installed nor configured by the script that would boot into a graphical login screen.

Manual Installation

The installation steps below allow you to pick and choose various components for your Sway desktop.

Install Fonts

Install DejaVu fonts (font-dejavu), which have good Unicode coverage:

# apk add font-dejavu

Install Sway

# apk add sway \ xwayland \ # if you need the xserver foot \ # default terminal emulator. Modify $term in config for a different one. wmenu \ # default Wayland native menu for choosing program and screensharing monitor swaylock swaylockd \ # lockscreen tool swaybg \ # display wallpaper grim \ # screenshot tool wl-clipboard \ # clipboard management i3status \ # simple status bar swayidle # idle management (DPMS) daemon

For complimentary software alternatives, see Sway's wiki or Gentoo's wiki.

Starting Sway

Manually Launch Sway

You can launch Sway manually by issuing the sway command from a TTY.

$ sway

Tip: When using Wayland, for PipeWire and screensharing to work in Firefox and Chromium, a D-Bus is required. In the absence of a user service manager, consider running sway with dbus-run-session, a convenient wrapper that will explicitly export the path of the session bus.

$ dbus-run-session sway

Automatically Launch Sway on tty1

Adding the following lines to ~/.profile or to its equivalent will ensure that sway launches automatically, with a D-Bus, only from tty1. This is handy for troubleshooting, because if the Sway configuration ever falters, one could troubleshoot by logging into a different TTY (tty2-tty6), and your startup script then will not attempt to launch the faulty Sway environment from there also.

Contents of ~/.profile

... if [ "$(tty)" = "/dev/tty1" ]; then exec dbus-run-session sway fi ...

Using a Wrapper Script to Launch Sway

Instead of using ~/.profile or its equivalent file, a wrapper script can be placed at /usr/local/bin/sway-run. This script can be used to launch sway from either a TTY or by greetd, a lightweight display manager, as follows:

Contents of /usr/local/bin/sway-run

#!/bin/sh # Session export XDG_SESSION_TYPE=wayland export XDG_SESSION_DESKTOP=sway export XDG_CURRENT_DESKTOP=sway # Wayland stuff export MOZ_ENABLE_WAYLAND=1 export QT_QPA_PLATFORM=wayland export SDL_VIDEODRIVER=wayland export _JAVA_AWT_WM_NONREPARENTING=1 # Launch Sway with a D-Bus server exec dbus-run-session sway "$@"

Make the file executable:

# chmod +x /usr/local/bin/sway-run

Configuration

Sway config File

Copy the default Sway configuration file to ~/.config/sway/config so that it can be customized as per each user's choices:

$ mkdir -p ~/.config/sway $ cp /etc/sway/config ~/.config/sway/

Read through it to learn the default keybindings. Sway's configuration is mostly backward compatible with that of i3's, and if you are looking for a solution for a specific issue, you could try checking whether it hasn't been provided for the i3 window manager.

For additional information, start at man 5 sway and read the upstream wiki.

PipeWire and Screensharing

The Sway compositor has no involvement with audio playback. In order for screensharing to work, PipeWire is required. Therefore, installing PipeWire is recommended for audio playback too.

Since v3.22, Alpine Linux provides the necessary scripts to start PipeWire as a user service in OpenRC. Alternatively, PipeWire can be launched with Sway by adding the following line to Sway's config file:

exec /usr/libexec/pipewire-launcher

From a screensharing perspective, applications are split into two categories:-

  • Those which use the native Wayland wlr-screencopy protocol
  • 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 include Firefox and Chromium) require setting up xdg portals in addition to PipeWire.

# apk add xdg-desktop-portal xdg-desktop-portal-wlr

If you are using a dbus-run-session wrapper to launch Sway, you will also need to set D-Bus variables in order for the portal and for screensharing features to work; add the following line to the beginning of Sway's config file:

exec dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway

Screen Lock and suspend-to-RAM

Tip: For a seat manager-agnostic and DE-/WM-agnostic tool, consider installing the zzz utility, available in the community repository, or the powerctl utility from the testing repository, in order to manage suspend and hibernation.

Putting the system to sleep with the loginctl suspend command from Elogind requires elevated privileges or additional configuration.

To put the system to sleep after 600 seconds, use:

exec swayidle -w timeout 600 'doas /bin/loginctl suspend'

Do not lock the screen if program is running in full screen:

for_window [app_id="^.*"] inhibit_idle fullscreen
Todo: The option below, related to wayland-pipewire-idle-inhibit, needs to be tested. If you find the option below to be working, please remove this Todo.


If you do not want to lock the screen while media is being played through PipeWire, then install the wayland-pipewire-idle-inhibit package, and add the following to Sway's config file:

exec wayland-pipewire-idle-inhibit

Make changes to the ~/.config/wayland-pipewire-idle-inhibit/config.toml configuration file or to whichever configuration file you may have referenced instead through the --config <PATH>, if required, as per the project's website.

Elogind and swayidle

swayidle has integration with elogind, and it can handle before-sleep events.

If using swayidle before-sleep, then there will be a race condition, so that when you resume the computer from suspend, the screen will show 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 the /etc/elogind/system-sleep/10-swaylock.sh file, and then add the following script to this file:

Contents of /etc/elogind/system-sleep/10-swaylock.sh

#!/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 its 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 to Backlight for information on brightness control.

Output Scaling for High Resolution Displays

Without further configuration, program interfaces may 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 both to the performance impact and to 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 toolkit scaling is recommended. See See below.

Scaling with wdisplays

To enable Sway scaling, the user can first preview different scaling factors with the 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 the following line, completed with your settings, to Sway's config file.

output <name> scale <factor>

Toolkit Scaling

To use toolkit scaling, say, at x2, add the following, for instance, to your ~/.profile:

# for GTK-based programs such as firefox and emacs:
export GDK_DPI_SCALE=2
# for QT-based programs
export QT_WAYLAND_FORCE_DPI="physical"
# or if still too small, use a custom DPI
export QT_WAYLAND_FORCE_DPI=192 # 2x scaling
export QT_QPA_PLATFORM="wayland-egl"

Notification Daemon

mako is a lightweight notification daemon that works seamlessly with Sway.

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 Sway's wiki article for a listing of further screenshot tools.

Make Clipboard Content Persistent

By default, the clipboard content does not persist after terminating the program: if you copy some text from Firefox and then exit Firefox, then the copied text is also lost.

Install clipman from the community repo, and then add the following to Sway's 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 configuration 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 the following 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 the 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 configuration does not result in change, try logging out and in.

Note: Wayland allows for client-side cursors. It is possible that applications do not evaluate the values of $XCURSOR_SIZE and $XCURSOR_THEME.

Custom Keyboard Layout

To use a custom keyboard layout, just use:

input type:keyboard {
  xkb_file /path/to/my/custom/layout
}

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 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 similar to those shown in the Firefox screensharing section above. For example, an autostart section in 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

These instructions are only needed if these backends are not started automatically via other means.

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 configuration files with git (if and when 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

Alternatively, you can also issue the below command from TTY.

$ sway -d 2> ~/sway_error.log

Video Driver Issues

After installing Sway, and while launching it for the first time, a lack of appropriate video drivers may cause various error messages such as:

  • "unable to create backend"
  • "Failed to create renderer"

Install the necessary drivers in order for your graphics card to work with Sway.

XDG_RUNTIME_DIR is not set in the environment. Aborting

If seatd is used instead of elogind, the error message XDG_RUNTIME_DIR is not set in the environment. Aborting might be encountered.

Ensure that the mandatory steps outlined in the Seatd wiki page are completed in order to set the XDG_RUNTIME_DIR variable.

No backend was able to open a seat

If no seat manager is available, then the error below will appear.

[libseat] [libseat/libseat.c:73] libseat_open_seat : No backend was able to open a seat
[backend/session/libseat.c:102] Unable to create seat : Function not implemented
[backend/backend.c:303] Failed to open any DRM device
[sway/server.c:49] Unable to create backend

Ensure that either Elogind or Seatd is properly configured and running.

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, one could install an icon theme package for all users.

Missing file picker/cannot download

Go to about:config and set widget.use-xdg-desktop-portal.file-picker to 0.

Nvidia Issues

This material is work-in-progress ...

This section is partly outdated and could benefit from contributions in view of Nvidia's current support of Wayland. Help is encouraged.
(Last edited by John3-16 on 24 Aug 2025.)


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