# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit edo gnome2-utils flag-o-matic meson systemd virtualx vala

DESCRIPTION="Application menu module for GTK"
HOMEPAGE="https://gitlab.com/vala-panel-project/vala-panel-appmenu"
SRC_URI="https://gitlab.com/vala-panel-project/vala-panel-appmenu/-/archive/${PV}/vala-panel-appmenu-${PV}.tar.bz2 -> ${P}.tar.bz2"
S="${WORKDIR}/vala-panel-appmenu-${PV}"

LICENSE="LGPL-3+"
SLOT="0"
KEYWORDS="amd64 ~arm arm64 ~loong ~ppc64 ~riscv x86"
IUSE="gtk2 wayland xfce"

RDEPEND="
	dev-libs/glib[dbus]
	>=x11-libs/gtk+-3.22.0:3[wayland?,X]
	gtk2? ( >=x11-libs/gtk+-2.24.0:2 )
	xfce? ( xfce-base/xfce4-panel )
"
DEPEND="${RDEPEND}
	wayland? ( dev-libs/wayland )
"
BDEPEND="virtual/pkgconfig"

src_configure() {
	# defang automagic dependencies, bug #785619
	use wayland || append-cflags -DGENTOO_GTK_HIDE_WAYLAND

	# outputs [ '2', '3' ] OR [ '3' ]
	local gtks="[$(usex gtk2 " '2'," '') '3' ]"

	local emesonargs=(
		-Dxfce="$(usex xfce 'enabled' 'disabled')"
		-Dappmenu-gtk-module=enabled
	)

	VALAC=valac-$(vala_best_api_version) VAPIGEN=vapigen-$(vala_best_api_version) meson_src_configure
}

my_test() {
	cd "${BUILD_DIR}"/tests || die

	local name
	for name in hello radio tester ; do
		edo ./${name}
	done
}

src_test() {
	virtx my_test
}

src_install() {
	meson_src_install

	mv "${ED}"/usr/share/doc/appmenu-gtk-module/* "${ED}"/usr/share/doc/${PF} || die
	rmdir "${ED}"/usr/share/doc/appmenu-gtk-module || die

	rm "${ED}"/usr/share/licenses/appmenu-gtk-module/LICENSE || die

	exeinto /etc/X11/xinit/xinitrc.d
	newexe "${FILESDIR}"/${PN}-r1 85-${PN}
}

pkg_postinst() {
	gnome2_schemas_update
}