#
# 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

# 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 "$DESKTOP_SESSION" &

# Reload the Xresources file
mod4 + e ; x
    xrdb -I "$HOME" -merge "$HOME"/.Xresources

# "Theme" mnemonic
mod4 + e ; t
    delight

# 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

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

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

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

ctrl + alt + Delete
    poweroptionsmenu

mod4 + Delete
    poweroptionsmenu

#### 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)"}

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

#### 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"

# 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"
