# -*- mode: makefile-gmake; -*-
SRC := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

include ../lib/shared.mk
TARGET :=  $(XDG_DIR)/sway

PATH_ICON_BOSTON := "$$HOME/.icons/Boston"
PATH_GTK_ANT_NEBULA := "$$HOME/.theme/Ant-Nebula"

install: | init update

init:
	if (( ! $$+commands[sway] )) ; then
		$(report) debug "Sway not installed. Skipping."
	else
		$(report) header "Setting up sway"
		$(mk_link) $(SRC) $(TARGET)
		$(MAKE) -C $(SRC) init_icons
		$(MAKE) -C $(SRC) init_theme
	fi

init_icons:
	if [ ! -e $(PATH_ICON_BOSTON) ] ; then
		git clone "https://github.com/heychrisd/Boston-Icons" $(PATH_ICON_BOSTON)
			; $(report) "Installed Boston icons."
	else
		$(report) debug "$(PATH_ICON_BOSTON) already exists. Skipping"
	fi

init_theme:
	if [ ! -e $(PATH_GTK_ANT_NEBULA) ] ; then
		git clone "https://github.com/EliverLara/Ant-Nebula" $(PATH_GTK_ANT_NEBULA)
			; $(report) "Installed Ant Nebula GTK."
	else
		$(report) debug "$(PATH_GTK_ANT_NEBULA) already exists. Skipping"
	fi
	if (( $$+commands[gsettings] )) ; then
		gsettings set org.gnome.desktop.interface gtk-theme "Ant-Nebula" \
			&& gsettings set org.gnome.desktop.wm.preferences theme "Ant-Nebula" \
			; $(report) "Set theme in gnome"
	else
		$(report) debug "gsettings not installed. Skipping"
	fi

update:
	if (( ! $$+commands[swaymsg] )) ; then
		$(report) debug "swaymsg not installed. Skipping."
	else
		$(report) header "Reloading sway"
		swaymsg reload ; $(report) "sway reload"
		$(MAKE) -C $(SRC) update_icons
		$(MAKE) -C $(SRC) update_theme
	fi

update_icons:
	if [ ! -e $(PATH_ICON_BOSTON) ] ; then
		cd $(PATH_ICON_BOSTON)
		git pull ; $(report) "Updated Boston icons."
	fi

update_theme:
	if [ ! -e $(PATH_GTK_ANT_NEBULA) ] ; then
		cd $(PATH_GTK_ANT_NEBULA)
		git pull ; $(report) "Updated Ant Nebula GTK."
	fi

remove:
	$(report) header "Removing sway"
	$(rm_link) $(TARGET)
	if [ -e $(PATH_ICON_BOSTON) ] ; then
		rm -rf $(PATH_ICON_BOSTON) \
			; $(report) "Removed $(PATH_ICON_BOSTON)"
	fi
	if [ -e $(PATH_GTK_ANT_NEBULA) ] ; then
		rm -rf $(PATH_GTK_ANT_NEBULA) \
			; $(report) "Removed $(PATH_GTK_ANT_NEBULA)"
	fi