#!/usr/bin/env bash
#  ____ _____
# |  _ \_   _|  Derek Taylor (DistroTube)
# | | | || |  	http://www.youtube.com/c/DistroTube
# | |_| || |  	http://www.gitlab.com/dwt1/ 
# |____/ |_|  	
#        
# A customized sxhkdrc for the bspwm window manager.
# https://github.com/baskerville/sxhkd
# https://github.com/baskerville/bspwm

### WM INDEPENDENT KEYBINDINGS ###

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

### BSPWM HOTKEYS ###

# terminal emulator
super + Return
	alacritty

# run program launcher
super + shift + Return
	dm-run

# quit/restart bspwm
super + shift + q
	dm-logout

# quit/restart bspwm
super + shift + r
	bspc wm -r

# close and kill
super + shift + c
	bspc node -c

# terminal emulator
super + slash
	dtos-help

# alternate between the tiled and monocle layout
super + space
	bspc desktop -l next

# send the newest marked node to the newest preselected node
super + y
	bspc node newest.marked.local -n newest.!automatic.local

# swap the current node and the biggest node
super + m
	bspc node -s biggest

# STATE/FLAGS

# set the window state
super + {t,shift + t,s,f}
	bspc node -t {tiled,pseudo_tiled,floating,fullscreen}

# set the node flags
super + ctrl + {m,x,y,z}
	bspc node -g {marked,locked,sticky,private}

# FOCUS/SWAP

# focus the node in the given direction
super + {_,shift + }{h,j,k,l}
	bspc node -{f,s} {west,south,north,east}

# focus the node for the given path jump
super + {shift + p, shift + b, ctrl + f, ctrl + s}
	bspc node -f @{parent,brother,first,second}

# focus the next/previous node in the current desktop
super + {_,shift + }n
	bspc node -f {next,prev}.local

# focus the next/previous desktop in the current monitor
super + {Left, Right}
 	bspc desktop -f {prev,next}.local

# focus the next/previous monitor
super + {comma, period}
    bspc monitor -f {prev,next}

super + {shift + comma, shift + period}
    bspc node -s {prev,next}

# focus the last node/desktop
super + {shift + Tab,Tab}
	bspc {node,desktop} -f last

# focus the older or newer node in the focus history
super + {o,i}
	bspc wm -h off; \
	bspc node {older,newer} -f; \
	bspc wm -h on

# focus or send to the given desktop
super + {_,shift + }{1-9,0}
	bspc {desktop -f,node -d} focused:'^{1-9,10}'

# PRESELECT

# preselect the direction
super + ctrl + {h,j,k,l}
	bspc node -p {west,south,north,east}

# preselect the ratio
super + ctrl + {1-9}
	bspc node -o 0.{1-9}

# cancel the preselection for the focused node
super + ctrl + space
	bspc node -p cancel

# cancel the preselection for the focused desktop
super + ctrl + shift + space
	bspc query -N -d | xargs -I id -n 1 bspc node id -p cancel

# MOVE/RESIVE
# shrink/expand
ctrl + alt + h
	bspc node -z {left -20 0} || bspc node -z {right -20 0}
ctrl + alt + j
	bspc node -z {bottom 0 20} || bspc node -z {top 0 20}
ctrl + alt + k
	bspc node -z {bottom 0 -20} || bspc node -z {top 0 -20}
ctrl + alt + l
	bspc node -z {left 20 0} || bspc node -z {right 20 0}

# move a floating window
super + {Left,Down,Up,Right}
	bspc node -v {-20 0,0 20,0 -20,20 0}

# launch qutebrowser
super + b
    qutebrowser "https://distro.tube"

# dmscripts (SUPER + p followed by another key)
super + p; h
    dm-hub
super + p; {a}
    dm-sounds
super + p; {b}
    dm-setbg
super + p; {c}
    dtos-colorscheme
super + p; {shift + c}
    dm-colpick
super + p; {e}
    dm-confedit
super + p; {i}
    dm-maim
super + p; {k}
    dm-kill
super + p; {m}
    dm-man
super + p; {n}
    dm-note
super + p; {o}
    dm-bookman
super + p; p
    passmenu -p Pass:
super + p; {q}
    dm-logout
super + p; {r}
    dm-radio
super + p; {s}
    dm-websearch
super + p; {t}
    dm-translate

# emacs (SUPER + e followed by another key)
super + e; e
    emacsclient -c -a 'emacs'
super + e; a
    emacsclient -c -a 'emacs' --eval '(emms)' --eval '(emms-play-directory-tree \"~/Music/\")'
super + e; b
    emacsclient -c -a 'emacs' --eval '(ibuffer)'
super + e; d
    emacsclient -c -a 'emacs' --eval '(dired nil)'
super + e; i
    emacsclient -c -a 'emacs' --eval '(erc)'
super + e; n
    emacsclient -c -a 'emacs' --eval '(elfeed)'
super + e; s
    emacsclient -c -a 'emacs' --eval '(eshell)'
super + e; v
    emacsclient -c -a 'emacs' --eval '(+vterm/here nil)'
super + e; w
    emacsclient -c -a 'emacs' --eval '(doom/window-maximize-buffer(eww "distro.tube"))'
