Sway: Difference between revisions

From Alpine Linux
(→‎Steam games launched via Proton crash before creating a window: mention proton-ge with a disclaimer that it'll only work with nix, with a warning on potential privacy risks, with a link to steam's TOSDR)
(removed the LIBSEAT_BACKEND variable)
 
(129 intermediate revisions by 6 users not shown)
Line 1: Line 1:
[https://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.


== Installation ==
== Prerequisites ==


{{:Include:Setup_Device_Manager}}
* Internet [[Configure_Networking#Connectivity_testing|connectivity]], unless the packages have been pre-fetched into a local cache.
* A [[Setting_up_a_new_user#Creating_a_new_user|non-root user account]].
* The [[Repositories#Managing_repositories|community repositories must be enabled]].
* Install appropriate [[Graphics driver]] drivers for your hardware. Without graphics drivers [[#Video Driver Issues|errors]] are likely to occur.
* 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.


Graphics drivers:
== Setup-desktop ==


* [[Intel Video]]
The [[setup-desktop]] command automates the installation of a basic desktop setup.
* [[Radeon Video]]
* [[Nvidia Video]]
Add user to the input and video groups:


{{Cmd|# adduser $USER input
== Manual Installation ==
<nowiki>#</nowiki> adduser $USER video
 
}}
The below installation step allows you to pick and choose various componenents for your Sway Desktop.
 
=== Install fonts ===
 
Install DejaVu fonts, which has good Unicode coverage:
{{cmd|# apk add font-dejavu}} 
=== Install Sway ===


{{cmd|# apk add sway \
    xwayland            \ # if you need 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
}}


Install some TTF fonts:
For complimentary software alternatives, see [https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway sway wiki] or [https://wiki.gentoo.org/wiki/List_of_software_for_Wayland Gentoo Wiki.]


{{Cmd|# apk add font-dejavu}}
== Starting sway ==


seatd daemon:
=== Manually launch sway ===


{{Cmd|# apk add seatd
You can launch <Code>sway</Code> manually by issuing the command sway from TTY. {{Cmd|$ sway}}  
<nowiki>#</nowiki> rc-update add seatd
<nowiki>#</nowiki> rc-service seatd start
<nowiki>#</nowiki> adduser $USER seat
}}


Install sway:
{{Tip|When using [[Wayland]], for PipeWire and screensharing to work in Firefox and Chromium, [[D-Bus]] is required. In the absence of a user service manager, consider running with <code>dbus-run-session</code>, a convenience wrapper that will explicitly export the path of the session bus.}}


{{Cmd|# apk add sway
=== Automatically launch sway on tty1 ===
<nowiki>#</nowiki> 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
}}


For complimentary software alternatives, see for example [https://wiki.gentoo.org/wiki/List_of_software_for_Wayland this list at Gentoo Wiki.]
Adding the following lines to {{Path|~/.profile}} or other shell specific profile file will launch Sway automatically with [[D-Bus]] only in tty1. {{Cat| ~/.profile|<nowiki>...
if [ "$(tty)" = "/dev/tty1" ]; then
    exec dbus-run-session sway
fi
...</nowiki>}}


Configure [[Wayland#XDG_RUNTIME_DIR|XDG_RUNTIME_DIR]].
=== Use Wrapper script to launch sway ===


== Usage ==
Instead of using {{Path|~/.profile}} or it's 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 both TTY and [[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


For inter-program communication and functionality such as screensharing, install and enable [[D-Bus]] 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.
# 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 available, use:
# Launch Sway with a D-Bus server
exec dbus-run-session sway "$@" </nowiki>}}


{{Cmd|dbus-run-session -- sway #prepend with exec in your login shell init script}}
Make the file executable: {{Codeline|<Code># chmod +x /usr/local/bin/sway-run</Code>}}


== Configuration ==
== Configuration ==


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.
===Sway config file ===
Copy default sway configuration file to {{Path|~/.config/sway/config}} so that it can be customized per user:{{cmd|$ mkdir -p ~/.config/sway
$ cp /etc/sway/config ~/.config/sway/}}
 
Read through it to learn the default keybindings.
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.
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].
For additional information, start at <code>man 5 sway</code> and read the [https://github.com/swaywm/sway/wiki upstream wiki].


=== Firefox screensharing ===
=== PipeWire and Screensharing ===
 
The sway compositor has no involvement in audio playback. For screen sharing to work pipewire is needed. So installing [[PipeWire#Installation|PipeWire]] is recommended for audio playback too.
 
Launch PipeWire with Sway by adding the following to sway [[#Sway config file|config]] file:
exec /usr/libexec/pipewire-launcher
 
From screensharing perspective, 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 <code>xdg-desktop-portal</code> (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#Installation|PipeWire]]. {{Cmd|#  apk add xdg-desktop-portal xdg-desktop-portal-wlr}}
 
If you are using <code>dbus-run-session</code> 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 [[#Sway config file|config]] file:
exec dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
 
=== Screen lock and suspend-to-RAM ===
 
{{Tip| For a seat manager and de/wm agnostic tools consider {{Pkg|zzz}} utility or {{Pkg|powerctl}} utility available in [[Repositories#Testing|testing]] repository to manage suspend and hibernation.}}
 
Putting the system to sleep with <Code>loginctl suspend </Code> 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 below option related to wayland-pipewire-idle-inhibit needs to be tested. If you find the below option working, please remove this todo.}}
If you do not want to lock the screen, when media is being played through [[PipeWire]], Install {{pkg|wayland-pipewire-idle-inhibit}} package and add the following to sway [[#Sway config file|config]] file:
exec wayland-pipewire-idle-inhibit
 
Make changes to the config file {{Path|~/.config/wayland-pipewire-idle-inhibit/config.toml}} if required, as per [https://github.com/rafaelrc7/wayland-pipewire-idle-inhibit?tab=readme-ov-file#config project website].
 
=== Elogind and swayidle ===
 
<code>swayidle</code> has integration with <code>elogind</code> and can handle <code>before-sleep</code> events.
 
If using <code>swayidle before-sleep</code>, 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.


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 this file <code>/etc/elogind/system-sleep/10-swaylock.sh</code>, then add the following script to this file:


* Install and configure [[PipeWire]]
#!/bin/sh
* Install xdg-desktop-portal and xdg-desktop-portal-wlr package
if [ "${1}" == "pre" ]; then
* Install wofi for screen selection
  touch /tmp/swaylock-sleep
* Launch pipewire on sway startup:
  sleep 1
<pre>
fi
exec /usr/libexec/pipewire-launcher
</pre>
* xdg-desktop-portal will start xdg-desktop-portal-wlr when needed, but needs a few environment variables. Unless <code>dbus-daemon</code> is a descendant of the <code>sway</code> process, add to the sway config:
<pre>
exec dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
</pre>
* Export the following variables:


{{Cmd|export MOZ_ENABLE_WAYLAND {{=}}"1"
Then set it to executable.
export XDG_CURRENT_DESKTOP{{=}}sway
export QT_QPA_PLATFORM{{=}}"wayland-egl"
}}


=== Flatpaks ===
Later, once sway is installed, add the following line to sway [[#Sway config file|config]] file:


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 [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.
exec touch /tmp/swaylock-sleep && inotifyd swaylock /tmp/swaylock-sleep


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:
With this line, the screen will be promptly locked before suspend-to-RAM starts.
<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.
=== Brightness control ===


=== Scaling for high resolution screens ===
Refer to [[Backlight]] for information on brightness control.


Without further configuration, program interfaces might be too small to use on high resolution screens.
=== Output scaling for high resolution displays ===


==== Via sway ====
Without further configuration, program interfaces might be too small to use on high resolution displays.


Sway supports the per-display configuration of
Sway supports the per-display configuration of
Line 110: Line 161:
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.
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 <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 <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 below to sway [[#Sway config file|config]] file.


<pre>
<pre>
Line 116: Line 167:
</pre>
</pre>


to ~/.config/sway/config.
To use toolkit scaling, use
 
==== Via GTK/Qt ====
 
{{Cmd|# for GTK-based programs such as firefox and emacs:
{{Cmd|# for GTK-based programs such as firefox and emacs:
export GDK_DPI_SCALE{{=}}2
export GDK_DPI_SCALE{{=}}2
Line 130: Line 178:
}}
}}


=== Make clipboard content persistent ===
=== Screenshots ===
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.
 
<strike>Install clipman from testing repo and add the following to sway config:</strike>
 
Unfortunately, the clipman project has been abandoned and deleted from GitHub. Use [https://github.com/sentriz/cliphist cliphist] instead, which is also available in the testing repository.
See [https://github.com/sentriz/cliphist#picker-examples picker examples] section on the project's page to add an appropriate keybinding line to your sway config.


<pre>
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 ===
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:
A simple tool that works well under Wayland is Grimshot. Example keybindings:
<pre>
<pre>
Line 160: Line 190:
See [https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway the sway wiki's article] for a list of screenshot tools.
See [https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway the sway wiki's article] for a list of screenshot tools.


=== Start with NumLock enabled ===
=== Make clipboard content persistent ===
Add this to your sway config file:
 
<code>input type:keyboard xkb_numlock enabled</code>
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 {{Pkg|clipman}} from testing repo and add the following to sway [[#Sway config file|config]] file:


=== 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:


{{Cat|/etc/init.d/sway|#!/sbin/openrc-run
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>


description{{=}}"Sway Compositor"
=== Start with NumLock enabled ===


command{{=}}"/usr/bin/sway"
Add this to your sway config file:
command_args{{=}}""


pidfile{{=}}"/run/sway.pid"
input type:keyboard xkb_numlock enabled


start_stop_daemon_args{{=}}"--background --pidfile ${pidfile}"
=== Change mouse cursor theme and size ===


depend() {
Add to your sway [[#Sway config file|config]] file:
  need localmount
  after elogind
  use seatd dbus
}
}}


Then run
seat seat0 xcursor_theme my_cursor_theme my_cursor_size


{{Cmd|# chmod +x /etc/init.d/sway}}
For example, set a mouse cursor, using GNOME Adwaita theme:


and
seat seat0 xcursor_theme Adwaita 16


{{Cmd|# rc-update add sway default}}
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.


Make sure you have {{Pkg|elogind}} installed or specify another service, like your display/login manager after which the sway service will run.
{{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>.}}


=== Custom keyboard layout ===
=== Custom keyboard layout ===


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>:
To use custom keyboard layout, just use
<pre>
<pre>
<layout>
input type:keyboard {
      <configItem>
  xkb_file /path/to/my/custom/layout
        <name>[the name of your layout, same as the name of the file in /usr/share/X11/xkb/symbols]</name>
}
        <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  
 
=== Flatpaks ===
{{main|Flatpak}}
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 [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 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 [[#Sway config file|config]] file may include:
<pre>
<pre>
input * {
exec /usr/libexec/xdg-desktop-portal-gtk
  xkb_layout "my_layout"
exec /usr/libexec/xdg-desktop-portal-wlr
}
exec /usr/libexec/xdg-desktop-portal-gnome
</pre>
</pre>
If you have enabled <code>xkb_numlock</code>, include this setting inside those braces as well.
 
This is only needed if they are not started automatically via other means.


== 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 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 <code>sway</code> in your startup file by
<code>sway -d 2> ~/sway_error.log</code>.
Alternately, you can also issue the below command from TTY.
{{cmd|$ sway -d 2> ~/sway_error.log}}
=== Video Driver Issues ===
After installing sway, while launching it for the first time, lack of proper [[#Install Graphics Drivers|video drivers]] causes various error messages such as:
* "unable to create backend"
* "Failed to create renderer"
Do install necessary drivers for your [[#Install Graphics Drivers|graphics card]] for sway to work.
=== 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 [[seatd]] page to set the [[XDG_RUNTIME_DIR]] variable is completed.
=== No backend was able to open a seat ===
If no [[seat manager]] is available, the below error 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 either [[Elogind]] or [[Seatd]] is properly configured and running.


=== Firefox (Flatpak) and/or GTK apps ===
=== Firefox (Flatpak) and/or GTK apps ===
==== Disappearing cursor ====
==== 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>.
 
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 [https://pkgs.alpinelinux.org/packages?name=*-icon-theme&branch=edge&repo=&arch=x86_64&origin=&flagged=&maintainer= icon theme] package for all users.


==== Missing file picker/cannot download ====
==== Missing file picker/cannot download ====
Line 243: Line 296:
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 ===
 
{{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 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''').
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 ===
== See also ==
 
See [[Sway#Installation|Installation]] for instructions on how to set this environmental variable. This issue may occur with terminal multiplexers, such as [[tmux]]
 
=== Steam games launched via Proton crash before creating a window ===
 
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.
 
As your last resort, you can try installing [https://github.com/GloriousEggroll/proton-ge-custom proton-ge-custom], but please note that in order for this to be even detected by Steam, you will need to install Steam via Nix due to high level of isolation that Flatpaks utilize. This can however come at the expense of your [https://tosdr.org/en/service/180 privacy].
 
== See Also ==


* [https://github.com/swaywm/sway/wiki/ Sway Wiki]
* [https://wiki.archlinux.org/title/Sway Archwiki]
* [https://wiki.archlinux.org/title/Sway Archwiki]
* [https://wiki.gentoo.org/wiki/Sway Gentoo Wiki]
* [https://wiki.postmarketos.org/wiki/Sway PostmarketOS Wiki]


[[Category:Compositor]]
[[Category:Desktop]]
[[Category:Desktop]]
[[Category:Window Managers]]
[[Category:Window Managers]]
[[Category:Wayland]]

Latest revision as of 03:37, 11 April 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

Setup-desktop

The setup-desktop command automates the installation of a basic desktop setup.

Manual Installation

The below installation step allows you to pick and choose various componenents for your Sway Desktop.

Install fonts

Install DejaVu fonts, which has good Unicode coverage:

# apk add font-dejavu

Install Sway

# apk add sway \ xwayland \ # if you need 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 wiki or Gentoo Wiki.

Starting sway

Manually launch sway

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

$ sway

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

Automatically launch sway on tty1

Adding the following lines to ~/.profile or other shell specific profile file will launch Sway automatically with D-Bus only in tty1.

Contents of ~/.profile

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

Use Wrapper script to launch sway

Instead of using ~/.profile or it's equivalent file, a wrapper script can be placed at /usr/local/bin/sway-run. This script can be used to launch sway from both TTY and 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 default sway configuration file to ~/.config/sway/config so that it can be customized per user:

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

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

The sway compositor has no involvement in audio playback. For screen sharing to work pipewire is needed. So installing PipeWire is recommended for audio playback too.

Launch PipeWire with Sway by adding the following to sway config file:

exec /usr/libexec/pipewire-launcher

From screensharing perspective, applications are split into two categories:

  • Those which use the native wayland protocol, wlr-screencopy
  • 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.

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

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

Tip: For a seat manager and de/wm agnostic tools consider zzz utility or powerctl utility available in testing repository to manage suspend and hibernation.

Putting the system to sleep with 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 below option related to wayland-pipewire-idle-inhibit needs to be tested. If you find the below option working, please remove this todo.


If you do not want to lock the screen, when media is being played through PipeWire, Install wayland-pipewire-idle-inhibit package and add the following to sway config file:

exec wayland-pipewire-idle-inhibit

Make changes to the config file ~/.config/wayland-pipewire-idle-inhibit/config.toml if required, as per project website.

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

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

# 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"

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 clipman 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.

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 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 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.

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.

$ sway -d 2> ~/sway_error.log

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.

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 seatd page to set the XDG_RUNTIME_DIR variable is completed.

No backend was able to open a seat

If no seat manager is available, the below error 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 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 you can Install a 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

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