#!/bin/bash
#
# a simple dmenu session script 
#
###

if ! [ -f "$HOME/.dmenurc" ]; then
	cp /usr/share/dmenu/dmenurc $HOME/.dmenurc
fi
. $HOME/.dmenurc

eval $(xdotool getmouselocation --shell)
menu_widht=120
monitor_widht=$(wattr w $(lsw -r))
monitor_height=$(wattr h $(lsw -r))
lines=7
menu_height=$(($lines * 23))
maxx=$(($monitor_widht - $menu_widht))
miny=$PANEL_HEIGHT
maxy=$(($monitor_height - $menu_height))
XP=$X
[[ $XP -gt $maxx ]] && XP=$maxx
YP=$Y
[[ $YP -lt $miny ]] && YP=$miny
[[ $YP -gt $maxy ]] && YP=$maxy

choice=$(echo -e "screenlock\nlogout\nshutdown\nreboot\nsuspend\nhibernate" | rofi -config "~/.config/rofi/config-monocle.rasi" -theme-str "#window { location: northwest; border: 0; width: 140; x-offset: ${XP}px;}" -dmenu -p "Exit")

case "$choice" in
  screenlock) screenlock & ;;
  logout) bspc quit 1 && pkill lemonpanel && pkill lemonbar && pkill conky & ;;
  shutdown) poweroff & ;;
  reboot) reboot & ;;
  suspend) systemctl suspend & ;;
  hibernate) systemctl hibernate & ;;
esac
