#!/bin/sh

video_selection() {
	slop;
	# wxh startxend
}

record_both() {
	ffmpeg -y \
	-f x11grab \
	-s 1280x720 \
	-i :0.0 \
	-f alsa -i default \
	"$HOME/recordings/out-$(date '+%m%d-%H%M').mkv" &
	echo $! > /tmp/recordingpid
	echo "[rec]" > $HOME/recordings/.recording_status
}

end_recording() { \
	recpid="$(cat /tmp/recordingpid)"
	kill -15 "$recpid"
	echo "[]" > $HOME/recordings/.recording_status
	rm -f /tmp/recordingpid
	sleep 3
	kill -9 "$recpid"
	exit
}

select_recording_type() {
	recording=$(printf "both\nvideo\naudio\nend" | dmenu -i -p "What do:")

	case "$recording" in
		"both")
			record_both;;
		"video")
			;;
		"video_selection")
			video_selection;;
		"audio")
			;;
		"end")
			end_recording;;
	esac
}

case "$1" in
	"both")
		record_both;;
	"end")
		end_recording;;
	*)
		select_recording_type;;
esac
