Sway: Difference between revisions

From Alpine Linux
(→‎Installation: The value hardcoded here was okay for the author's setup, but will vary depending on XDG_RUNTIME_DIR.)
(→‎Install greetd (optional): link to greetd pahe)
 
(92 intermediate revisions by 13 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 i3 window manager for X11. It works with your existing i3 configuration and supports most of i3's features, plus a few extras.


== Installation ==
== Installation ==
=== Add a normal user ===


eudev:
Use <code>setup-user</code> to add a non-system normal user for running Sway.


<pre>
=== Set up eudev ===
# apk add eudev
 
# setup-devd udev
[[eudev]] is recommended and required for. Without it, sway cannot connect to input devices.
</pre>
 
setup-devd udev
 
=== Install Graphics Drivers ===


Graphics drivers:
Graphics drivers:
Line 15: Line 19:
* [[Radeon Video]]
* [[Radeon Video]]
* [[Nvidia Video]]
* [[Nvidia Video]]
Add user to the input and video groups:


<pre>
=== Setting up a seat manager ===
# adduser $USER input
 
# adduser $USER video
Wayland compositors need raw access to input and output devices. This is mediated by a [[seat manager]]. Using either [[seatd]] or [[elogind]] is supported. Using both may lead to conflicts.
</pre>
 
==== Install seatd ====
 
See [[Seatd]].
 
==== Install elogind ====
 
See [[Elogind]].
 
===== 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.
 
To solve this issue, do the following:
 
Create this file <code>/etc/elogind/system-sleep/10-swaylock.sh</code>, 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:
 
# in ~/.config/sway/config
exec touch /tmp/swaylock-sleep && inotifyd swaylock /tmp/swaylock-sleep
 
With this line, the screen will be promptly locked before suspend-to-RAM starts.
 
=== Install greetd (optional) ===
 
{{Box YELLOW|Note:|This content is tangential, and should be moved into the '[[greetd]]' page}}


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


Install some TTF fonts:
In <code>/etc/greetd/config.toml</code>, set


<pre>
<pre>
# apk add ttf-dejavu
[default_session]
 
command = "cage -s -- gtkgreet"
</pre>
</pre>


seatd daemon:
To use a graphical greeter with seatd add <code>rc_need=seatd</code> to <code>/etc/conf.d/greetd</code>.


In <code>/etc/greetd/environments</code>, set
<pre>
<pre>
# apk add seatd
# Launch Sway with a D-Bus server available, use:
# rc-update add seatd
dbus-run-session -- sway
# rc-service seatd start
# adduser $USER seat
</pre>
</pre>


[[elogind]], optional for suspending with a key (otherwise you can run <code>echo mem > /sys/power/state as a root</code>), or lid close support {{Note|Even though elogind may be installed and the service running, you may still need to configure some values. Otherwise you may for example be able to suspend with a key, but encounter a freeze upon waking. It is always vital to verify it is set up correctly with <code>loginctl list-sessions</code>}}
D-Bus is required for PipeWire and screensharing in Firefox and Chromium. Running with <code>dbus-run-session</code> is a convenience wrapper that will explicitly export the path of the session bus.
 
=== Install fonts ===
 
Install DejaVu fonts, which has good Unicode coverage:
 
apk add font-dejavu


Install sway:
=== Install Sway ===


<pre>
apk add sway \
# apk add sway sway-doc
     xwayland            \ # if you need xserver
# apk add                \ # Install optional dependencies:
     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
     wmenu                \ # default 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
</pre>


Configure [[Wayland#XDG_RUNTIME_DIR|XDG_RUNTIME_DIR]].
For complimentary software alternatives, see [https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway the relevant page from sway's wiki] or [https://wiki.gentoo.org/wiki/List_of_software_for_Wayland this list at Gentoo Wiki.]


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


Launch Sway with dbus support:
Copy default sway configuration to <code>~/.config</code>:


<pre>
# as normal user
dbus-run-session -- sway #prepend with exec in your login shell init script
mkdir -p ~/.config/sway
</pre>
cp /etc/sway/config ~/.config/sway/
 
== 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.
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 enable screensharing ==
 
For audio playback, either PipeWire or PulseAudio work fine. The compositor has no involvement in audio playback.
 
For screen sharing, applications are split into two categories:
 
* Those which use the native wayland protocol, </code>wlr-screencopy</code>
* Those which use the API from Flatpak's <code>xdg-desktop-portal</code> (this portal is also used by native non-Flatpak applications).
 
Applications in the first group require not additional setup. Applications in the second group (which includes Firefox and Chromium) require setting up pipewire, wireplumber and xdg portals:
 
{{Todo|Move this content into [[PipeWire]].}}
 
apk add pipewire pipewire-pulse pipewire-tools
apk add wireplumber
apk add xdg-desktop-portal xdg-desktop-portal-wlr
 
Launch PipeWire with Sway. Use your service manager of choice, or add the following to sway config:
 
exec /usr/libexec/pipewire-launcher
 
If your are using automatic D-Bus activation, 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
 
{{Box YELLOW|Unclear:|The following paragraph is unclear and needs further work}}
 
Replace dmenu (depends on X server) with bemenu (Wayland native) for launching programs and selecting which screen to share in Firefox/Chromium:
 
set $menu bemenu-run | xargs swaymsg exec
 
== Screen lock and suspend-to-RAM ==
 
=== Without elogind ===
 
Consider using {{Pkg|powerctl}}.
 
=== With elogind ===


For some programs, additional configuration is needed to launch them natively under Wayland and to support special features such as screen sharing.
Putting the system to sleep with elogind requires elevated privileges or additional configuration.


To launch Firefox natively under Wayland and to enable support for screensharing, you need:
For details on configuring <code>doas</code> with <code>elogind</code>, see [[Elogind#Doas]]


* Install and configure [[PipeWire]]
To put the system to sleep after 600 seconds, use:
* Install xdg-desktop-portal and xdg-desktop-portal-wlr package
 
* Install wofi for screen selection
exec swayidle -w timeout 600 'doas /bin/loginctl suspend'
* Launch support programs on sway startup:
 
<pre>
loginctl suspend command will trigger the screenlock, as mentioned in the section [[#Install elogind (optional)|Install elogind (optional)]] above.
exec /usr/libexec/pipewire-launcher #pipewire must be launched first
 
exec /usr/libexec/xdg-desktop-portal-wlr
Do not lock the screen if program is running in full screen:
</pre>
* Export the following variables:


<pre>
for_window [app_id="^.*"] inhibit_idle fullscreen
export MOZ_ENABLE_WAYLAND="1"
export XDG_CURRENT_DESKTOP=sway
export QT_QPA_PLATFORM="wayland-egl"
</pre>


=== Flatpaks ===
== Brightness control ==


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.
Controlling display backlight requires either the proper udev rules, or using some form of privilege escalation.


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:
{{Pkg|brightnessctl}} is a reliable alternative, although its default udev rules require too wide permissions (see {{Issue|15409}}). You may need your own rules, or configure doas to allow running it as an unprivileged user.
<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.
Optionally enable brightnessctl service to restore brightness settings on reboot:


=== Scaling for high resolution screens ===
rc-update add brightnessctl


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 126: Line 198:
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:
export GDK_DPI_SCALE{{=}}2
 
<nowiki>#</nowiki> for QT-based programs
export QT_WAYLAND_FORCE_DPI{{=}}"physical"
<nowiki>#</nowiki> 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:
<pre>
<pre>
# for GTK-based programs such as firefox and emacs:
bindsym Print exec grimshot copy area
export GDK_DPI_SCALE=2
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
</pre>
 
See [https://github.com/swaywm/sway/wiki/Useful-add-ons-for-sway the sway wiki's article] for a list of screenshot tools.


# for QT-based programs
== Tweaks ==
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"
</pre>


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


Install clipman from test repo and add the following to sway config:
Install clipman from testing repo and add the following to sway config:


<pre>
<pre>
Line 153: Line 237:
<pre>
<pre>
for_window [app_id="firefox" title="^Picture-in-Picture$"] floating enable, move position 877 450, sticky enable, border none
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>
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
</pre>
</pre>


Line 168: Line 243:
<code>input type:keyboard xkb_numlock enabled</code>
<code>input type:keyboard xkb_numlock enabled</code>


=== Change cursor theme and size ===
=== Change mouse cursor theme and size ===
Add to your sway config:
Add to your sway config:
<pre>
seat seat0 xcursor_theme my_cursor_theme my_cursor_size
</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 ===
seat seat0 xcursor_theme my_cursor_theme my_cursor_size
Although this is not necessary, you may write an init script like the following:
<pre>
{{/etc/init.d/sway|
#!/sbin/openrc-run


description="Sway Compositor"
For example, set a mouse cursor, using GNOME Adwaita theme:


command="/usr/bin/sway"
seat seat0 xcursor_theme Adwaita 16
command_args=""


pidfile="/run/sway.pid"
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.
 
start_stop_daemon_args="--background --pidfile ${pidfile}"


depend() {
{{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>.}}
  need localmount
  after elogind
  use seatd dbus
}
</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 ===
=== 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>
Then, to enable for all keyboards, navigate to the input section of ''~/.config/sway/config'' and modify it to
<pre>
input * {
  xkb_layout "my_layout"
}
}
</pre>
</pre>
If you have enabled <code>xkb_numlock</code>, include this setting inside those braces as well.
 
=== Changing default application fonts ===
 
See [[Fontconfig]]


== 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).  
=== 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 "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 ===
=== Firefox (Flatpak) and/or GTK apps ===
Line 244: Line 299:
=== 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 terminal multiplexer|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:Desktop]]
[[Category:Window Managers]]
[[Category:Wayland]]

Latest revision as of 21:43, 6 March 2024

Sway is a tiling Wayland compositor and a drop-in replacement for the i3 window manager for X11. It works with your existing i3 configuration and supports most of i3's features, plus a few extras.

Installation

Add a normal user

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

Set up eudev

eudev is recommended and required for. Without it, sway cannot connect to input devices.

setup-devd udev

Install Graphics Drivers

Graphics drivers:

Setting up a seat manager

Wayland compositors need raw access to input and output devices. This is mediated by a seat manager. Using either seatd or elogind is supported. Using both may lead to conflicts.

Install seatd

See Seatd.

Install elogind

See Elogind.

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:

# in ~/.config/sway/config
exec touch /tmp/swaylock-sleep && inotifyd swaylock /tmp/swaylock-sleep

With this line, the screen will be promptly locked before suspend-to-RAM starts.

Install greetd (optional)

Note: This content is tangential, and should be moved into the 'greetd' page
apk add greetd greetd-gtkgreet cage
rc-update add greetd
adduser greetd seat

In /etc/greetd/config.toml, set

[default_session]

command = "cage -s -- gtkgreet"

To use a graphical greeter with seatd add rc_need=seatd to /etc/conf.d/greetd.

In /etc/greetd/environments, set

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

D-Bus is required for PipeWire and screensharing in Firefox and Chromium. Running with dbus-run-session is a convenience wrapper that will explicitly export the path of the session bus.

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
   grim                 \ # screenshot tool
   wl-clipboard         \ # clipboard management
   i3status             \ # simple status bar
   swayidle               # idle management (DPMS) daemon

For complimentary software alternatives, see the relevant page from sway's wiki or 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.

PipeWire and enable screensharing

For audio playback, either PipeWire or PulseAudio work fine. The compositor has no involvement in audio playback.

For screen sharing, 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 not additional setup. Applications in the second group (which includes Firefox and Chromium) require setting up pipewire, wireplumber and xdg portals:

Todo: Move this content into PipeWire.


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

Launch PipeWire with Sway. Use your service manager of choice, or add the following to sway config:

exec /usr/libexec/pipewire-launcher

If your are using automatic D-Bus activation, 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
Unclear: The following paragraph is unclear and needs further work

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

set $menu bemenu-run | xargs swaymsg exec

Screen lock and suspend-to-RAM

Without elogind

Consider using powerctl.

With elogind

Putting the system to sleep with elogind requires elevated privileges or additional configuration.

For details on configuring doas with elogind, see Elogind#Doas

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

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

loginctl suspend command will trigger the screenlock, as mentioned in the section Install elogind (optional) above.

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

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

Brightness control

Controlling display backlight requires either the proper udev rules, or using some form of privilege escalation.

brightnessctl is a reliable alternative, although its default udev rules require too wide permissions (see #15409). You may need your own rules, or configure doas to allow running it as an unprivileged user.

Optionally enable brightnessctl service to restore brightness settings on reboot:

rc-update add brightnessctl

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"


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.

Tweaks

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

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:

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
}

Changing default application fonts

See Fontconfig

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


See Also