# Maintainer: Peter Cai <peter at typeblog dot net>
# Maintainer: Antonin Décimo <antonin dot decimo at gmail dot com>
# Contributor: Adrian Perez de Castro <aperez@igalia.com>
pkgname=wlroots-hidpi-git
pkgver=0.21.0.r7879.2cec06a461
pkgrel=1
license=(custom:MIT)
pkgdesc='Modular Wayland compositor library, with XWayland HiDPI (git version)'
url=https://gitlab.freedesktop.org/wlroots/wlroots.git
arch=(x86_64)
provides=("libwlroots.so" "wlroots=${pkgver%%.r*}")
conflicts=(wlroots wlroots-git)
options=(debug)
depends=(
	glslang
	libinput
	libxcb
	libxkbcommon
	opengl-driver
	pixman
	wayland
	xcb-util-errors
	xcb-util-renderutil
	xcb-util-wm
	seatd
	vulkan-icd-loader
	xorg-xwayland
	libdisplay-info
	lcms2
	libliftoff)
depends+=(libdisplay-info.so)
makedepends=(
	git
	meson
	vulkan-headers
	wayland-protocols
	xorgproto)
# https://gitlab.freedesktop.org/MisterDA/wlroots/-/tree/xwayland_hidpi
source=("${pkgname}::git+${url}"
        "0001-xwayland-add-support-for-global-scale-factor.patch"
        "0002-xwayland-add-support-for-changing-global-scale-facto.patch"
        "0003-Revert-compositor-send-WL_SURFACE_ERROR_INVALID_SIZE.patch"
       )
sha256sums=('SKIP'
            '010225254192767ecda06b6ba7c8b6cf27d1933528c46f7df9377556edd080df'
            'f6e0cf6a02dcc3972e6afbfddcd5d3c0d83f7cf1fc6cbd49a5ded05ce72733e9'
            'a77ded105d3ee5760848bcb92144e516cfe2aed776e52d801e3409fada464169')


_builddir="build"

_meson_setup () {
	arch-meson \
		--buildtype=debug \
		-Dwerror=false \
		-Dexamples=false \
		"${pkgname}" "$1"
}

pkgver () {
	(
		set -o pipefail
		cd "${pkgname}"
		cat meson.build | awk 'match($0, /version:\s*'\''([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)(-.*)?'\''/, ret) {printf "%s",ret[1]}'
		printf ".r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
	)
}

prepare () {
	cd "${pkgname}"
	patch -Np1 < "${srcdir}/0001-xwayland-add-support-for-global-scale-factor.patch"
	patch -Np1 < "${srcdir}/0002-xwayland-add-support-for-changing-global-scale-facto.patch"
	patch -Np1 < "${srcdir}/0003-Revert-compositor-send-WL_SURFACE_ERROR_INVALID_SIZE.patch"
}

build () {
	_meson_setup "${_builddir}"
	meson compile -C "${_builddir}"
}

package () {
	DESTDIR="${pkgdir}" meson install -C build
	install -Dm644 "${pkgname}/"LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

post_upgrade() {
  echo "Make sure to upgrade wlroots-hidpi-git and sway-hidpi-git together."
  echo "Upgrading one but not the other is unsupported."
}
