From 7549f63e043f6cb457dc44b5b4aadc2f202b4e48 Mon Sep 17 00:00:00 2001 From: Protesilaos Stavrou Date: Wed, 22 May 2019 22:26:42 +0300 Subject: [PATCH] MAJOR CHANGES: Review sxhkd and make it modular MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Work in progress, which requires further testing and might not be merged into `master`… 1. Review several key bindings that control BSPWM. Specifically: 1. Simplify the navigation through the node focus history. Remove some keys, refine the behaviour of others. Cycling through the available nodes is desktop-specific and uses the familiar Alt and Tab combo. 2. Add support for swapping the current window with the biggest one on the current desktop (super + {b,z}). Doing this while also holding down the shift key will switch back to the last focused window. 2. Create a new set of key chords that, once active, do not require repeated key presses that involve the modifiers. I call this "continuous mode" and thus start all chord chains with "super + c". This is the inline description I wrote: The following key chords have a colon sign `:' before their last part. By pressing the keys to the left of the colon, you can then pass the commands by only using the keys to the right of the colon. This eliminates the need for repeated chord presses that involve the modifier keys. Exit the mode with "Escape". An example is in order. In my config, there is a definition which allows you to resize gaps by holding down "super + shift" and then pressing either of the brackets. The left bracket decrements the gap size, while the right bracket increments it. Every action requires you to keep pressing all those keys together. Whereas in "continuous mode", you would activate the mode with "super + c" and then {de,in}crement the gaps by only pressing the brackets. No need for holding down any modifier keys. 3. Create domain-specific configuration files. Currently there are two: (i) one with BSPWM-specific commands, (ii) another with WM-agnostic ones. The intention of the multiple configs (aka "modules") is to improve readability. This is the area that requires more testing. --- bspwm/.config/bspwm/bspwmrc | 2 +- bspwm/.config/sxhkd/sxhkdrc | 157 ++-------------------------- bspwm/.config/sxhkd/sxhkdrc_bspc | 170 +++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 150 deletions(-) create mode 100644 bspwm/.config/sxhkd/sxhkdrc_bspc diff --git a/bspwm/.config/bspwm/bspwmrc b/bspwm/.config/bspwm/bspwmrc index 93315328..b57c86fc 100755 --- a/bspwm/.config/bspwm/bspwmrc +++ b/bspwm/.config/bspwm/bspwmrc @@ -56,7 +56,7 @@ bspc config presel_feedback_color "#2a2829" # feedback for manual node split # The hotkey daemon that handles all custom key bindings, including the # ones that control BSPWM -sxhkd & +sxhkd -c "$HOME/.config/sxhkd/"sxhkdrc* & # Launch my custom Lemonbar implementation if [ "$(command -v melonpanel 2> /dev/null)" ]; then diff --git a/bspwm/.config/sxhkd/sxhkdrc b/bspwm/.config/sxhkd/sxhkdrc index 23726e13..4f021e18 100644 --- a/bspwm/.config/sxhkd/sxhkdrc +++ b/bspwm/.config/sxhkd/sxhkdrc @@ -1,19 +1,19 @@ # +# SXHKD module with WM-agnostic keys +# # ~/.config/sxhkd/sxhkdrc # # Description # =========== # -# 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 +# 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 # -# Most commands are derived from `man bspc|bspwm` and `man sxhkd`. Each -# action is preceded by comments which explain what it does. -# -# Last full review on 2018-11-07 -# Last major edit on 2019-04-01 +# Last full review on 2019-05-22 + + # Index with key chord chain mnemonics # ==================================== @@ -28,13 +28,7 @@ # Assign (node flags): super + a ; ... # Split (split ratios): super + s ; ... -# FIXME key chain chords in the form of `super + n ; ...` have a bug See -# https://github.com/baskerville/sxhkd/issues/83. The awkward -# workaround is to use this syntax instead `super + n; X ; ...`, where X -# is a variable. -# General key chords that do not invoke BSPC -# ========================================== # Keyboard layout # --------------- @@ -234,138 +228,3 @@ XF86AudioMicMute super + XF86Audio{Mute,LowerVolume,RaiseVolume} amixer set Capture {toggle,5%-,5%+} -# BSPWM operations for window management -# ====================================== - -# Close or kill currently focused node -super + {_,shift + }q - bspc node -{c,k} - -# Node layout state and flags -# --------------------------- - -# Toggle monocle layout (maximise focused node). If you use `-l -# monocle` you lose the toggle functionality. -super + m - bspc desktop -l next - -# Toggle tiled, pseudo_tiled, floating, fullscreen view. Tiled is what -# is used by default. Pseudo-tiled presents the window in its original -# dimensions inside the split it would normally occupy as a tile (I have -# never found a practical use for this). Floating windows have their -# own dimensions and can be stacked on top of each other. -# -# NOTE the presence of the tilde ~. If current state matches the given -# state, then the argument is interpreted as the last state. -super + {t,shift + space,space,f} - bspc node -t ~{tiled,pseudo_tiled,floating,fullscreen} - -# Set the node flags. Locked is a node that cannot be closed with `bspc -# node --close`. Sticky stays in the focused desktop. Private tries to -# keep its dimensions and tiling position. -# -# There also are flags for "hidden" and "marked" but I have yet to find -# any practical use for them. -super + a ; {l,s,p} - bspc node -g {locked,sticky,private} - -# Set the split ratio on demand -super + s ; {2,3} - bspc config split_ratio { \ - 0.50 && notify-send "BSPWM configuration" "Split ratio set to 0.50", \ - 0.66 && notify-send "BSPWM configuration" "Split ratio set to 0.66" \ - } - -# Make node split ratios equal or balanced. -super + s ; {e,b} - bspc node @/ {--equalize,--balance} - -# Focus/swap nodes/desktops -# ------------------------- - -# Focus the node in the given direction (select window). -super + {_,shift + }{h,j,k,l} - bspc node -{f,s} {west,south,north,east} - -# Focus {or send focused node} to the given desktop. -super + {_,shift + }{1-9,0} - bspc {desktop -f,node -d} '^{1-9,10}' - -# Send and follow focused node to given desktop. -super + ctrl + shift + {1-9} - id=$(bspc query -N -n); bspc node -d ^{1-9}; bspc node -f ${id} - -# Expand or contract node in the given direction. -# -# For floating windows one can use Alt + Right Mouse click to -# drag/resize in the given direction (this works in other DEs as well, -# such as MATE and Xfce). I have not set the script to resize floating -# windows because: (i) I do not use them and if I do I do not want to -# change their dimensions, and (ii) to keep the script concise. -super + ctrl + {h,j,k,l} - own_script_bspwm_node_resize {west,south,north,east} 50 - -# Move a floating window with the arrow keys (else use Alt + Left Mouse -# Click to drag). I seldom use floating windows. -super + shift + {Left,Down,Up,Right} - bspc node -v {-20 0,0 20,0 -20,20 0} - -# FIXME TODO on focus history (see following three commands) -# -# 1. Can Alt+Tab work like the standard Alt+Tab implementation where -# releasing the key on the first occurrence rewrites the focus -# history so the next Alt+Tab brings you to the previous window? -# 2. Research how to consolidate these in fewer keystrokes on something -# that makes more sense. Too many options that provide overlapping -# functions. - -# Focus the last node/desktop. This only cycles through the active and -# the last active node. Compare it to the behaviour of the following -# two commands. -super + {grave,Tab} - bspc {node,desktop} -f last - -# Focus on older/newer window in history. This does not cycle through -# windows. It stops once reaching the {old,new}est. -super + {o,n} - bspc wm --record-history off; \ - bspc node --focus {older,newer}; \ - bspc wm --record-history on - -# Focus next/previous window. This does cycle through windows. -alt + {_,shift +} Tab - bspc node -f {next,prev} - -# preselect -# --------- -# NOTE there also is an option to insert a "receptacle", but I have -# found no use for it yet. Not included herein. - -# Preselect the direction or insert again to cancel the preselection. -# This enters the manual mode. -super + alt + {h,j,k,l} - bspc node --presel-dir '~{west,south,north,east}' - -# Preselect the ratio. The default value is 0.5, defined in `bspwmrc`. -super + alt + {1-9} - bspc node -o 0.{1-9} - -# Manipulate the workspace -# ------------------------ - -# Rotate all windows [counter-]clockwise by 90 degrees. -super + {_,shift + }r - bspc node @/ --rotate {90,-90} - -# Flip desktop: what is on the right/top moves to the left/bottom and -# vice versa. -super + alt + {_,shift + }r - bspc node @/ --rotate {180,-180} - -# Switch between gap presets. -super + shift + {y,u,i,o} - bspc config window_gap {0,5,10,20} - -# Dynamic gaps. -super + shift + bracket{left,right} - bspc config -d focused window_gap $((`bspc config -d focused window_gap` {-,+} 5 )) diff --git a/bspwm/.config/sxhkd/sxhkdrc_bspc b/bspwm/.config/sxhkd/sxhkdrc_bspc new file mode 100644 index 00000000..7858c19f --- /dev/null +++ b/bspwm/.config/sxhkd/sxhkdrc_bspc @@ -0,0 +1,170 @@ +# +# SXHKD module with BPSWM-specific commands +# +# ~/.config/sxhkd/sxhkdrc_bspc +# + +# 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 +# +# Last full review on 2019-05-22 + + + +# Close or kill currently focused node +super + {_,shift + }q + bspc node -{c,k} + +# Focus/swap nodes/desktops +# ------------------------- + +# Focus {or swap} the node in the given direction. +super + {_,shift + }{h,j,k,l} + bspc node -{f,s} {west,south,north,east} + +# Focus {or send focused node to} the given desktop. +super + {_,shift + }{1-9,0} + bspc {desktop -f,node -d} '^{1-9,10}' + +# Send and follow focused node to given desktop. +super + ctrl + shift + {1-9} + id=$(bspc query -N -n); bspc node -d ^{1-9}; bspc node -f ${id} + +# Expand or contract node in the given direction. +# +# For floating windows one can use Alt + Right Mouse click to +# drag/resize in the given direction (this works in other DEs as well, +# such as MATE and Xfce). I have not set the script to resize floating +# windows because: (i) I do not use them and if I do I do not want to +# change their dimensions, and (ii) to keep the script concise. +super + ctrl + {h,j,k,l} + own_script_bspwm_node_resize {west,south,north,east} 50 + +# Move a floating window with the arrow keys (else use Alt + Left Mouse +# Click to drag). I seldom use floating windows. +super + shift + {Left,Down,Up,Right} + bspc node -v {-20 0,0 20,0 -20,20 0} + +# Focus the last node/desktop. This only cycles through the active and +# the last active node. Compare it to the behaviour of the following +# two commands. +super + {grave,Tab} + bspc {node,desktop} -f last + +# Focus {next,previous} window in the current desktop. This does cycle +# through windows. +alt + {_,shift +} Tab + bspc node -f {next,prev}.local + +# Swap current window with the biggest one in the present desktop. +# Using it with shift will focus back to the last node. The keys {b,z} +# are chosen as mnemonics for Biggest/Back or Zoom in/out… +super + {_,shift +} {b,z} + bspc node {-s biggest.local,-f last} + +# preselect +# --------- +# NOTE there also is an option to insert a "receptacle", but I have +# found no use for it yet. Not included herein. + +# Preselect the direction or insert again to cancel the preselection. +# This enters the manual mode. +super + alt + {h,j,k,l} + bspc node --presel-dir '~{west,south,north,east}' + +# Preselect the ratio. The default value is 0.5, defined in `bspwmrc`. +super + alt + {1-9} + bspc node -o 0.{1-9} + +# Node layout state and flags +# --------------------------- + +# Toggle monocle layout (maximise focused node). If you use `-l +# monocle` you lose the toggle functionality. +super + m + bspc desktop -l next + +# Toggle tiled, pseudo_tiled, floating, fullscreen view. Tiled is what +# is used by default. Pseudo-tiled presents the window in its original +# dimensions inside the split it would normally occupy as a tile (I have +# never found a practical use for this). Floating windows have their +# own dimensions and can be stacked on top of each other. +# +# NOTE the presence of the tilde ~. If current state matches the given +# state, then the argument is interpreted as the last state. +super + {t,shift + space,space,f} + bspc node -t ~{tiled,pseudo_tiled,floating,fullscreen} + +# Set the node flags. Locked is a node that cannot be closed with `bspc +# node --close`. Sticky stays in the focused desktop. Private tries to +# keep its dimensions and tiling position. +# +# There also are flags for "hidden" and "marked" but I have yet to find +# any practical use for them. +super + a ; {l,s,p} + bspc node -g {locked,sticky,private} + +# Set the split ratio on demand +super + s ; {2,3} + bspc config split_ratio { \ + 0.50 && notify-send "BSPWM configuration" "Split ratio set to 0.50", \ + 0.66 && notify-send "BSPWM configuration" "Split ratio set to 0.66" \ + } + +# Make node split ratios equal or balanced. The former applies to the +# root of the tree, the latter to the parent node. +super + s ; {e,b} + bspc node {@/ --equalize,@parent --balance} + +# Manipulate the workspace +# ------------------------ + +# Rotate all windows [counter-]clockwise by 90 degrees. +super + {_,shift + }r + bspc node @/ --rotate {90,-90} + +# Flip desktop: what is on the right/top moves to the left/bottom and +# vice versa. +super + alt + {_,shift + }r + bspc node @/ --rotate {180,-180} + +# Switch between gap presets. +super + shift + {y,u,i,o} + bspc config window_gap {0,5,10,20} + +# Dynamic gaps. +super + shift + bracket{left,right} + bspc config -d focused window_gap "$(($(bspc config -d focused window_gap) {-,+} 5 ))" + + + +# Continuous input mode +# ===================== +# EXPLAIN: The following key chords have a colon sign `:' before their +# last part. By pressing the keys to the left of the colon, you can +# then pass the commands by only using the keys to the right of the +# colon. This eliminates the need for repeated chord presses that +# involve the modifier keys. Exit the mode with "Escape". +# +# NOTE: All of the following are mirrors of their afore-mentioned +# couterparts. + +# Focus {or swap with node} in the given direction. +super + c : {_,shift + } {h,j,k,l} + bspc node -{f,s} {west,south,north,east} + +# Gaps presets. +super + c : {y,u,i,o} + bspc config window_gap {0,5,10,20} + +# Mode for dynamic gaps. +super + c : bracket{left,right} + bspc config -d focused window_gap "$(($(bspc config -d focused window_gap) {-,+} 5 ))" + +# Move floating windows with the arrow keys +super + c : {Left,Down,Up,Right} + bspc node -v {-20 0,0 20,0 -20,20 0}