Sway: Difference between revisions
No edit summary Tag: Reverted |
(Added a section for novice questions and detailed a few more troubleshooting steps) Tag: Reverted |
||
Line 279: | Line 279: | ||
=== 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 | You may need to get an icon pack and possibly a theme from [https://www.pling.com/browse?cat=107&ord=latest Pling store] and set <code>GTK_THEME</code> environmental variable. Alternatively you can install a theme for all users (search [https://pkgs.alpinelinux.org/ Alpine Linux Packages] for ''*-icon-theme'') using <code>apk add</code>. | ||
==== Missing file picker/cannot download ==== | ==== Missing file picker/cannot download ==== | ||
Line 291: | Line 291: | ||
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 terminal multiplexer|tmux]] | ||
=== Sway freezes after loading and no iput works === | |||
You can move to a new <code>tty</code> [<code>CTRL</code> + <code>ALT</code> + <code>F<n></code>; where <code><n></code> is a number Fkey on your keyboard], login as root, and kill all the processes that are linked to the problem <code>tty</code>. | |||
{{Tip|Something like this | |||
<pre> | |||
# for i in $(ps | awk '{ if($2==<user>) { print $1 } }'); do | |||
> kill -9 $i | |||
> done # don't forget to replace <user> with the user of the frozen tty | |||
</pre> | |||
}} | |||
=== Steam games launched via Proton crash before creating a window === | === Steam games launched via Proton crash before creating a window === | ||
Line 326: | Line 336: | ||
sway version 1.7 | sway version 1.7 | ||
</pre> | </pre> | ||
=== Where is good Alpine documentation? === | |||
Try here for reading. | |||
[[gitlab.alpinelinux.org/alpine/aports/-/issues|gitlab.alpinelinux.org/alpine/aports/-/issues]] | |||
=== How do I debug the launch of Sway? === | |||
I ran <code>sway -Vc /home/<user>/.config/sway/config</code> as root so that I would experience an error and not complete. | |||
=== What happens if <var>SWAYSOCK</var> is empty? === | |||
[[Swaylock|https://github.com/swaywm/swaylock/blob/master/README.md]] | |||
=== What happens if <var>LD_LIBRARY_PATH</var> is empty? === | === What happens if <var>LD_LIBRARY_PATH</var> is empty? === | ||
<blockquote> | |||
"LD_PRELOAD (not LD_PRELOAD_PATH) is a list of specific libraries (files) to be loaded before any other libraries, whether the program wants it or not. LD_LIBRARY_PATH is a list of directories to search when loading libraries that would have been loaded anyway. On linux you can read man ld.so for more information about these and other environment variables that affect the dynamic linker." | |||
<hr> | |||
{{Define|Source|[https://stackoverflow.com/questions/14715175/what-is-the-difference-between-ld-preload-path-and-ld-library-path]}} | |||
</blockquote> | |||
<blockquote> | |||
"When should I set LD_LIBRARY_PATH? | |||
The short answer is never. | |||
Why? | |||
Some users seem to set this environment variable because of bad advice from other users or badly linked code that they do not know how to fix." | |||
<hr> | |||
{{Define|Source|[http://linuxmafia.com/faq/Admin/ld-lib-path.html]}} | |||
</blockquote> | |||
{{Define|Source|[http://linuxmafia.com/faq/Admin/ld-lib-path.html]}} | |||
</blockquote> | |||
{{Note|ENVIRONMENT | |||
The following environment variables have an effect on sway: | |||
SWAYSOCK | |||
Specifies the path to the sway IPC socket. | |||
XKB_DEFAULT_RULES, XKB_DEFAULT_MODEL, XKB_DEFAULT_LAYOUT, XKB_DEFAULT_VARIANT, XKB_DEFAULT_OPTIONS | |||
Configures the xkb keyboard settings. See xkeyboard-config(7). The preferred way to configure the keyboard is via the configuration file, see sway-input(5). | |||
The following environment variables are set by sway: | |||
DISPLAY | |||
If compiled with Xwayland support and Xwayland is not disabled by the config, this will be set to the name of the X display used for Xwayland. | |||
I3SOCK | |||
For compatibility with i3, specifies the path to the sway IPC socket. | |||
SWAYSOCK | |||
Specifies the path to the sway IPC socket.[https://itcomprehension.com/ipc-ports-services-and-connections-explained] | |||
WAYLAND_DISPLAY | |||
Specifies the name of the Wayland display that sway is running on. | |||
XCURSOR_SIZE] | |||
Specifies the configured cursor size. | |||
XCURSOR_THEME | |||
Specifies the configured cursor theme. | |||
<hr/> | |||
{{Define|Source|[https://man.archlinux.org/man/sway.1]}} | |||
}} | |||
<pre> | |||
# swaymsg -t get_seats | |||
<timestamp> [swaymsg/main.c:419] Unable to retrieve socket path | |||
</pre> | |||
=== What if <var>/etc/sway/config.d/*</var> is empty? === | === What if <var>/etc/sway/config.d/*</var> is empty? === |
Revision as of 06:08, 28 February 2023
Sway is a tiling Wayland compositor. It's a drop-in replacement for the i3 window manager.
Setup
Don't forget, you will need to add the community repository.
$ whoami user $ su <snippet> # whoami root # echo $USER # just so that we know we retained the same environment variables user # # if the output is 'root' then we know we must have logged in using 'su -' # cat /etc/apk/repositories <snippet> # # You can edit the files in vi and remove the comment '#' from the line that has <version>/community
Once you have updated the file manually you can continue to the installation step.
# tFILE='/etc/apk/repositories' # line="$(cat $tFILE | grep -E "^#.*alpine/v.*/community" | cut -f1 -d:)" # add the comments so that it doesn't run everytime # awk -v line=$line 'FNR == line { sub("#",""); print } FNR != line { print }' $tFILE > $tFILE.upd # cat $tFILE.upd # if everything is correct after inspection then we can move it over <snippet> # cp $tFILE $tFILE.bak # just in case the hairbrained idea doesn't work # cat $tFILE.upd > $tFILE; rm $tFILE.upd # we want to keep the file permissions so don't use cp
Installation
eudev:
# whoami root # rc-update # let's look at the services that are configured for each run-level <snippet> # apk add eudev # setup-devd udev # rc-update # we can now see the services that have been added by the setup script <snippet>
Graphics drivers:
Add user to the input and video groups:
# whoami root # echo $USER user # adduser $USER input # adduser $USER video
Install some TTF fonts:
# apk add ttf-dejavu <snippet>
seatd daemon:
# # if we like we can look at the services again using rc-update # apk add seatd <snippet> # rc-update add seatd # # and then look again to compare # rc-service seatd start # adduser $tempUSER seat
Install sway:
# apk add sway sway-doc <snippet> # apk add \ # Install optional dependencies: xwayland \ # recommended for compatibility reasons foot \ # default terminal emulator. Modify $term in config for a different one. bemenu \ # wayland menu swaylock swaylockd \ # lockscreen tool swaybg \ # wallpaper daemon swayidle # idle management (DPMS) daemon
Configure XDG_RUNTIME_DIR.
Usage
For inter-program communication and functionality such as screensharing, install and enable dbus and PipeWire, see PipeWire and set SWAYSOCK
environmental variable to the value exported by 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.
Launch Sway with a D-Bus server available, use:
dbus-run-session -- sway #prepend with exec in your login shell init script
Configuration
An example config is provided at /etc/sway/config
. Copy it to ~/.config/sway/config
and 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.
Firefox screensharing
For some programs, additional configuration is needed to launch them natively under Wayland and to support special features such as screen sharing.
To launch Firefox natively under Wayland and to enable support for screensharing, you need:
- Install and configure PipeWire
- Install xdg-desktop-portal and xdg-desktop-portal-wlr package
- Install wofi for screen selection
- Launch support programs on sway startup:
exec /usr/libexec/pipewire-launcher #pipewire must be launched first exec /usr/libexec/xdg-desktop-portal-wlr
- Export the following variables:
export MOZ_ENABLE_WAYLAND="1" export XDG_CURRENT_DESKTOP=sway export QT_QPA_PLATFORM="wayland-egl"
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-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.
Scaling for high resolution screens
Without further configuration, program interfaces might be too small to use on high resolution screens.
Via sway
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
Via GTK/Qt
# 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 test 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.
$XCURSOR_SIZE
and $XCURSOR_THEME
.Start as a service
Although this is not necessary, you may write an init script like the following:
{{/etc/init.d/sway| #!/sbin/openrc-run description="Sway Compositor" command="/usr/bin/sway" command_args="" pidfile="/run/sway.pid" start_stop_daemon_args="--background --pidfile ${pidfile}" depend() { need localmount after elogind use seatd dbus }
Then as a root run chmod +x /etc/init.d/seat
and rc-update add sway default
. 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
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.
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).
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
Sway freezes after loading and no iput works
You can move to a new tty
[CTRL
+ ALT
+ F<n>
; where <n>
is a number Fkey on your keyboard], login as root, and kill all the processes that are linked to the problem tty
.
# for i in $(ps | awk '{ if($2==<user>) { print $1 } }'); do > kill -9 $i > done # don't forget to replace <user> with the user of the frozen tty
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.
Novice Questions
What if the services hwdrivers or mdev are not in the sysinit run-level?
"udev performs its own hwdrivers module detection, it does not need the additional service. We delete the hwdrivers service when enabling udev, and add it when enabling mdev and mdevd."
Source: alpine-conf
What does seatd do?
"Seat management takes care of mediating access to shared devices (graphics, input), without requiring the applications needing access to be root."
Source: sourcehut
What if I run into a problem with sway?
You can always check the version that you are running. But problems like the following error can occur:
# sway --version Error loading shared library libjson-c.so.5: I/O error (needed by /usr/bin/sway) <snippet>
When this error occurred I was experiencing trouble with the filesystem. The filesystem had *booped* itself into read-only mode. A reboot fixed this error.
# sway --version sway version 1.7
Where is good Alpine documentation?
Try here for reading. gitlab.alpinelinux.org/alpine/aports/-/issues
How do I debug the launch of Sway?
I ran sway -Vc /home/<user>/.config/sway/config
as root so that I would experience an error and not complete.
What happens if SWAYSOCK is empty?
https://github.com/swaywm/swaylock/blob/master/README.md
What happens if LD_LIBRARY_PATH is empty?
"LD_PRELOAD (not LD_PRELOAD_PATH) is a list of specific libraries (files) to be loaded before any other libraries, whether the program wants it or not. LD_LIBRARY_PATH is a list of directories to search when loading libraries that would have been loaded anyway. On linux you can read man ld.so for more information about these and other environment variables that affect the dynamic linker."
- Source
- [1]
"When should I set LD_LIBRARY_PATH? The short answer is never.
Why? Some users seem to set this environment variable because of bad advice from other users or badly linked code that they do not know how to fix."
- Source
- [2]
- Source
- [3]
The following environment variables have an effect on sway:
SWAYSOCK
Specifies the path to the sway IPC socket. XKB_DEFAULT_RULES, XKB_DEFAULT_MODEL, XKB_DEFAULT_LAYOUT, XKB_DEFAULT_VARIANT, XKB_DEFAULT_OPTIONS
Configures the xkb keyboard settings. See xkeyboard-config(7). The preferred way to configure the keyboard is via the configuration file, see sway-input(5). The following environment variables are set by sway:
DISPLAY
If compiled with Xwayland support and Xwayland is not disabled by the config, this will be set to the name of the X display used for Xwayland. I3SOCK
For compatibility with i3, specifies the path to the sway IPC socket.
SWAYSOCK
Specifies the path to the sway IPC socket.[4]
WAYLAND_DISPLAY
Specifies the name of the Wayland display that sway is running on. XCURSOR_SIZE]
Specifies the configured cursor size. XCURSOR_THEME
Specifies the configured cursor theme.
- Source
- [5]
# swaymsg -t get_seats <timestamp> [swaymsg/main.c:419] Unable to retrieve socket path