# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit git-r3 savedconfig toolchain-funcs

DESCRIPTION="Scrollable, floating, mouse-chorded Wayland compositor in the spirit of Plan 9 rio"
HOMEPAGE="https://wayland.fyi/ https://git.sr.ht/~dlm/hevel"
EGIT_REPO_URI="https://git.sr.ht/~dlm/hevel"

LICENSE="ISC"
SLOT="0"

RDEPEND="gui-libs/neuswc"
DEPEND="${RDEPEND}"
BDEPEND="virtual/pkgconfig"

src_prepare() {
	default
	restore_config config.h
	if [[ ! -f config.h ]]; then
		cp config.def.h config.h || die
	fi
}

src_compile() {
	tc-export CC PKG_CONFIG
	# Command-line overrides replace the Makefile's hardcoded CC/CFLAGS
	# and its /usr/local -I/-L/-rpath assumptions, so the pkg-config
	# flags the Makefile would have appended must be inlined here.
	emake \
		CC="${CC}" \
		CFLAGS="${CFLAGS} -std=c99 $(${PKG_CONFIG} --cflags swc)" \
		LDFLAGS="${LDFLAGS}" \
		LDLIBS="$(${PKG_CONFIG} --libs swc)" \
		hevel
}

src_install() {
	dobin hevel
	einstalldocs
	save_config config.h
}

pkg_postinst() {
	elog "Start hevel from a TTY with:"
	elog "    swc-launch hevel"
	elog
	elog "All configuration is compile-time via config.h — enable"
	elog "USE=savedconfig to keep your own copy across rebuilds."
	elog
	elog "The default 1->3 chord spawns the terminal 'st-wl', which is not"
	elog "packaged in Gentoo. Set 'term' in config.h to a terminal you have"
	elog "(e.g. foot, alacritty, havoc) or install st-wl manually."
}