# Contributor: Marvin Preuss <marvin@xsteadfastx.org>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
maintainer="Jakub Jirutka <jakub@jirutka.cz>"
pkgname=rofi
pkgver=1.7.9_p1
_pkgver="${pkgver%_p*}+wayland${pkgver#*_p}"
pkgrel=0
pkgdesc="Window switcher, application launcher and dmenu replacement"
url="https://github.com/lbonn/rofi"
arch="all"
license="MIT"
makedepends="
	bison
	cairo-dev
	flex
	gdk-pixbuf-dev
	glib-dev
	libxcb-dev
	libxkbcommon-dev
	meson
	pango-dev
	ronn
	startup-notification-dev
	xcb-util-cursor-dev
	xcb-util-dev
	xcb-util-keysyms-dev
	xcb-util-wm-dev
	xcb-util-xrm-dev
	wayland-dev
	wayland-protocols
	"
checkdepends="
	cppcheck
	check-dev
	xkeyboard-config-dev
	"
replaces="rofi-themes<1.7.8_p1 rofi-wayland<1.7.0-r1"  # for backward compatibility
subpackages="
	$pkgname-x11-wayland:_x11_wayland
	$pkgname-wayland
	$pkgname-dev
	$pkgname-doc
	"
source="https://github.com/lbonn/rofi/releases/download/$_pkgver/rofi-$_pkgver.tar.gz
	rofi-sensible-terminal-use-sh.patch
	libnkutils-ignore-failing-asserts.patch
	disable-failing-tests.patch
	"
builddir="$srcdir/rofi-$_pkgver"

build() {
	abuild-meson \
		-Dxcb=enabled \
		-Dwayland=enabled \
		. output
	meson compile -C output

	abuild-meson \
		-Dxcb=disabled \
		-Dwayland=enabled \
		. output-wayland
	meson compile -C output-wayland
}

check() {
	meson test --print-errorlogs -C output
}

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

	# This image makes 2/3 of the size of the themes directory.
	# It's not the default theme, so get rid of it.
	rm -rf "$pkgdir"/usr/share/rofi/themes/iggy.jpg
}

_x11_wayland() {
	pkgdesc="$pkgdesc (X11 and Wayland)"
	depends="$pkgname=$pkgver-r$pkgrel !rofi-wayland"
	install_if="$pkgname"
	replaces=""

	amove usr/bin/rofi
}

wayland() {
	pkgdesc="$pkgdesc (Wayland only)"
	depends="$pkgname=$pkgver-r$pkgrel !rofi-x11-wayland"
	replaces=""

	# Cannot amove due to path conflict with -x11-wayland.
	install -Dm755 "$builddir"/output-wayland/rofi -t "$subpkgdir"/usr/bin/
}

sha512sums="
0264c4e048cd798da286f729d580965ee3f59fef87b7d89c8ef752e701ff242924075f9f1b1c578279a4c8b86e58be0af2780a2f763cc1fe3767104e46929c18  rofi-1.7.9+wayland1.tar.gz
c25940edf74a02c674da65d16c4fdbcc3bf6700c3b5f5e61d468851d5655490e3683b330dce0a15ea3ac4c3d440c63a69d48f3cea99cf7fd529b9de0fbfc9eae  rofi-sensible-terminal-use-sh.patch
ba7b406c2ea423c1222c86bae6aa4a097ce4b1ab2e9f057a0b788d384eb3fd0782d78d64a619d36931af747d465764a4a765748baee29b5e872f34181d44a3a5  libnkutils-ignore-failing-asserts.patch
2642cc00b534e902d7d6234d0067f4a9de4fbbf0f0eca8af12f3afc30f84047d8375824123042e4cc0e05e3854dde8bdc1ff15a223ca76c2af07e4b6ddf73c62  disable-failing-tests.patch
"
