Sway
Sway (forma ridotta del compositore SirCmpwn's Wayland) è un compositore Waykand a sorgente libera progettato per essere compatibile col gestore delle finestre i3.
Installazione
Opzioni USE
USE flags for gui-wm/sway i3-compatible Wayland window manager
+filecaps
|
Use Linux file capabilities to control privilege rather than set*id (this is orthogonal to USE=caps which uses capabilities at runtime e.g. libcap) |
+man
|
Build and install man pages |
+swaybar
|
Install 'swaybar': sway's status bar component |
+swaynag
|
Install 'swaynag': shows a message with buttons |
X
|
Enable support for X11 applications (XWayland) |
tray
|
Enable support for StatusNotifierItem tray specification |
wallpapers
|
Install sway's default wallpaper image |
Emerge
root #
emerge --ask gui-wm/sway
Configurazione
Per visionare tutte le opzioni di configurazione disponibili
user $
man 5 sway
Documenti
Ogni utente utilizzante sway può modificare il documento di configurazione predefinito per personalizzare la sessione di sway. Gentoo tiene questi documenti nelle posizioni di /etc/sway/config predefinite:
user $
mkdir -p ~/.config/sway/
user $
cp /etc/sway/config ~/.config/sway/
Emulatore di terminale
Per impostazione predefinita Sway usa il terminale virtuale foot (trovato nel pacchetto gui-apps/foot). È bene emergere questo emulatore di terminale in modo che ce ne sia uno disponibile all'utilizzo di Sway:
root #
emerge --ask gui-apps/foot
Altre scelte diffuse sono x11-terms/alacritty o x11-terms/kitty, che funziona nativamente con Wayland se la variabile ambientale KITTY_ENABLE_WAYLAND
è impostata su 1
.
Un'altra alternativa leggera è st, ma non è nativa per Wayland
Configurazione dello schermo
Le opzioni di visualizzazione possono essere richieste con:
user $
swaymsg -t get_outputs
Output DP-1 'HP Inc. HP X34 6CM2261GK2' (focused) Current mode: 3440x1440 @ 165.000 Hz Position: 0,0 Scale factor: 1.000000 Scale filter: nearest Subpixel hinting: unknown Transform: normal Workspace: 1 Max render time: off Adaptive sync: disabled Available modes: 3440x1440 @ 165.000 Hz ... Output DP-2 'LG Electronics LG HDR QHD 110NTTQ0U193' Current mode: 2560x1440 @ 59.951 Hz Position: 3440,0 Scale factor: 1.000000 Scale filter: nearest Subpixel hinting: unknown Transform: normal Workspace: 2 Max render time: off Adaptive sync: disabled Available modes: 2560x1440 @ 59.951 Hz 2560x1440 @ 74.971 Hz ... Output DP-3 'Ancor Communications Inc VE247 E3LMQS103610' Current mode: 1920x1080 @ 60.000 Hz Position: 6000,0 Scale factor: 1.000000 Scale filter: nearest Subpixel hinting: unknown Transform: normal Workspace: 3 Max render time: off Adaptive sync: disabled Available modes: 1920x1080 @ 60.000 Hz
I risultati sono stati abbreviati in modo da contenere solo le risoluzioni desiderate. Le posizioni predefinite non sono configurate correttamente, e possono essere corrette modificando ~/.config/sway/config. A documento salvato, l'impostazione può essere ricaricata con $mod+Shift+C
output DP-1 resolution 3440x1440@165hz pos 2560 350
output DP-2 resolution 2560x1440@74.971hz pos 0 250
output DP-3 resolution 1920x1080@60hz pos 6000 0 transform 270
Dispositivi di Input
I dispositivi di input possono essere visualizzati con:
user $
swaymsg -t get_inputs
Input device: Logitech G502 HERO Gaming Mouse Keyboard Type: Mouse Identifier: 1133:49291:Logitech_G502_HERO_Gaming_Mouse_Keyboard Product ID: 49291 Vendor ID: 1133 Libinput Send Events: enabled Input device: Logitech G502 HERO Gaming Mouse Keyboard Type: Keyboard Identifier: 1133:49291:Logitech_G502_HERO_Gaming_Mouse_Keyboard Product ID: 49291 Vendor ID: 1133 Active Keyboard Layout: English (US) Libinput Send Events: enabled Input device: Logitech G502 HERO Gaming Mouse Type: Mouse Identifier: 1133:49291:Logitech_G502_HERO_Gaming_Mouse Product ID: 49291 Vendor ID: 1133 Libinput Send Events: enabled
input "1133:49291:Logitech_G502_HERO_Gaming_Mouse" {
accel_profile "flat"
pointer_accel -0.1
}
Application launcher
By default, Sway is configured to use dmenu, which uses X. dev-libs/bemenu is a good alternative that supports Wayland.
root #
emerge --ask dev-libs/bemenu
set $menu bemenu-run | xargs swaymsg exec --
set $menu bemenu-run -p "" | xargs swaymsg exec --
Barra di stato
In aggiunta alla barra di stato propria di Sway, Waybar può essere usato come una barra di stato altamente personalizzabile per esso.
root #
emerge --ask gui-apps/waybar
Questa può essere abilitata con:
bar {
status_command waybar
mode invisible
}
o:
exec waybar
Luminosità
la pagina di github per dev-libs/light attualmente (2023-09) stata: "Questo progetto è considerato orfano a partire dall'8 marzo 2023. Il suo uso è altamente scpraggiato fino a quando non verrà adottato da un altro sviluppatore.". Attualmente il pacchetto rimane nella Gentoo ebuild repository, ma gli utenti potrebbero voler tenere in considerazione il messaggio dello sviluppatore.
dev-libs/light può venir usato per modificare la retroilluminazione e luminosità. Qui un esempio di configurazione:
bindsym XF86MonBrightnessDown exec light -U 2
bindsym XF86MonBrightnessUp exec light -A 4
In alternativa, sys-power/acpilight può effettuare gli stessi cambiamenti della luminosità tramite un comando compatibile con xbacklight:
bindsym XF86MonBrightnessDown exec xbacklight -dec 2
bindsym XF86MonBrightnessUp exec xbacklight -inc 4
Volume
Se pulseaudio è in uso, la seguente impostazione può essere usata per modificare il volume:
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
Se PipeWire è in uso, la seguente impostazione può essere usata per modificare il volume (con Wireplumber):
bindsym XF86AudioRaiseVolume exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
bindsym XF86AudioLowerVolume exec wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
Se ALSA è in uso, la seguente impostazione può essere usata per modificare il volume (con Wireplumber):
bindsym XF86AudioRaiseVolume exec amixer -Mq set Speaker 5%+
bindsym XF86AudioLowerVolume exec amixer -Mq set Speaker 5%-
Se media-sound/sndio è in uso, la seguente impostazione può essere usata per modificare il volume (con Wireplumber):
bindsym XF86AudioRaiseVolume exec sndioctl -f snd/default output.level=+0.05
bindsym XF86AudioLowerVolume exec sndioctl -f snd/default output.level=-0.05
Acquisire schermate
Simple approach: use slurpshot
(Slurpshot) is a script to simplify taking screenshots. It uses native wayland apps only and enables selecting specific windows only, as well as previewing and printing screenshots withous saving them. First install dependencies:
root #
emerge --ask gui-apps/grim gui-apps/slurp app-misc/jq dev-libs/bemenu
Put the slurpshot script somewhere in your PATH, for example to ~/bin, make it executable and just set one keybind:
#
# Screen capture
#
bindsym Print exec slurpshot
Manual approach
To add screenshot support, use the grim utility (found in the gui-apps/grim package). The abbreviation grim
is defined as Grab Images. This utility is tailored to the specifics of the Wayland protocol. In order to install grim, use the following command:
root #
emerge --ask gui-apps/grim
To add support for determining the boundaries of the selected screen area, the slurp utility, found in the gui-apps/slurp package, is used in combination with the grim utility. To install slurp, use the command:
root #
emerge --ask gui-apps/slurp
Next, edit the configuration file to add support for keyboard shortcuts to perform a screenshot operation:
#
# Screen capture
#
set $ps1 Print
set $ps2 Control+Print
set $ps3 Alt+Print
set $ps4 Alt+Control+Print
set $psf $(xdg-user-dir PICTURES)/ps_$(date +"%Y%m%d%H%M%S").png
bindsym $ps1 exec grim - | wl-copy
bindsym $ps2 exec grim -g "$(slurp)" - | wl-copy
bindsym $ps3 exec grim $psf
bindsym $ps4 exec grim -g "$(slurp)" $psf
Please note that the Print or Ctrl + Print keys combination creates a screenshot in the wl-copy
buffer. This allows pasting the image directly from the clipboard, without having to save to a file on disk.
For the Alt + Print or Alt + Ctrl + Print keyboard shortcuts, the method of automatically saving the image file in the Pictures user directory is used.
Snipping tool like behavior
The following captures an area of the screen to the clipboard when mod+shift+S is pressed:
bindsym $mod+shift+s exec grimshot copy area
Set a random wallpaper
A random wallpaper can be pulled from a folder and be set: [1]
set $wallpapers_path $HOME/Pictures/Wallpapers
output * bg $(find $wallpapers_path -type f | shuf -n 1) fill
Swaylock
gui-apps/swaylock can be used to lock the current session.
root #
emerge --ask gui-apps/swaylock
bindsym $mod+l exec swaylock --ignore-empty-password --show-failed-attempts --color 1e1e1e
bindsym $mod+l exec swaylock --ignore-empty-password --show-failed-attempts \
--color 1e1e1e --inside-color cccccc --ring-color ffffff \
--inside-clear-color 11a8cd --ring-clear-color 29b8db \
--inside-ver-color 2472c8 --ring-ver-color 3b8eea \
--inside-wrong-color cd3131 --ring-wrong-color f14c4c
If the account is locked out, swaylock will not indicate this, and will simply fail. Switching to another TTY and attempting login can help diagnose this
Swayidle
gui-apps/swayidle runs a command after a certain idle time, typically to lock and/or power off the screen.
root #
emerge --ask gui-apps/swayidle
exec swayidle -w \
timeout 900 'swaymsg "output * power off"' \
resume 'swaymsg "output * power on"'
HiDPI
To adjust sway's rendering for HiDPI displays (4K and above), the name of the display to be adjusted must be obtained. After a sway session is running, issue the following:
user $
swaymsg -t get_outputs
The
swaymsg
USE flag must be enabled for the swaymsg command to be available on the system.The output
statement in the sway configuration file will accept a scale
parameter to adjust the scaling of the high resolution display.
Xresources
exec_always test -f ~/.Xresources && xrdb -merge ~/.Xresources
GTK configuration
Dark Mode
GTK3
GTK3 dark mode can be enabled by setting:
[Settings]
gtk-application-prefer-dark-theme = true
GTK2
GTK2 does not have a dark mode toggle, a dark theme must be selected:
gtk-theme-name = "Adwaita-dark"
GTK3 Themes and Fonts
Currently setting a GTK font and theme should be done by editing sway's configuration file (see Sway's wiki as well):
set $gnome-schema org.gnome.desktop.interface
exec_always {
gsettings set $gnome-schema gtk-theme 'theme name'
gsettings set $gnome-schema icon-theme 'icon theme name'
gsettings set $gnome-schema cursor-theme 'cursor theme name'
gsettings set $gnome-schema font-name 'Sans 10'
}
If encountering problems setting the mouse cursor with certain applications (including sway), this may help:
seat seat0 xcursor_theme custom_cursor_theme custom_cursor_size
Replace custom_cursor_theme and custom_cursor_size. Adwaita and 24 are pretty much default on all Linux distributions.
Automatic floating windows
By default, Sway opens new windows in tiling mode. The following configuration snippet makes many common windows which should float, float:
for_window [window_role = "pop-up"] floating enable
for_window [window_role = "bubble"] floating enable
for_window [window_role = "dialog"] floating enable
for_window [window_type = "dialog"] floating enable
for_window [window_role = "task_dialog"] floating enable
for_window [window_type = "menu"] floating enable
for_window [app_id = "floating"] floating enable
for_window [app_id = "floating_update"] floating enable, resize set width 1000px height 600px
for_window [class = "(?i)pinentry"] floating enable
for_window [title = "Administrator privileges required"] floating enable
Firefox Tweaks
for_window [title = "About Mozilla Firefox"] floating enable
for_window [window_role = "About"] floating enable
for_window [app_id="firefox" title="Library"] floating enable, border pixel 1, sticky enable
for_window [title = "Firefox - Sharing Indicator"] kill
for_window [title = "Firefox — Sharing Indicator"] kill
Steam Tweaks
for_window [class="^Steam$" title="^Friends$"] floating enable
for_window [class="^Steam$" title="Steam - News"] floating enable
for_window [class="^Steam$" title=".* - Chat"] floating enable
for_window [class="^Steam$" title="^Settings$"] floating enable
for_window [class="^Steam$" title=".* - event started"] floating enable
for_window [class="^Steam$" title=".* CD key"] floating enable
for_window [class="^Steam$" title="^Steam - Self Updater$"] floating enable
for_window [class="^Steam$" title="^Screenshot Uploader$"] floating enable
for_window [class="^Steam$" title="^Steam Guard - Computer Authorization Required$"] floating enable
for_window [title="^Steam Keyboard$"] floating enable
Service
OpenRC
root #
rc-update add elogind boot
Usage
Starting Sway
Starting Sway with dbus requires that XDG_RUNTIME_DIR is set. elogind or systemd will set this if used. Omitting the dbus-run-session may cause runtime errors.
Starting Sway without elogind.
Launching Sway automatically with TTY login
To start Sway on login to the first TTY:
if [ -z "${WAYLAND_DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
dbus-run-session sway
fi
Starting Sway manually
user $
dbus-run-session sway
Launching Sway from a script
This method uses a script to forcibly take over a virtual terminal and launch Sway in it. The typical use case is to launch Sway automatically on boot.
Sway is not supposed to be launched this way, the script may need some tuning to work.
#!/bin/sh
# Launch sway with a specific user, from a specific Virtual Terminal (vt)
# Two arguments are expected: a username (e.g., larry) and the id of a free vt (e.g., 7)
# prepare the tty for the user. vtX uses /dev/ttyX
chown "$1" "/dev/tty${2}"
chmod 600 "/dev/tty${2}"
# setup a clean environment for the user, take over the target vt, then launch sway
su --login --command "openvt --switch --console ${2} -- sway >\${HOME}/.sway_autolauncher.log 2>&1" "$1"
# this script returns immediately
This script has a few limitations:
- XDG_RUNTIME_DIR is expected to be defined and valid, see the section above.
- Without the
--switch
option for openvt, sway will freeze when trying to switch to a different VT (Ctrl+Alt+Fn), whether this is a bug or not is unknown. - The VT is not cleared when Sway exits, clear it by calling deallocvt.
- Similarly the TTY's owner and mode are not changed back to their default values when Sway exits.
Launching this script on boot can be done with the local service:
#!/bin/sh
sway_launcher larry 7
Starting Sway without elogind or systemd
Systems that are configured with neither systemd nor elogind will need to create a shell script (or use some other means) to set the XDG_RUNTIME_DIR variable.
The environment variable can be defined in the usual configuration files. For example, if Larry the cow (Larry) sets the XDG_RUNTIME_DIR variable in his shell's configuration file and he has chosen that the directory will be in /tmp:
#!/bin/sh
if test -z "${XDG_RUNTIME_DIR}"; then
UID="$(id -u)"
export XDG_RUNTIME_DIR=/tmp/"${UID}"-runtime-dir
if ! test -d "${XDG_RUNTIME_DIR}"; then
mkdir "${XDG_RUNTIME_DIR}"
chmod 0700 "${XDG_RUNTIME_DIR}"
fi
fi
With the XDG_RUNTIME_DIR defined, sway can be launched as usual:
user $
dbus-run-session sway
If issues are encountered, check Sway issues on GitHub before contacting the Sway community on IRC (#sway (webchat)) or opening a new Gentoo bug.
Movement
All key combinations will be defined in the ~/.config/sway/config configuration file.
The Super key is defined as the $mod
value by default. On most keyboards this will be the Windows key.
Sway has a Vi-like interface. h (left), j (down), k (up), and l (right) can be used for movement, in addition to the arrow keys.
Focus can be moved with mod+direction key, windows can be moved with mod+shift+direction key:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right
See man 5 sway-input for more information.
Useful binds
bindsym $mod+control+Right workspace next
bindsym $mod+control+Left workspace prev
Layouts
By default, Sway uses a tiling layout. Layout modes can be switched with the following default binds:
- mod+b - Horizontal split
- mod+v - Vertical split
- mod+s - Stacking
- mod+w - Tabbed
- mod+e - Toggle split
- mod+shift+space - Toggle floating
bindsym $mod+b splith
bindsym $mod+v splitv
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
bindsym $mod+Shift+space floating toggle
Terminal
The default key combination to open a terminal emulator is $mod+Enter.
Foot Server
Foot is a minimal Wayland terminal emulator that can be configured to run as a server, reducing resource usage.
exec foot -s
set $term footclient
If starting the foot server with Sway, it may not start fast enough to also auto-start a service, exec swaymsg "workspace 2; exec $term {command}" may be slow enough to mitigate this
Adding features
Sway is designed to be extended, adding additional features is easy:
bindsym control+shift+escape exec $term htop
If using foot, the app_id, which is set with -a, can be set to make it float automatically:
bindsym control+shift+escape exec $term -a 'flying-foot' htop
for_window [app_id="flying-foot"] floating enable
Troubleshooting
Screen sharing does not work
Make sure the package gui-libs/xdg-desktop-portal-wlr is installed. By default, it is autostarted by D-Bus but it fails to run because it needs environment variables exported by Sway, and the D-Bus session is started before Sway. To fix, update the D-Bus environment by adding the following line to the beginning of Sway's config:
exec --no-startup-id dbus-update-activation-environment --all
Failed to connect to user bus
[swaybar/tray/tray.c:42] Failed to connect to user bus: No such file or directory
- Forum topic [swaybar/tray/tray.c:42] Failed to connect to user bus: No such file or directory => Use dbus-run-session sway
- Forum topic sway(bar) with tray support
- https://github.com/swaywm/sway/issues/1415
Warning: no icon themes loaded
[swaybar/tray/icon.c:348] Warning: no icon themes loaded
It is looking for x11-themes/hicolor-icon-theme
No backend was able to open a seat
[ERROR] [wlr] [libseat] [libseat/libseat.c:78] No backend was able to open a seat
It is looking for a seat management daemon such as sys-auth/seatd or sys-auth/elogind. Also check whether setting XDG_RUNTIME_DIR is required.
I programmi dimenticano gli accessi
Alcuni programmi (es. net-misc/nextcloud-client) usano un "agente per servizi segreti" (Secret-Service-Agent) per salvare le credenziali d'accesso. Se un programma richiede le credenziali d'accesso ad ogni esecuzione, un agente configurato incorrettamente ne potrebbe essere la causa.
Prima, emergere gnome-base/gnome-keyring.
root #
emerge --ask gnome-base/gnome-keyring
Poi, abilitare l'opzione USE gnome-keyring
.
# Sway Secret-Service-Agent
*/* gnome-keyring
Aggiorna il sistema ed applica le nuove opzioni USE.
root #
emerge -avuDN @world
Per eseguire e sbloccare il luogo d'Agente quando si accede ad una sessione di Sway, modificare questi due documenti.
exec dbus-update-activation-environment --all
exec gnome-keyring-daemon --start --components=secrets
exec export $(gnome-keyring-daemon)
auth optional pam_gnome_keyring.so
password optional pam_gnome_keyring.so
session optional pam_gnome_keyring.so auto_start
Vedi anche
Riferimenti
- ↑ https://github.com/swaywm/sway/issues/1269
- ↑ https://github.com/Madic-/Sway-DE/blob/master/config/sway/sway.d/06_floating.conf
- ↑ https://github.com/Madic-/Sway-DE/blob/master/config/sway/sway.d/06_floating.conf
- ↑ https://github.com/Madic-/Sway-DE/blob/master/config/sway/sway.d/06_floating.conf
- ↑ https://github.com/Madic-/Sway-DE/blob/master/config/sway/sway.d/06_floating.conf
- ↑ https://github.com/swaywm/sway#running