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

# Autogenerated by pycargoebuild 0.15.1

EAPI=8

RUST_MIN_VER="1.88.0"

inherit cargo systemd udev

DESCRIPTION="Dynamic key remap for X and Wayland"
HOMEPAGE="https://github.com/xremap/xremap"
SRC_URI="
	https://github.com/xremap/xremap/archive/v${PV}/${P}.tar.gz
	https://github.com/yamader/xremap/releases/download/v${PV}/${P}-crates.tar.xz
"

LICENSE="MIT"
# Dependent crate licenses
LICENSE+=" Apache-2.0 BSD GPL-3+ MIT Unicode-3.0 ZLIB"
SLOT="0"
KEYWORDS="~amd64"
IUSE="cosmic gnome hyprland kde niri pantheon socket udev wlroots x11"
REQUIRED_USE="?? ( cosmic gnome hyprland kde niri pantheon socket wlroots x11 )"

DEPEND="udev? ( virtual/libudev )"
RDEPEND="${DEPEND}"

DOCS=( CHANGELOG.md README.md )

QA_FLAGS_IGNORED=".*"

src_configure() {
	local myfeatures=(
		$(usev gnome)
		$(usev x11)
		$(usev hyprland hypr)
		$(usev kde)
		$(usev wlroots)
		$(usev udev)
		$(usev niri)
		$(usev cosmic)
		$(usev socket)
		$(usev pantheon)
	)
	cargo_src_configure --no-default-features
}

src_install() {
	cargo_src_install

	insinto /etc/xremap
	doins example/config.yml
	doins example/emacs.yml

	insinto /etc/xdg/autostart
	doins example/xremap.desktop

	systemd_douserunit example/xremap.service

	insinto /usr/lib/modules-load.d
	doins "${FILESDIR}"/xremap-uinput.conf

	use udev && udev_newrules "${FILESDIR}"/xremap-input.rules 99-xremap-input.rules

	einstalldocs
}

pkg_postinst() {
	udev_reload
}

pkg_postrm() {
	udev_reload
}
