Sway: Difference between revisions

From Alpine Linux
mNo edit summary
(pipewire-launcher)
(24 intermediate revisions by 8 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.
[http://swaywm.org Sway] is a tiling [[Wayland]] compositor. It's a drop-in replacement for the i3 window manager.


== Prerequisites ==
== Installation ==


First, install & configure eudev:
eudev:


<pre>
<pre>
# apk add eudev
# apk add eudev
# setup-udev
# setup-devd udev
</pre>
 
Then install graphics drivers appropriate to your system:
 
<pre>
# apk add mesa-dri-gallium  # gallium
# apk add mesa-dri-classic  # or classic
</pre>
</pre>


The following links contain guides for setting up the video stack.
Graphics drivers:


* [[Intel Video]]
* [[Intel Video]]
* [[Radeon Video]]
* [[Radeon Video]]
 
* [[Nvidia Video]]
Add yourself to the input and video groups:
Add user to the input and video groups:


<pre>
<pre>
Line 29: Line 22:
</pre>
</pre>


You have to log out and back in for this to take effect.


Install some TTF fonts:
Install some TTF fonts:
Line 37: Line 29:
</pre>
</pre>


Since sway 1.6.1 (more specifically, since wlroots 0.14), you need to set up libseat backend if you wish to run sway directly (without nesting it in another wayland compositor). To do that, choose one of the following methods:
seatd daemon:
 
<dl>


<dt>seatd daemon</dt>
<dd>
<pre>
<pre>
# apk add seatd
# apk add seatd
Line 50: Line 38:
</pre>
</pre>


If you are already logged in as a $USER, you will need to relogin.
[[elogind]], optional for suspend on lid close support.
</dd>
 
Install sway:
 
<pre>
# apk add sway sway-doc
# apk add                \ # Install optional dependencies:
    xwayland            \ # recommended for compatibility reasons
    foot                \ # default terminal emulator
    bemenu              \ # wayland menu
    swaylock swaylockd  \ # lockscreen tool
    swaybg              \ # wallpaper daemon
    swayidle              # idle management (DPMS) daemon
</pre>
 
Configure XDG_RUNTIME_DIR.  Add the following to shell init scripts, for the default ash shell it is ~/.profile:
 
<pre>
if test -z "${XDG_RUNTIME_DIR}"; then
  export XDG_RUNTIME_DIR=/tmp/$(id -u)-runtime-dir
  if ! test -d "${XDG_RUNTIME_DIR}"; then
    mkdir "${XDG_RUNTIME_DIR}"
    chmod 0700 "${XDG_RUNTIME_DIR}"
  fi
fi
</pre>
 
 
For inter-program communication and functionality such as screensharing, install and enable dbus and PipeWire, see [[PipeWire]].
 
Re-login or reboot to allow above modifications to take effect.
 
Launch Sway with dbus support:


<dt>seatd-launch</dt>
<dd>
<pre>
<pre>
# apk add seatd-launch
dbus-run-session -- sway
</pre>
</pre>


When starting sway, you will need to prefix invocation with <code>seatd-launch</code>.
== Configuration ==
Note: <code>seatd-launch</code> is a suid binary, so it might be wise to use one of the other methods from a security perspective.
 
</dd>
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.
 
For additional information, start at <code>man 5 sway</code> and read the [https://github.com/swaywm/sway/wiki upstream wiki].


<dt>elogind daemon</dt>
=== Firefox screensharing ===
<dd>
TODO
</dd>


</dl>
For some programs, additional configuration is needed to launch them natively under Wayland and to support special features such as screen sharing.


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


We can now install sway:
* 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:
<pre>
exec /usr/libexec/pipewire-launcher #pipewire must be launched first
exec /usr/libexec/xdg-desktop-portal-wlr
</pre>
* Export the following variables:


<pre>
<pre>
# apk add sway sway-doc
export MOZ_ENABLE_WAYLAND="1"
# apk add                \ # Install optional dependencies:
export XDG_CURRENT_DESKTOP=sway
    xwayland            \ # recommended for compatibility reasons
export XDG_SESSION_TYPE=wayland
    foot                \ # default terminal emulator
export QT_QPA_PLATFORM="wayland-egl"
    dmenu                \ # default application launcher
    swaylock            \ # lockscreen tool
    swayidle              # idle management (DPMS) daemon
</pre>
</pre>


== Running Sway ==
=== Scaling for high resolution screens ===


To run sway, first set XDG_RUNTIME_DIR to a suitable location (e.g. /tmp). Install & configure elogind to skip this step. Then run sway from the Linux console:
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 <code>wdisplays</code> package. Note the output name (eDP-1, LVDS-1) and try apply scaling factors such as 1 and 2.  To make changes permanent, add


<pre>
<pre>
$ XDG_RUNTIME_DIR=/tmp sway
output <name> scale <factor>
</pre>
</pre>


(if you run sway with seatd-launch, you will need to use <code>$ XDG_RUNTIME_DIR=/tmp seatd-launch sway</code>)
to ~/.config/sway/config.


See the [https://wiki.alpinelinux.org/wiki/Wayland Wayland] page for a permanent configuration
==== Via GTK/Qt ====


{{Note|
<pre>
swaylock needs to be able to read your <code>/etc/shadow</code> file to be able to validate your password
# for GTK-based programs such as firefox and emacs:
}}
export GDK_DPI_SCALE=2


== Configuration and Usage ==
# 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"
</pre>


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


For additional information, start at <code>man 5 sway</code> and read the [https://github.com/swaywm/sway/wiki upstream FAQ].
<pre>
exec wl-paste --type text/plain --watch clipman store --histpath="~/.local/state/clipman-primary.json"
bindsym $mod+h exec clipman pick --tool wofi --histpath="~/.local/state/clipman-primary.json"
</pre>


[[Category:Desktop]]
[[Category:Desktop]]

Revision as of 19:40, 11 September 2022

Sway is a tiling Wayland compositor. It's a drop-in replacement for the i3 window manager.

Installation

eudev:

# apk add eudev
# setup-devd udev

Graphics drivers:

Add user to the input and video groups:

# adduser $USER input
# adduser $USER video


Install some TTF fonts:

# apk add ttf-dejavu

seatd daemon:

# apk add seatd
# rc-update add seatd
# rc-service seatd start
# adduser $USER seat

elogind, optional for suspend on lid close support.

Install sway:

# apk add sway sway-doc
# apk add                \ # Install optional dependencies:
    xwayland             \ # recommended for compatibility reasons
    foot                 \ # default terminal emulator
    bemenu               \ # wayland menu
    swaylock swaylockd   \ # lockscreen tool
    swaybg               \ # wallpaper daemon
    swayidle               # idle management (DPMS) daemon

Configure XDG_RUNTIME_DIR. Add the following to shell init scripts, for the default ash shell it is ~/.profile:

if test -z "${XDG_RUNTIME_DIR}"; then
  export XDG_RUNTIME_DIR=/tmp/$(id -u)-runtime-dir
  if ! test -d "${XDG_RUNTIME_DIR}"; then
    mkdir "${XDG_RUNTIME_DIR}"
    chmod 0700 "${XDG_RUNTIME_DIR}"
  fi
fi


For inter-program communication and functionality such as screensharing, install and enable dbus and PipeWire, see PipeWire.

Re-login or reboot to allow above modifications to take effect.

Launch Sway with dbus support:

dbus-run-session -- sway

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.

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 XDG_SESSION_TYPE=wayland
export QT_QPA_PLATFORM="wayland-egl"

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"