# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Maintainer: Integral <integral@member.fsf.org>

pkgname=xdg-desktop-portal-hyprland-git
_pkgname="${pkgname%-git}"
pkgver=1.4.1.r3.g688feb3
pkgrel=1
epoch=1
pkgdesc="xdg-desktop-portal backend for hyprland"
url="https://github.com/hyprwm/${_pkgname}"
arch=('x86_64')
license=('BSD-3-Clause')
depends=(
	'libinih'
	'pipewire'
	'qt6-base'
	'qt6-wayland'
	'sdbus-cpp'
	'util-linux-libs'
	'wlroots0.19'
	'xdg-desktop-portal'
	'hyprlang-git'
	'hyprutils-git' 'libhyprutils.so'
	'hyprwayland-scanner-git'
)
makedepends=(
	'git'
	'cmake'
	'wayland'
	'wayland-protocols'
)
optdepends=('grim: required for the screenshot portal to function'
	'slurp: support for interactive mode for the screenshot portal')
provides=("${_pkgname}" "xdg-desktop-portal-impl" "xdg-desktop-portal-wlr")
conflicts=("${_pkgname}" "xdg-desktop-portal-wlr")
source=("git+${url}.git"
	"git+https://github.com/hyprwm/hyprland-protocols.git"
	"hyprland-portals.conf")
sha256sums=('SKIP'
            'SKIP'
            '20bc215211f16a361086d59fa051df7337d95f91c695a29d8c5d23d40407fad5')

pkgver() {
	cd "${_pkgname}/"
	git describe --long --tags --abbrev=7 | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/v//'
}

prepare() {
	cd "${_pkgname}/"

	git rm subprojects/sdbus-cpp # Use sdbus-cpp from [extra]
	git submodule init
	git config submodule.subprojects/hyprland-protocols.url "${srcdir}/hyprland-protocols"
	git -c protocol.file.allow=always submodule update
}

build() {
	cmake -B build -S "${_pkgname}" \
		-D CMAKE_INSTALL_PREFIX=/usr \
		-D CMAKE_INSTALL_LIBEXECDIR=/usr/lib \
		-D CMAKE_BUILD_TYPE=Release

	cmake --build build
}

package() {
	DESTDIR="${pkgdir}" cmake --install build
	install -Dm644 "${srcdir}/hyprland-portals.conf" -t "${pkgdir}/usr/share/xdg-desktop-portal/"
	install -Dm644 "${_pkgname}/LICENSE" -t "${pkgdir}/usr/share/licenses/${pkgname}/"
}
