aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2016-09-27 02:43:45 +0200
committerGravatar Tom Willemse2016-09-27 02:43:45 +0200
commited7cd3dc4a91d42fb15e503ebcd850ec81574fd4 (patch)
treebe0a9ceeddd8a19c47be27cb37cb2edbc7966303
parentb0a3ff8fdc537574d14ee81903e8a50f036a8c71 (diff)
downloadnew-dotfiles-ed7cd3dc4a91d42fb15e503ebcd850ec81574fd4.tar.gz
new-dotfiles-ed7cd3dc4a91d42fb15e503ebcd850ec81574fd4.zip
Add tag swapping script
-rwxr-xr-xherbstluftwm/.config/herbstluftwm/autostart2
-rwxr-xr-xherbstluftwm/usr/bin/hlwm-switch-tags48
2 files changed, 50 insertions, 0 deletions
diff --git a/herbstluftwm/.config/herbstluftwm/autostart b/herbstluftwm/.config/herbstluftwm/autostart
index 2a72115..5b17d02 100755
--- a/herbstluftwm/.config/herbstluftwm/autostart
+++ b/herbstluftwm/.config/herbstluftwm/autostart
@@ -75,6 +75,8 @@ hc keybind $Mod-t spawn hlwm-run-or-raise Emacs \
emacsclient --create-frame --alternate-editor=''
# Lock the screen with C-M-l.
hc keybind Control-Mod1-l spawn i3lock --color 000000
+# Swap visible tags
+hc keybind $Mod-x spawn hlwm-switch-tags
# Since I use the colemak keyboard layout, hjkl doesn't make much
# sense. I use neio instead since that is almost in the same place
diff --git a/herbstluftwm/usr/bin/hlwm-switch-tags b/herbstluftwm/usr/bin/hlwm-switch-tags
new file mode 100755
index 0000000..091cf2e
--- /dev/null
+++ b/herbstluftwm/usr/bin/hlwm-switch-tags
@@ -0,0 +1,48 @@
+#!/usr/local/bin/scsh \
+-o define-record-types -s
+!#
+;; hlwm-switch-tags --- Switch the currently visible tags
+;;
+;; Given there are two monitors, get the active tag for each and
+;; switch them around. This saves me the trouble of having to switch
+;; them manually.
+;;
+;; This script depends on herbstluftwm.
+
+(define-record-type monitor :monitor
+ (monitor id tag focus)
+ monitor?
+ (id monitor-id)
+ (tag monitor-tag)
+ (focus monitor-focused?))
+
+(define-record-discloser :monitor
+ (lambda (m) `(monitor ,(monitor-id m) ,(monitor-tag m) ,(monitor-focused? m))))
+
+(define (make-monitor str)
+ (let* ((re (rx bos (submatch (+ digit))
+ ": "
+ (+ digit) "x" (+ digit) "+" (+ digit) "+" (+ digit)
+ " with tag \"" (submatch (+ any)) "\""
+ (submatch (? " [FOCUS]")) eos))
+ (match (regexp-search re str)))
+ (monitor (string->number (match:substring match 1))
+ (match:substring match 2)
+ (> (string-length (match:substring match 3)) 0))))
+
+(define monitors
+ (map make-monitor (run/strings (herbstclient list_monitors))))
+
+(run (herbstclient lock))
+
+(run (herbstclient add switch_tmp))
+(run (herbstclient focus_monitor ,(monitor-id (car monitors))))
+(run (herbstclient use switch_tmp))
+(run (herbstclient focus_monitor ,(monitor-id (cadr monitors))))
+(run (herbstclient use ,(monitor-tag (car monitors))))
+(run (herbstclient focus_monitor ,(monitor-id (car monitors))))
+(run (herbstclient use ,(monitor-tag (cadr monitors))))
+(run (herbstclient focus_monitor ,(monitor-id (find monitor-focused? monitors))))
+(run (herbstclient merge_tag switch_tmp))
+
+(run (herbstclient unlock))