# Contributor: Henrik Riomar <henrik.riomar@gmail.com>
# Contributor: Antoine Fontaine <antoine.fontaine@epfl.ch>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=sway
pkgver=1.9
pkgrel=3
pkgdesc="i3-compatible window manager for Wayland"
url="https://swaywm.org/"
license="MIT"
arch="all"
makedepends="
	basu-dev
	cairo-dev
	eudev-dev
	gdk-pixbuf-dev
	json-c-dev
	libcap-utils
	libevdev-dev
	libinput-dev
	libxkbcommon-dev
	linux-pam-dev
	meson
	ninja
	pango-dev
	pcre2-dev
	scdoc
	wayland-dev
	wayland-protocols
	wlroots0.17-dev
	"
subpackages="
	$pkgname-dbg
	$pkgname-doc
	$pkgname-wallpapers::noarch
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	$pkgname-portalsconf
	swaybar
	swaynag
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/swaywm/sway/archive/$pkgver.tar.gz
	sway-portals.conf
	sway.desktop
	remove-aports-git-version.patch
	"
install="$pkgname-portalsconf.pre-install $pkgname-portalsconf.pre-upgrade"
options="setcap !check" # no test suite

# Remove when Alpine >= 3.21
replaces="sxmo-sway"
provides="sway-virtual sxmo-sway=$pkgver-r$pkgrel"
provider_priority=100

build() {
	abuild-meson \
		-Db_lto=true \
		-Dsd-bus-provider=basu \
		. output
	meson compile -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# for setting SCHED_RR scheduling policy
	# before starting the Wayland server
	setcap cap_sys_nice=+ep "$pkgdir"/usr/bin/sway

	install -D -m644 "$srcdir"/sway.desktop \
		-t "$pkgdir"/usr/share/wayland-sessions/
}

portalsconf() {
	pkgdesc="xdg-desktop-portal configuration of compatible portals for Sway"
	install_if="$pkgname=$pkgver-r$pkgrel xdg-desktop-portal>=1.17.0"

	install -Dm644 "$srcdir"/sway-portals.conf \
		-t "$subpkgdir"/usr/share/xdg-desktop-portal/
}

wallpapers() {
	pkgdesc="Wallpapers for Sway"
	license="CC0-1.0"
	install_if="$pkgname=$pkgver-r$pkgrel"

	amove usr/share/backgrounds
}

swaybar() {
	pkgdesc="Standard bar for Sway"
	install_if="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin/swaybar
}

swaynag() {
	pkgdesc="CLI to show a warning or error message with buttons in Sway"
	install_if="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin/swaynag
}

sha512sums="
7ec0a29078eb7e0fb1b6af97613c263adec78ddb03a63cb75fb5e44c7241ed144687fd094ee2eb70f4397832ca9bdffc88bc32dee7683bf0e515417c7a05d4c4  sway-1.9.tar.gz
c10862928d839a5a8a3a8c235ab9df58b0ffb111b7a0b11e9110b39169ac37de6e7eb1d945ec3611fb213ba159f0e47afd97085faa6ee8238e4d06fed0d74d70  sway-portals.conf
327f11cc053b39816da76a62199ef40f564acc1fe474b013fc1fd594c448ae3da805bfc475b7c68cce3a17b4a261c5a4bc7e9e91a471f90f5cf4e95bbd937e6c  sway.desktop
3081f34ff88be38889ace94489ff4dc97a3d2d8402a6f2e83e968b991db478b7d3329d1685697898d8e43761e83be0d7c348a5fee45fe41dbb77521cda7b5a72  remove-aports-git-version.patch
"
