# vim: sw=1:fdm=indent:fdl=0
#
# bspwm hotkeys
#

# Quit bspwm
super + ctrl + Escape
 pkill -x panel; bspc quit

## Desktop

# Move desktop (with focused node) to the left
super + {_,shift} + v
 bspc {desktop -f prev.local,node -d prev.local --follow}; \
 clear_desktops

# Move desktop (with focused node) to the right
super + {_,shift} + l
 last=`cat /tmp/lastdesk`; \
 if [ `bspc query -D -d focused --names` -eq "$last" ]; then; \
  let "last += 1"; \
  echo $last > /tmp/lastdesk; \
  bspc monitor -a $last; \
 fi; \
 bspc {desktop -f next.local,node -d next.local --follow}; \
 clear_desktops

# Send node to a new empty desktop at the far right (and follow)
super + {_,shift} + j
 echo `bspc query -D -d focused --names` > /tmp/desk; \
 last=`cat /tmp/lastdesk`; \
 let "last += 1"; \
 echo $last > /tmp/lastdesk; \
 bspc monitor -a $last; \
 bspc node -d "$last" {_,--follow}; \
 clear_desktops

# Go to last node and back (optionally carrying a node)
super + {_,shift} + n
 old=`cat /tmp/desk`; \
 current=`bspc query -D -d focused --names`; \
 last=`cat /tmp/lastdesk`; \
 if [[ "$current" == "$last" ]]; then; \
   target="$old"; \
 else; \
   target="$last"; \
   echo $current > /tmp/desk; \
 fi; \
 bspc {desktop -f "$target",node -d "$target" --follow}; \
 clear_desktops

# Rotate desktop
super + {q,h}
 bspc node @focused:/ -R {270,90}

# Toggle monitor focus
super + percent
 bspc monitor -f next

# Move node to the other monitor
super + shift + percent
 win=`bspc query -N -n focused`; \
 bspc node -m next; \
 bspc monitor -f next; \
 bspc node -f $win; \
 clear_desktops

# Go to desktop and back
super + {quotedbl,guillemotleft,guillemotright,parenleft,parenright,Delete,at,plus,minus,slash}
 togo={ , , ,1,2,3,4,5,6,7}; \
 old=`cat /tmp/desk`; \
 current=`bspc query -D -d focused --names`; \
 if [[ "$current" == "$togo" ]]; then; \
   target="$old"; \
 else; \
   target="$togo"; \
   echo $current > /tmp/desk; \
 fi; \
 bspc desktop -f "$target"; \
 clear_desktops

# Move node to desktop n and back
super + shift + {quotedbl,guillemotleft,guillemotright,parenleft,parenright,Delete,at,plus,minus,slash}
 togo={ , , ,1,2,3,4,5,6,7}; \
 old=`cat /tmp/desk`; \
 current=`bspc query -D -d focused --names`; \
 if [[ "$current" == "$togo" ]]; then; \
   target="$old"; \
 else; \
   target="$togo"; \
   echo $current > /tmp/desk; \
 fi; \
 bspc node -d "$target" --follow; \
 clear_desktops

# Balance desktop
super + k
 bspc node @focused:/ -B

## node

# Focus/swap to DIR
super + {_,shift + }{t,s,d,r}
 bspc node -{f,s} {west,south,north,east}

# Focus to CYCLE_DIR
super + w
 bspc node -f next.local

# Preselect node to DIR
super + ctrl + {t,s,d,r}
 bspc node -p \~{west,south,north,east}

# Resize node to DIR
super + alt + {t,s,d,r}
 bspc node @{west -r -100,south -r +100,north -r -100,east -r +100}
super + alt + shift + {t,s,d,r}
 bspc node @{east -r -100,north -r +100,south -r -100,west -r +100}

# Toggle floating/pseudo_tiles/fullscreen
super + {y,x,period}
 bspc node -t \~{floating,tiled,fullscreen}

# Move to presel
super + b
 bspc node -n last.!automatic

# Close node
super + {g,agrave}
 bspc node -c

# wm independent hotkeys
#
# File explorer
super + space
 popup Ranger ranger

# Popup utils
# Music
super + a
 popup Music_playlist ncmpcpp -s playlist ; \
 popup Music_media ncmpcpp -s media_library

super + eacute
 popup Music_playlist_home ncmpcpp -s playlist -h 192.168.1.121 ; \
 popup Music_media_home ncmpcpp -s media_library -h 192.168.1.121

# Torrent
super + i
 popup Torrent transmission-remote-cli

# xdotool search --onlyvisible --classname Torrent windowunmap ||\
# xdotool search --classname Torrent windowmap ||\
# kitty --name Torrent transmission-remote-cli

# Wiki
super + u
 popup Wiki nvim ~/Private/vimwiki/index.wiki

# Volume
super + e
 popup Volume pulsemixer

# Weather
super + p
 xdotool search --onlyvisible --classname Meteo windowkill ||\
 kitty --override background_opacity=0 -o background='#000000' -o font_size=9 --hold --name Meteo meteo_display && meteo

# Pin pop-up window
super + shift + space
 bspc node -g sticky=off -t tiled &&\
 xdotool getactivewindow set_window --classname urxvt

# Launcher
super + alt + space
 rofi -font "monofur for Powerline 18" -show

# Show conky
super + c
 if [ `bspc config -d focused left_padding` -gt 0 ]; then;\
   start=500;\
   step=-20;\
   end=0;\
 else;\
   start=0;\
   step=20;\
   end=500;\
 fi;\
 for pad in `seq $start $step $end`; do;\
   bspc config -d focused left_padding $pad;\
 done

# Show calendar
super + m
 if [ `bspc config -d focused right_padding` -gt 0 ]; then;\
   start=500;\
   step=-20;\
   end=0;\
 else;\
   start=0;\
   step=20;\
   end=500;\
 fi;\
 for pad in `seq $start $step $end`; do;\
   bspc config -d focused right_padding $pad;\
 done

# Open terminal
super + ctrl + space
 kitty

# vim everywhere

super + Return
 kitty --name evimwhere nvim '+au BufWritePost * %y+' /dev/null -c 'startinsert';\
 sleep .5;\
 xdotool key ctrl+v

# make sxhkd reload its configuration files:
super + Escape
 pkill -USR1 -x sxhkd

# Lock
super + z
 slimlock

XF86Display
 arandr

XF86MonBrightnessUp
 xbacklight +5

XF86MonBrightnessDown
 xbacklight -5

XF86AudioRaiseVolume
 pactl set-sink-volume 0 +4%;\
 dunstify -r 1234 "`echo -e "\uf028"` `volume -f '%i'`"

XF86AudioLowerVolume
 pactl set-sink-volume 0 -4%;\
 dunstify -r 1234 "`echo -e "\uf027"` `volume -f '%i'`"

XF86AudioMute
 pactl set-sink-mute 0 toggle;\
 dunstify -r 1234 "`echo -e "\uf026"` `volume -f '%s' -d hw:1`"

XF86AudioPlay
 mpc toggle;\
 dunstify -r 1234 "`echo -e "\uf04b\uf04c"`"

Print
 scrot

alt + Print
 scrot -s
