aboutsummaryrefslogtreecommitdiffstats
path: root/herbstluftwm/usr/bin/hlwm-switch-tags
blob: f741ed89bc8c2645f3bdaea641d009b5c6ce534e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env sh
# -*- mode: scheme; -*-
IFS=" "
exec scsh -o define-record-types -s "$0" "$@"
!#
;; 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))