#!/bin/bash
# adjust screen position of drive icons (zzzfm desktop)
# 260101 radky

export TEXTDOMAIN=desktopcontrol
export OUTPUT_CHARSET=UTF-8

[ ! -e ~/.config/autostart/zzzfm.desktop ] && exit # zzzfm desktop is disabled
[ -e ~/.config/zzzfm/particons_off ] && exit # desktop drive icons are disabled

# set screen position of drive icons
	MAXROW=$(cat ~/.config/zzzfm/row-max)                 # maximum x-axis icons
	CALROW=$(cat ~/.config/zzzfm/row-calc 2>/dev/null)    # calculated drive row
	SELROW=$(cat ~/.config/zzzfm/row-sel 2>/dev/null)     # user-selected drive row
	[ -z "$SELROW" ] && SELROW=$CALROW
	RETURN=$(yad 2>/dev/null --form --field=" Grid Row: :NUM" "$SELROW"\!1..$MAXROW\!1.0\!0 \
		--title="Screen Position of Drive Icons" \
		--borders=20 \
		--text-align=center \
		--text="Select a screen grid row for the position of drive icons.\n\n \
Lower values will align the icons higher on the screen.\n \
Values too low will overlay drive and application icons.\n \
Values too high will wrap drive icons to the screen top.\n\n \
<b>Current Drive Icon Position:</b>  Row $SELROW of $MAXROW\n" \
		--button="Rescan Screen":1 \
		--button="Apply":2 \
		--button="Cancel":0
		) ret=$?
		if [ "$ret" == 1 ]; then
			rm -f ~/.config/zzzfm/row-calc ~/.config/zzzfm/row-sel
			particons
			spacefm-gridrow
			exit
		elif [ "$ret" == 2 ]; then
			echo "$RETURN" | cut -d "|" -f1 > ~/.config/zzzfm/row-sel
			particons
			spacefm-gridrow
			exit
		else
			exit
		fi
