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

EAPI=8

inherit meson xdg

MY_PV="$(ver_cut 1-3)+wayland$(ver_cut 5)"

DESCRIPTION="A window switcher, run dialog and dmenu replacement"
HOMEPAGE="https://github.com/lbonn/rofi"
SRC_URI="https://github.com/lbonn/rofi/releases/download/${MY_PV}/rofi-${MY_PV}.tar.xz"
S="${WORKDIR}"/rofi-${MY_PV}

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="drun windowmode test"
RESTRICT="!test? ( test )"

RDEPEND="
	!x11-misc/rofi
	>=dev-libs/glib-2.40:2
	x11-libs/cairo
	x11-libs/gdk-pixbuf:2
	x11-libs/pango
	dev-libs/wayland
	>=dev-libs/wayland-protocols-1.17
"
DEPEND="
	${RDEPEND}
	test? ( dev-libs/check )
"
BDEPEND="
	dev-util/wayland-scanner
	sys-devel/bison
"

src_configure() {
	local emesonargs=(
		-Dwayland=enabled
		-Dxcb=disabled
		-Dcheck=disabled
		$(meson_use drun)
		$(meson_use windowmode window)
		$(meson_feature test check)
	)
	meson_src_configure
}

pkg_postinst() {
	for v in ${REPLACING_VERSIONS}; do
		if ver_test "${v}" -lt 1.7.0; then
			elog "Rofi 1.7.0 removed the (deprecated) xresources based configuration setup."
			elog "If you are still using old configuration setup, please convert it to new format manually."
			elog "The new format configuration can be generated by 'rofi -dump-config > ~/.config/rofi/config.rasi'."
			elog "For more information, please see https://github.com/davatorium/rofi/releases/tag/1.7.0"
		fi
	done

	xdg_icon_cache_update
}