Sway: Difference between revisions

From Alpine Linux
(to work with gallium, crocus is needed for older graphics)
(firefox screensharing support, hidpi)
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>
Line 10: Line 10:
</pre>
</pre>


Then install the mesa graphics drivers:
Graphics drivers:
 
<pre>
# apk add mesa-dri-gallium
## older intel graphics need
# MESA_LOADER_DRIVER_OVERRIDE=crocus
</pre>
 
The following links contain guides for setting up the video stack.


* [[Intel Video]]
* [[Intel Video]]
* [[Radeon Video]]
* [[Radeon Video]]


Add yourself to the input and video groups:
Add user to the input and video groups:


<pre>
<pre>
Line 30: 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 38: 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, [[Repositories#Enabling_the_community_repository|enable the community repository]] and choose one of the following methods:
seatd daemon:


<dl>
<dt>Option 1: seatd daemon (recommended)</dt>
<dd>
<pre>
<pre>
# apk add seatd
# apk add seatd
Line 51: 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>
 
<dt>Option 2: seatd-launch</dt>
<dd>
<pre>
# apk add seatd-launch
</pre>
 
When starting sway, you will need to prefix invocation with <code>seatd-launch</code>. 
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>


<dt>Option 3: elogind daemon</dt>
Install sway:
<dd>
 
<pre>
# apk add elogind polkit-elogind
# rc-update add elogind
# rc-service elogind start
</pre>
 
Using <code>elogind</code> will automatically set the necessary permissions, so you can skip adding groups like <code>seat</code> and <code>video</code>
 
</dd>
 
</dl>
 
== Installation ==
 
We can now install sway:


<pre>
<pre>
Line 88: Line 47:
     xwayland            \ # recommended for compatibility reasons
     xwayland            \ # recommended for compatibility reasons
     foot                \ # default terminal emulator
     foot                \ # default terminal emulator
     dmenu                \ # default application launcher
     wofi                \ # wayland menu for application selection and screensharing
     swaylock             \ # lockscreen tool
     swaylock swaylockd  \ # lockscreen tool
     swaybg              \ # wallpaper daemon
     swaybg              \ # wallpaper daemon
     swayidle              # idle management (DPMS) daemon
     swayidle              # idle management (DPMS) daemon
</pre>
</pre>


== Running Sway ==
Configure XDG_RUNTIME_DIR.  Add the following to shell init scripts, for the default ash shell it is ~/.profile:
 
To run sway, first set XDG_RUNTIME_DIR to a suitable location (e.g. create a .run folder in your home directory and set it to ~/.run). Then run sway from the Linux console (dbus-launch is used because pipewire needs it, it is included in dbus-x11 and you may omit it):


<pre>
<pre>
$ XDG_RUNTIME_DIR=~/.run dbus-launch sway
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>
</pre>


(if you run sway with seatd-launch, you will need to use <code>$ XDG_RUNTIME_DIR=~/.run dbus-launch seatd-launch sway</code>)
Launch Sway with dbus support:


You can also create a simple alias in your shell rc file (e.g. .zshrc), like:
<pre>
<pre>
alias swayinit="XDG_RUNTIME_DIR=~/.run dbus-launch seatd-launch sway"
dbus-launch --exit-with-session sway
</pre>
</pre>


See the [https://wiki.alpinelinux.org/wiki/Wayland Wayland] page for a permanent configuration
== Launching program under Wayland ==


{{Note|
For some programs, additional configuration is needed to launch them natively under Wayland and to support special features such as screen sharing.
swaylock needs to be able to read your <code>/etc/shadow</code> file to be able to validate your password
}}


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


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.
* 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: Add <code>exec pipewire</code> and <code>/usr/libexec/xdg-desktop-portal-wlr</code> to ~/.config/sway/config
* Export the following variables:


You might want to have gaps between windows, in which case add:
<pre>
<pre>
inner_gaps 20
export MOZ_ENABLE_WAYLAND="1"
outer_gaps 20
export XDG_CURRENT_DESKTOP=sway
export XDG_SESSION_TYPE=wayland
</pre>
</pre>
(replace 20 with the amount of pixels you want to be used for gaps) in your sway config.


You might have two monitors, and you might want to set their position, so here's an example of how to do it:
== HiDPI ==
 
<pre>
<pre>
output eDP-1 mode 1920x1080@60Hz
# for GTK-based programs such as firefox and emacs:
output eDP-1 position 1920,0
export GDK_DPI_SCALE=2
output DP-1 position 0,0
 
output DP-1 mode 1920x1080@120Hz
# for QT-based programs
export QT_WAYLAND_FORCE_DPI="physical"
export QT_QPA_PLATFORM="wayland-egl"
</pre>
</pre>
In this case, eDP-1 is the internal laptop monitor running at 60Hz and DP-1 is the external monitor running at 120Hz. The position of the laptop monitor is where the external monitor's width ends, so if the display is 1920 pixels wide and it is on the left, the laptop's monitor would be on the right, so it's width would start at the end of the second monitor's width, so at 1920. Replace the eDP-1 and DP-1 outputs with your own ones, and to change resolution and refresh rate, change the mode according to your parameters.


For additional information, start at <code>man 5 sway</code> and read the [https://github.com/swaywm/sway/wiki upstream FAQ].
== 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.
 
 
For additional information, start at <code>man 5 sway</code> and read the [https://github.com/swaywm/sway/wiki upstream wiki].


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

Revision as of 15:55, 21 July 2022

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

Installation

eudev:

# apk add eudev
# setup-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
    wofi                 \ # wayland menu for application selection and screensharing
    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

Launch Sway with dbus support:

dbus-launch --exit-with-session sway

Launching program under Wayland

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: Add exec pipewire and /usr/libexec/xdg-desktop-portal-wlr to ~/.config/sway/config
  • Export the following variables:
export MOZ_ENABLE_WAYLAND="1"
export XDG_CURRENT_DESKTOP=sway
export XDG_SESSION_TYPE=wayland

HiDPI

# for GTK-based programs such as firefox and emacs:
export GDK_DPI_SCALE=2

# for QT-based programs
export QT_WAYLAND_FORCE_DPI="physical"
export QT_QPA_PLATFORM="wayland-egl"

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.