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

EAPI=8

VALA_MIN_API_VERSION="0.52"
GNOME_MIN_VERSIOM="40" # Its what is said in the mason.build file

inherit gnome2-utils meson vala xdg

DESCRIPTION="Desktop Environment based on GNOME 3"
HOMEPAGE="https://github.com/BuddiesOfBudgie/"
SRC_URI="https://github.com/BuddiesOfBudgie/${PN}/releases/download/v${PV}/${PN}-v${PV}.tar.xz -> ${P}.tar.xz"

LICENSE="GPL-2 LGPL-2.1"
SLOT="0"
KEYWORDS="~amd64 ~x86 ~arm ~arm64"
IUSE="gtk-doc +policykit stateless +bluetooth +hibernate networkmanager systemd"

COMMON_DEPEND="
	>=sys-apps/accountsservice-0.6.55

	>=budgie-base/budgie-desktop-services-1.0.2
	>=budgie-base/budgie-session-1.0.0

	>=gnome-base/gnome-desktop-${GNOME_MIN_VERSIOM}:3
	>=gnome-base/gnome-settings-daemon-47.2
	>=gnome-base/gsettings-desktop-schemas-${GNOME_MIN_VERSIOM}
	>=gnome-base/gnome-menus-3.10.3:3[introspection]
	>=x11-libs/gtk+-3.24.35:3[X,introspection]
	gui-libs/gtk-layer-shell[introspection,vala]
	x11-libs/gdk-pixbuf:2

	>=app-i18n/ibus-1.5.10[vala]
	media-libs/libcanberra-gtk3:=
	>=xfce-base/libxfce4windowing-4.20.4[vala]
	>=dev-libs/libgee-0.20.0:0.8=
	>=dev-libs/libpeas-2.0.7:2=
	>=x11-libs/libwnck-3.36:3
	
	>=media-libs/libpulse-2.0[glib]
	media-libs/gstreamer:1.0
	>=x11-libs/libnotify-0.7

	x11-themes/materia-theme
	>=sys-apps/xdg-desktop-portal-gtk-1.14.0
	gui-libs/xdg-desktop-portal-wlr

	gnome-extra/zenity
	sys-power/upower
	sys-apps/util-linux

	gui-apps/wdisplays
	gui-wm/labwc
	dev-python/psutil
	x11-apps/mesa-progs

	bluetooth? ( net-wireless/bluez )
	policykit? ( >=sys-auth/polkit-0.105[introspection] )
	networkmanager? ( gnome-extra/nm-applet )
"
# networkmanager useflag for applet support

RDEPEND="
	gui-apps/grim
	gui-apps/slurp
	x11-misc/gammastep
	gui-apps/wlopm
	gui-apps/swaybg
	gui-apps/swayidle
	
	|| (
		gui-apps/gtklock 
		gui-apps/swaylock
	)

	systemd? ( dev-python/python-systemd )
	sys-apps/gnome-disk-utility[gnome]
"

BDEPEND="
	$(vala_depend)
	dev-util/intltool
	dev-lang/sassc
	sys-libs/glibc
	dev-libs/glib
	gtk-doc? ( dev-util/gtk-doc )
"

DEPEND="
	${COMMON_DEPEND}
	>=dev-libs/gobject-introspection-1.44.0
"

src_unpack() {
	unpack ${P}.tar.xz
}

src_prepare() {
	sed -i -e "/add_install_script.*meson_post_install\.sh/d" meson.build || die

	# New release, I want to leave as much logging in but for non-systemd users I cannot force systemd purely for logging only.
	# I hate this approach but other than outright removing the logging as whole I rather go this way..
	if use !systemd; then
		PATCHES+=( "${FILESDIR}"/10.10.X/remove_labwc_journald_logging.patch )
	fi

	vala_setup
	default
}

src_configure() {
	local emesonargs=(
		$(meson_use gtk-doc with-gtk-doc)
		$(meson_use policykit with-polkit)
		$(meson_use stateless with-stateless)
		$(meson_use bluetooth with-bluetooth)
		$(meson_use hibernate with-hibernate)
	)
	meson_src_configure
}

pkg_postinst() {
	xdg_pkg_postinst
	gnome2_schemas_update

	ewarn "if upgrading from 10.9.3 and currently you are in a budgie-desktop session. Please logout and login again."
}

pkg_postrm() {
	xdg_pkg_postrm
	gnome2_schemas_update
}