Sway: Difference between revisions

From Alpine Linux
m (Steam stuff moved to Steam article.)
(add details about seatd, elogind and optional greeter)
Line 1: Line 1:
[https://swaywm.org Sway] is a tiling [[Wayland]] compositor. It's a drop-in replacement for the i3 window manager.
Install and configure Sway


== Installation ==
== Install Graphics Drivers ==
 
{{:Include:Setup_Device_Manager}}


Graphics drivers:
Graphics drivers:
Line 11: Line 9:
* [[Nvidia Video]]
* [[Nvidia Video]]


Adding your user account to the <code>input</code> and <code>video</code> groups is not required and discouraged by upstream. Sway will obtain access to input and video devices via <code>seatd</code> or <code>elogind</code>, whichever is available.
== Add a normal user ==
 
Use <code>setup-user</code> to add a non-system normal user for running Sway.
 
== Install seatd ==
 
Install seatd, a minimal seat management daemon.  This grants the required permissions to the user running sway:
 
apk add seatd
 
# add seatd to boot run-level, because it must be running before greetd
rc-update add seatd boot
 
rc-service seatd start
adduser $USER seat
 
== Install elogind (optional) ==
 
elogind is used to enable suspend-to-RAM with swayidle:
 
apk add elogind
rc-update add elogind
rc-service elogind start
 
== Set up eudev ==
 
[[eudev]] is recommended and required for the greeter. Or else it will not be able to find any input device (libinput failure).
 
setup-devd udev
 
== Install greetd (optional) ==
 
greetd is used to set [[Wayland#XDG_RUNTIME_DIR|XDG_RUNTIME_DIR]] and properly configure seat:
 
apk add greetd greetd-gtkgreet cage greetd-openrc
rc-update add greetd
adduser greetd seat
 
In <code>/etc/greetd/config.toml</code>, set
 
<pre>
[default_session]
 
command = "cage -s -- gtkgreet"
</pre>
 
In <code>/etc/greetd/environments</code>, set
<pre>
# Launch Sway with a D-Bus server available, use:
dbus-run-session -- sway
</pre>
 
We need to run sway with <code>dbus-run-session</code>, this is needed for PipeWire and screensharing in Firefox and Chromium.
 
== Install doas ==
Doas is used to grant permissions for suspend-to-RAM and brightness control with brightnessctl:
 
apk add doas brightnessctl
# optionally, allow $USER root access with password
adduser $USER wheel
 
In <code>/etc/doas.conf</code>, set
 
permit :wheel
permit nopass $USER as root cmd /bin/loginctl
permit nopass $USER as root cmd /usr/bin/brightnessctl
 
After setting the above, suspend-to-RAM can be triggered by running
 
/bin/loginctl suspend
 
(use full path to executable) and brightness can be adjusted by running
 
/usr/bin/brightnessctl set 100


Install some TTF fonts:
== Install fonts ==


{{Cmd|# apk add font-dejavu}}
Install DejaVu fonts, which has good Unicode coverage:


seatd daemon:
apk add font-dejavu


{{Cmd|# apk add seatd
== Install PipeWire, WirePlumber and XDG portals ==
<nowiki>#</nowiki> rc-update add seatd
 
<nowiki>#</nowiki> rc-service seatd start
For a reasonable desktop experience with support for audio and screensharing, install pipewire, wireplumber and xdg portals:
<nowiki>#</nowiki> adduser $USER seat
 
}}
apk add pipewire pipewire-pulse pipewire-tools
apk add wireplumber
apk add xdg-desktop-portal xdg-desktop-portal-wlr
 
Later, we need to launch PipeWire with Sway and configure several environment variables.


Install sway:
== Install Sway ==


{{Cmd|# apk add sway
apk add sway \
<nowiki>#</nowiki> apk add                \ # Install optional dependencies:
     xwayland            \ # if you need xserver
     xwayland            \ # recommended for compatibility reasons
     foot                \ # default terminal emulator. Modify $term in config for a different one.
     foot                \ # default terminal emulator. Modify $term in config for a different one.
     bemenu              \ # wayland menu
     bemenu              \ # wayland native menu for choosing program and screensharing monitor
     swaylock swaylockd  \ # lockscreen tool
     swaylock swaylockd  \ # lockscreen tool
     swaybg              \ # wallpaper daemon
     grim                \ # screenshot tool
    wl-clipboard        \ # clipboard management
    i3status            \ # simple status bar
     swayidle              # idle management (DPMS) 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.]
For complimentary software alternatives, see for example [https://wiki.gentoo.org/wiki/List_of_software_for_Wayland this list at Gentoo Wiki.]


Configure [[Wayland#XDG_RUNTIME_DIR|XDG_RUNTIME_DIR]].
== Configuration ==


== Usage ==
Copy default sway configuration to <code>~/.config</code>:


Applications such as Firefox or Chromium use Pipewire for screencasting. This requires installing [[D-Bus]] and [[PipeWire]] and running both as part of the user session. The <code>SWAYSOCK</code> environmental variable also needs to be set for Pipewire to the value exported by <code>sway</code>.
  # as normal user
mkdir -p ~/.config/sway
  cp /etc/sway/config ~/.config/sway/


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


Launch Sway with a D-Bus server available, use:
For additional information, start at <code>man 5 sway</code> and read the [https://github.com/swaywm/sway/wiki upstream wiki].


{{Cmd|dbus-run-session -- sway #prepend with exec in your login shell init script}}
== Launch PipeWire and enable screensharing ==
Launch PipeWire with Sway, add the following to sway config:


== Configuration ==
exec /usr/libexec/pipewire-launcher


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.
You also need to set DBus variables for the portal and screensharing features to work:
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].
exec dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway


=== Firefox screensharing ===
Replace dmenu (depends on X server) with bemenu (Wayland native) for launching programs and selecting which screen to share in Firefox/Chromium:


For some programs, additional configuration is needed to launch them natively under Wayland and to support special features such as screen sharing.
set $menu dmenu_path | bemenu | xargs swaymsg exec --


To launch Firefox natively under Wayland and to enable support for screensharing, you need:
== Mouse cursor theme ==


* Install and configure [[PipeWire]]
Set a mouse cursor, using GNOME Adwaita theme:
* Install xdg-desktop-portal and xdg-desktop-portal-wlr package
* Install wofi for screen selection
* Launch pipewire on sway startup:
<pre>
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"
seat "*" xcursor_theme Adwaita 16
export XDG_CURRENT_DESKTOP{{=}}sway
export QT_QPA_PLATFORM{{=}}"wayland-egl"
}}


=== Flatpaks ===
== Screen lock and suspend-to-RAM ==


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.
Set screen lock and suspend-to-RAM:


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 swayidle -w \
<pre>
          timeout 300 'swaylock --daemonize' \
exec /usr/libexec/xdg-desktop-portal-gtk
          timeout 330 'doas /bin/loginctl suspend' \
exec /usr/libexec/xdg-desktop-portal-wlr
          before-sleep 'swaylock --daemonize'
exec /usr/libexec/xdg-desktop-portal-gnome
</pre>


This is only needed if they are not started automatically via other means.
Do not lock the screen if program is running in full screen:


=== Scaling for high resolution screens ===
for_window [app_id="^.*"] inhibit_idle fullscreen


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 116: Line 178:
to ~/.config/sway/config.
to ~/.config/sway/config.


==== Via GTK/Qt ====
To use toolkit scaling, use
 
{{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 128: Line 189:
}}
}}


=== Make clipboard content persistent ===
== 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.
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.


Line 138: Line 199:
</pre>
</pre>


=== Firefox picture-in-picture mode/floating windows ===
== 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):
Add this to your sway config file (modify the numeric values to suit your needs and your display):
<pre>
<pre>
Line 144: Line 205:
</pre>
</pre>


=== Screenshots ===
== 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 155: Line 216:
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 ===
== Start with NumLock enabled ==
Add this to your sway config file:
Add this to your sway config file:
<code>input type:keyboard xkb_numlock enabled</code>
<code>input type:keyboard xkb_numlock enabled</code>


=== Change cursor theme and size ===
== Change cursor theme and size ==
Add to your sway config:
Add to your sway config:
<pre>
<pre>
Line 167: Line 228:
{{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>.}}
{{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 ===
Although this is not necessary, you may write an init script like the following:
{{Cat|/etc/init.d/sway|#!/sbin/openrc-run
description{{=}}"Sway Compositor"
command{{=}}"/usr/bin/sway"
command_user{{=}}"$USER"
command_args{{=}}""
pidfile{{=}}"/run/sway.pid"
start_stop_daemon_args{{=}}"--background --pidfile ${pidfile}"
depend() {
  need localmount
  after elogind
  use seatd dbus
}
}}
Replace <code>$USER</code> with your user name.
Then run
{{Cmd|# chmod +x /etc/init.d/sway}}
and
{{Cmd|# rc-update add sway default}}
Make sure you have {{Pkg|elogind}} installed or specify another service, like your display/login manager after which the sway service will run.


=== 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>:
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>:
Line 228: Line 256:
</pre>
</pre>
If you have enabled <code>xkb_numlock</code>, include this setting inside those braces as well.
If you have enabled <code>xkb_numlock</code>, include this setting inside those braces as well.
== Default font ==
This is not related to Sway, but still nice to have: change system wide default font selection.  In <code>/etc/fonts/conf.d/52-my-default-fonts.conf</code>, set
<pre>
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
<fontconfig>
  <!-- Default fonts -->
  <alias binding="same">
    <family>sans-serif</family>
    <prefer>
      <family>DejaVu Sans</family>
    </prefer>
  </alias>
  <alias binding="same">
    <family>serif</family>
    <prefer>
      <family>DejaVu Serif</family>
    </prefer>
  </alias>
  <alias binding="same">
    <family>monospace</family>
    <prefer>
      <family>DejaVu Sans Mono</family>
    </prefer>
  </alias>
</fontconfig>
</pre>
You can obtain a list of installed fonts with <code>fc-list</code>.


== Troubleshooting ==
== Troubleshooting ==
Line 233: Line 292:
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).  


=== Firefox (Flatpak) and/or GTK apps ===
== Flatpaks ==
==== Disappearing cursor ====
 
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.
 
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:
<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.
 
== Firefox (Flatpak) and/or GTK apps ==
=== 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 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 ===


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 ===
== Failing to start under certain graphics cards/multiple wlroots stacked windows spawning upon start ==
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 ===
== Sway socket not detected ==


See [[Sway#Installation|Installation]] for instructions on how to set this environmental variable. This issue may occur with terminal multiplexers, such as [[tmux]]
See [[Sway#Installation|Installation]] for instructions on how to set this environmental variable. This issue may occur with terminal multiplexers, such as [[tmux]]
== See Also ==
* [https://wiki.archlinux.org/title/Sway Archwiki]
* [https://wiki.gentoo.org/wiki/Sway Gentoo Wiki]
* [https://wiki.postmarketos.org/wiki/Sway PostmarketOS Wiki]
[[Category:Desktop]]
[[Category:Window Managers]]
[[Category:Wayland]]

Revision as of 23:14, 19 February 2024

Install and configure Sway

Install Graphics Drivers

Graphics drivers:

Add a normal user

Use setup-user to add a non-system normal user for running Sway.

Install seatd

Install seatd, a minimal seat management daemon. This grants the required permissions to the user running sway:

apk add seatd
# add seatd to boot run-level, because it must be running before greetd
rc-update add seatd boot
rc-service seatd start
adduser $USER seat

Install elogind (optional)

elogind is used to enable suspend-to-RAM with swayidle:

apk add elogind
rc-update add elogind
rc-service elogind start

Set up eudev

eudev is recommended and required for the greeter. Or else it will not be able to find any input device (libinput failure).

setup-devd udev

Install greetd (optional)

greetd is used to set XDG_RUNTIME_DIR and properly configure seat:

apk add greetd greetd-gtkgreet cage greetd-openrc
rc-update add greetd
adduser greetd seat

In /etc/greetd/config.toml, set

[default_session]

command = "cage -s -- gtkgreet"

In /etc/greetd/environments, set

# Launch Sway with a D-Bus server available, use:
dbus-run-session -- sway

We need to run sway with dbus-run-session, this is needed for PipeWire and screensharing in Firefox and Chromium.

Install doas

Doas is used to grant permissions for suspend-to-RAM and brightness control with brightnessctl:

apk add doas brightnessctl
# optionally, allow $USER root access with password
adduser $USER wheel

In /etc/doas.conf, set

permit :wheel
permit nopass $USER as root cmd /bin/loginctl
permit nopass $USER as root cmd /usr/bin/brightnessctl

After setting the above, suspend-to-RAM can be triggered by running

/bin/loginctl suspend

(use full path to executable) and brightness can be adjusted by running

/usr/bin/brightnessctl set 100

Install fonts

Install DejaVu fonts, which has good Unicode coverage:

apk add font-dejavu

Install PipeWire, WirePlumber and XDG portals

For a reasonable desktop experience with support for audio and screensharing, install pipewire, wireplumber and xdg portals:

apk add pipewire pipewire-pulse pipewire-tools
apk add wireplumber
apk add xdg-desktop-portal xdg-desktop-portal-wlr

Later, we need to launch PipeWire with Sway and configure several environment variables.

Install Sway

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

For complimentary software alternatives, see for example this list at Gentoo Wiki.

Configuration

Copy default sway configuration to ~/.config:

# as normal 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.

Launch PipeWire and enable screensharing

Launch PipeWire with Sway, add the following to sway config:

exec /usr/libexec/pipewire-launcher

You also need to set DBus variables for the portal and screensharing features to work:

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

Replace dmenu (depends on X server) with bemenu (Wayland native) for launching programs and selecting which screen to share in Firefox/Chromium:

set $menu dmenu_path | bemenu | xargs swaymsg exec --

Mouse cursor theme

Set a mouse cursor, using GNOME Adwaita theme:

seat "*" xcursor_theme Adwaita 16

Screen lock and suspend-to-RAM

Set screen lock and suspend-to-RAM:

exec swayidle -w \
         timeout 300 'swaylock --daemonize' \
         timeout 330 'doas /bin/loginctl suspend' \
         before-sleep 'swaylock --daemonize'

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

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

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

output <name> scale <factor>

to ~/.config/sway/config.

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"

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:

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

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.

Start with NumLock enabled

Add this to your sway config file: input type:keyboard xkb_numlock enabled

Change cursor theme and size

Add to your sway config:

seat seat0 xcursor_theme my_cursor_theme my_cursor_size

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 uses client-side cursors. It is possible that applications do not evaluate the values of $XCURSOR_SIZE and $XCURSOR_THEME.


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 </modelList> and after <layoutList>:

<layout>
      <configItem>
        <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]-->

Then, to enable for all keyboards, navigate to the input section of ~/.config/sway/config and modify it to

input * {
  xkb_layout "my_layout" 
}

If you have enabled xkb_numlock, include this setting inside those braces as well.

Default font

This is not related to Sway, but still nice to have: change system wide default font selection. In /etc/fonts/conf.d/52-my-default-fonts.conf, set

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
<fontconfig>
  <!-- Default fonts -->
  <alias binding="same">
    <family>sans-serif</family>
    <prefer>
      <family>DejaVu Sans</family>
    </prefer>
  </alias>
  <alias binding="same">
    <family>serif</family>
    <prefer>
      <family>DejaVu Serif</family>
    </prefer>
  </alias>
  <alias binding="same">
    <family>monospace</family>
    <prefer>
      <family>DejaVu Sans Mono</family>
    </prefer>
  </alias>
</fontconfig>

You can obtain a list of installed fonts with fc-list.


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

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.

Failing to start under certain graphics cards/multiple wlroots stacked windows spawning upon start

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

Sway socket not detected

See Installation for instructions on how to set this environmental variable. This issue may occur with terminal multiplexers, such as tmux