#
# SXHKD module with WM-agnostic keys
#
# Part of my dotfiles: <https://github.com/protesilaos/dotfiles>.
#

### Description
#
# Partial configuration file for the Simple X Hotkey Daemon.  Meant to
# work with `bspwm`.  This is part of my dotfiles, which are managed
# with GNU Stow.  See https://github.com/protesilaos/dotfiles

### Code:

#### Environment

# Xorg tiling window manager focus mode (my script)
mod4 + e ; f
    xtwm_focus_mode.sh

# Reload sxhkd
mod4 + e ; s
    pkill -USR1 -x sxhkd && notify-send -i key_bindings "Reloaded key bindings"

# Reload polybar (NOTE: check the panel names in its config)
mod4 + e ; p
    pkill -x polybar && polybar -rq "$DESKTOP_SESSION" &

# Reload the Xresources file
mod4 + e ; x
    xrdb -I "$HOME" -merge "$HOME"/.Xresources  && notify-send -i xterm "Reloaded Xresources"

# "Theme" mnemonic
mod4 + e ; t
    delight.sh

# Also use the F5 as it is what I have in Emacs to switch themes.  It
# makes sense for Super+F5 to do the same for the environment.
mod4 + F5
    delight.sh

mod4 + e ; d ; {q,Q,c,h}
    dunstctl {close,close-all,context,history-pop}

# 'dunst_toggle_notify.sh' is a shell script of mine.  Check my dotfiles.
# It pauses notifications.
mod4 + e ; d ; p
    dunst_toggle_notify.sh

# Invoke the session management menu (log out, lock, reboot, shutdown).
mod4 + e ; Delete
    poweroptionsmenu.sh

ctrl + alt + Delete
    poweroptionsmenu.sh

mod4 + Delete
    poweroptionsmenu.sh

#### Main programs

# # The -a "" tries to start the daemon and connect to it, if it is missing.
# mod4 + {_, shift +,ctrl + shift + } Return
#     {uxterm,emacsclient -w 2 -a "" -e "(prot-window-shell)",emacsclient -w 2 -a "" -e "(prot-window-coach)"}

mod4 + Return
    x-terminal-emulator

# Show the desired rofi views for "buffers" (windows) and desktop
# applications.
mod4 + {b,d}
    rofi -show {window,drun}

# Run `org-capture`, `tmr`, or `prot-project-switch` in a popup frame that is deleted after you are done.
mod4 + p ; {o,t,p}
    emacsclient -e "({prot-window-popup-org-capture,prot-window-popup-tmr,prot-window-popup-prot-project-switch})"

#### Miscellaneous tools and media keys


# # Screenshots (requires `scrot`).  First one is for the focused window.
# # The other is of the entire X session (including all active monitors).
# Print
#     scrot -u -z '%Y-%m-%d_%H:%M:%S_$wx$h$n.png' -e 'mv $f ~/Pictures' \
#     && notify-send -i gnome-screenshot "Window view screenshot" "Saved image to Pictures"
# mod4 + Print
#     scrot -m -z '%Y-%m-%d_%H:%M:%S_$wx$h.png' -e 'mv $f ~/Pictures' \
#     && notify-send -i gnome-screenshot "Screen view screenshot" "Saved image to Pictures"
# mod4 + shift + Print
#     scrot -s -l style=solid,width=3,color="#999999" -f '%Y-%m-%d_%H:%M:%S_$wx$h.png' -e 'mv $f ~/Pictures' \
#     && notify-send -i gnome-screenshot "Region view screenshot" "Saved image to Pictures"

# Screenshots with the `maim` program.
Print
    maim -i $(xdotool getactivewindow) ~/Pictures/Screenshots/$(date +%Y%m%dT%H%M%S)__window.png && notify-send -i gnome-screenshot "Window screenshot" "Saved image to ~/Pictures/Screenshots"
mod4 + Print
    maim -u ~/Pictures/Screenshots/$(date +%Y%m%dT%H%M%S)__desktop.png && notify-send -i gnome-screenshot "Desktop screenshot" "Saved image to ~/Pictures/Screenshots"
shift + Print
    maim -s -b 3 -c "1,0.5,0.3,1" ~/Pictures/Screenshots/$(date +%Y%m%dT%H%M%S)__selection.png && notify-send -i gnome-screenshot "Selection screenshot" "Saved image to ~/Pictures/Screenshots"


# Control the laptop's screen brightness (requires `xbacklight`).
XF86MonBrightness{Down,Up}
    xbacklight {-dec 15,-inc 15}

# Control the [last] currently active player.
XF86Audio{Play,Prev,Next}
    playerctl {play-pause,previous,next}

# Speaker/output volume.  Requires `amixer` and dedicated keys.
XF86Audio{Mute,LowerVolume,RaiseVolume}
    amixer set Master {toggle,5%-,5%+}

# Microphone/input volume.  Same requirements as previous definition.
XF86AudioMicMute
    amixer set Capture toggle
mod4 + XF86Audio{Mute,LowerVolume,RaiseVolume}
    amixer set Capture {toggle,5%-,5%+}

# TODO 2019-11-01: These will need to be reviewed once all key bindings
# are rewritten.  Perhaps it would be nice to produce something that is
# interactive and searchable…
# # Bring up the help text for common keybindings
# mod4 + {F1,Home}
#   uxterm -class "my_float_window" \
#   -geometry '100x30' -e less "$HOME/.config/sxhkd/cheatsheet_sxhkdrc.txt"
