Running Multiple swaybg Instances for Niri Overview Backdrop
By default, swaybg use fixed layer
namespace for all instance. However, to achieve a nice visual effect in
Niri where the overview has a different
(e.g., blurred) wallpaper than the main desktop, we need two instances of
swaybg with namespace running simultaneously.
This requires a patched version of swaybg that supports configurable Wayland
layer-shell namespaces: https://github.com/swaywm/swaybg/pull/87
Building the Patched Package
First, download the Arch Linux build scripts for swaybg:
yay -G swaybg
cd swaybg
Next, apply the patch to the PKGBUILD. This involves:
- Bumping the
pkgrel. - Adding the patch file to
source. - Updating
b2sums(you can generate this withpkgctl build --update-checksum). - Adding a
prepare()function to apply the patch.
diff --git a/PKGBUILD b/PKGBUILD
index 77694e0..52986ca 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -5,7 +5,7 @@
pkgname=swaybg
pkgver=1.2.1
-pkgrel=1
+pkgrel=2
pkgdesc='Wallpaper tool for Wayland compositors'
arch=(x86_64)
url='https://github.com/swaywm/swaybg'
@@ -22,14 +22,22 @@ depends=(
source=(
"$pkgname-$pkgver.tar.gz::https://github.com/swaywm/swaybg/releases/download/v$pkgver/swaybg-$pkgver.tar.gz"
"$pkgname-$pkgver.tar.gz.sig::https://github.com/swaywm/swaybg/releases/download/v$pkgver/swaybg-$pkgver.tar.gz.sig"
+ "swaybg-namespace.patch::https://github.com/swaywm/swaybg/pull/87.patch"
)
b2sums=('0183f11c2d8a967054572676a1c87c7d533c8f4a7bd204049d53e350966dfc825d2d779d0d8165cec9b8e019b9c1bc7a0b7702270b02aa0f02bfbc8400ec6b53'
- 'SKIP')
+ 'SKIP'
+ '57eb358dd0497178a432a18070a0379208d487ad133e3aff2e45ec07a957e2647c83b09c00124aeef4b2ec3a21b2f64e1a26e1b0d660e9320aa86e6678a6ed21')
validpgpkeys=(
"9DDA3B9FA5D58DD5392C78E652CB6609B22DA89A" # Drew DeVault
"34FF9526CFEF0E97A340E2E40FDE7BE0E88F5E48" # Simon Ser
)
+prepare() {
+ pushd "$pkgname-$pkgver"
+ patch -p1 -Ni ../swaybg-namespace.patch
+ popd
+}
+
build() {
meson "$pkgname-$pkgver" build \
--prefix /usr \
Now, build and install the package. Ensure you have the necessary PGP keys imported (found in validpgpkeys):
gpg --import keys/pgp/*.asc
pkgctl build
Systemd Service Configuration
To manage these wallpapers easily, we can use a Systemd template unit. Create
~/.config/systemd/user/[email protected]:
[Unit]
PartOf=graphical-session.target
After=graphical-session.target
Requisite=graphical-session.target
Description=Swaybg running on namespace %i
[Service]
# The -n flag is added by our patch to specify the namespace.
# We assume images are named 'image-wallpaper.png' and 'image-backdrop.png'.
ExecStart=/usr/bin/swaybg -m fill -n %i -i "%h/Pictures/Wallpapers/image-%i.png"
Restart=on-failure
[Install]
WantedBy=graphical-session.target
Enable and start the service for two separate namespaces: wallpaper (for the
desktop) and backdrop (for the overview).
systemctl --user enable --now [email protected]
systemctl --user enable --now [email protected]
Niri Configuration
Finally, configure Niri to treat the swaybg instance running in the
backdrop namespace as the overview background.
Add the following to the config.kdl:
// ... inside your config ...
// Put swaybg with namespace "backdrop" inside the overview.
layer-rule {
match namespace="^backdrop$"
place-within-backdrop true
}
Generating the Backdrop Image
To make the UI look better, use ImageMagick to create a blurred version for the backdrop:
magick '/path/to/image.png' -blur 0x15 '/path/to/image-backdrop.png'
# And ensure the normal one is named correctly for the service logic
cp '/path/to/image.png' '/path/to/image-wallpaper.png'