#
# SXHKD module with WM-agnostic keys
#
# Part of my dotfiles: https://gitlab.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://gitlab.com/protesilaos/dotfiles
#
# Note that `mod3' is the Hyper key, which I enable via Xmodmap (see my
# bspwmrc and relevant configs).


# Environment
# -----------

# I am using the prefix `mod3 + e' as a mnemonic for "environment".
#
# The following commands are:
#
# f == bspwm focus mode (my script)
# s == reload sxhkd
# p == reload melonpanel (my lemonbar script)
# t == dmenu to choose Tempus theme
# x == reload the Xresources file
mod3 + e ; {f,s,p,t,x}
    { \
    bspwm_focus_mode, \
    pkill -USR1 -x sxhkd && notify-send -i key_bindings "Reloaded key bindings", \
    pkill -x melonpanel && melonpanel, \
    tempusmenu, \
    xrdb -I "$HOME" -merge "$HOME"/.Xresources \
    }

# Invoke the session management menu (log out, lock, reboot, shutdown).
ctrl + alt + Delete
     poweroptionsmenu

# Keyboard layout
# ---------------
# We can set the keyboard layouts, as well as the toggle directly via
# `setxkbmap`.  Example of what I used to run:
#
#	setxkbmap -layout 'us,gr' -option 'grp:alt_caps_toggle'
#
# However, doing so means losing out on the possibility to easily find
# out the current/active layout from a script: X knows about "us,gr" in
# that order, not which one is currently typing.  As such, in `bspwmrc`
# I simply autostart `setxkbmap -layout 'us'` without defining the
# second layout and a toggle.  The toggle is set below.  With the
# difference being that it invokes a custom script that switches between
# the us,gr layout.  All this is done to be able to get the active
# keyboard layout and print its name to my system panel (custom lemonbar
# called "melonpanel").
#
# The key chord is based on the Emacs function `toggle-input-method',
# which is bound to C-\
mod3 + backslash
	toggle_kbd_layout

# Main programs
# -------------

# Use Xterm as a standalone tool or with Tmux (with Shift).
mod3 + {_, shift + } Return
	{xterm,xterm -e tmux new-session -A -s 'Default'}

# Show the desired rofi views.
mod3 + {x,b}
     rofi -show {drun,window}

# Bring up a rofi interface for `pass' (the superb UNIX password
# manager).
mod3 + p
     passmenu

# 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).
# Note that `scrot` also has an interactive mode that I do not use.
Print
	scrot -u -z '%Y-%m-%d_%H:%M:%S_$wx$h$n.png' -e 'mv $f ~/Desktop' \
    && notify-send -i gnome-screenshot "Window view screenshot" "Saved image to Desktop"
mod3 + Print
	scrot -m -z '%Y-%m-%d_%H:%M:%S_$wx$h.png' -e 'mv $f ~/Desktop' \
    && notify-send -i gnome-screenshot "Screen view screenshot" "Saved image to Desktop"

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


# Specifically for `bongo', my Emacs music manager.
XF86Audio{Play,Prev,Next}
	emacsclient -e { \
    "(bongo-pause/resume)", \
    "(bongo-previous)", \
    "(bongo-next)" \
    }

# Control the [last] currently active player.
mod3 + 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
mod3 + 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
# mod3 + {F1,Home}
# 	xterm -class "my_float_window" \
# 	-geometry '100x30' -e less "$HOME/.config/sxhkd/cheatsheet_sxhkdrc.txt"
