2012-02-23 17:02:11 +01:00
|
|
|
;;;_ Import
|
2012-02-06 21:51:01 +01:00
|
|
|
(use-modules (ice-9 popen)
|
|
|
|
(ice-9 rdelim))
|
|
|
|
|
2012-02-23 17:02:11 +01:00
|
|
|
;;;_ Variables
|
2012-01-30 00:04:07 +01:00
|
|
|
(define modkey 'mod4)
|
2012-02-09 09:09:50 +01:00
|
|
|
(define dmenu-font
|
|
|
|
"-misc-tamsyn-medium-r-normal-*-14-*-*-*-*-*-iso8859-*")
|
2012-02-07 11:07:38 +01:00
|
|
|
(define dmenu-cmd "dmenu")
|
2012-02-07 18:29:46 +01:00
|
|
|
(define dmenu-args
|
2012-02-09 09:09:50 +01:00
|
|
|
(string-append
|
|
|
|
"-b -nb '#000000' -nf '#15abc3' -sb '#e0c625' -sf '#000000' -fn '"
|
|
|
|
dmenu-font "'"))
|
|
|
|
(define dzen-font
|
|
|
|
"-misc-tamsyn-medium-r-normal-*-17-*-*-*-*-*-iso8859-*")
|
2012-02-07 20:07:39 +01:00
|
|
|
(define dzen-cmd "dzen2")
|
2012-02-09 09:09:50 +01:00
|
|
|
(define dzen-args
|
|
|
|
(string-append " -fn '" dzen-font
|
|
|
|
"' -x 5 -y 5 -bg '#000000' -fg '#15abc3'"))
|
2012-02-07 18:29:46 +01:00
|
|
|
(define dzen-pipe '())
|
2012-01-30 00:04:07 +01:00
|
|
|
|
2012-02-08 00:55:02 +01:00
|
|
|
(define previous-tag '())
|
|
|
|
(define current-tag "default")
|
2012-03-28 11:55:49 +02:00
|
|
|
(define terminal "st")
|
2012-02-08 00:55:02 +01:00
|
|
|
|
2012-02-23 17:02:11 +01:00
|
|
|
;;;_ Macros
|
2012-01-30 00:04:07 +01:00
|
|
|
(define-macro (cmd command)
|
|
|
|
`(lambda ()
|
|
|
|
(run-command ,command)
|
|
|
|
(reset-main-binding)))
|
|
|
|
|
2012-02-07 22:10:35 +01:00
|
|
|
(define-macro (create-map name binding . more)
|
|
|
|
`(define (,name)
|
|
|
|
(ungrab-all-keys)
|
|
|
|
(remove-all-keys)
|
|
|
|
(begin ,binding . ,more)
|
|
|
|
(xbindkey-function `(,modkey g) reset-main-binding)
|
|
|
|
(grab-all-keys)))
|
|
|
|
|
2012-02-23 17:02:11 +01:00
|
|
|
;;;_ Functions
|
2012-01-30 00:04:07 +01:00
|
|
|
(define (reset-main-binding)
|
|
|
|
"reset first binding"
|
2012-02-07 18:29:46 +01:00
|
|
|
(close-gui-window)
|
2012-01-30 00:04:07 +01:00
|
|
|
(ungrab-all-keys)
|
|
|
|
(remove-all-keys)
|
|
|
|
(main-binding)
|
|
|
|
(grab-all-keys))
|
|
|
|
|
2012-02-06 21:51:01 +01:00
|
|
|
(define (get-tags)
|
2012-02-07 20:07:39 +01:00
|
|
|
"Get a list of tags"
|
2012-02-06 21:51:01 +01:00
|
|
|
(let* ((file (open-input-pipe
|
|
|
|
"TAGS=( $(herbstclient tag_status 0 | tr \":\\!.+#\" \" \") ); echo ${TAGS[@]}"))
|
|
|
|
(tags (string-split (read-line file) #\ )))
|
|
|
|
(close-port file)
|
2012-02-08 00:55:02 +01:00
|
|
|
(set! tags (delete current-tag tags))
|
|
|
|
(set! tags (delete previous-tag tags))
|
|
|
|
(if (not (null? previous-tag))
|
|
|
|
(append `(,previous-tag) (append tags `(,current-tag)))
|
|
|
|
(append tags `(,current-tag)))))
|
2012-02-06 21:51:01 +01:00
|
|
|
|
2012-02-06 22:25:18 +01:00
|
|
|
(define (choose-tag prompt tags)
|
2012-02-07 00:53:01 +01:00
|
|
|
"Ask to choose a tag"
|
2012-02-06 22:25:18 +01:00
|
|
|
(let* ((file (open-input-pipe
|
|
|
|
(string-append "echo '" (string-join tags "\n")
|
2012-02-07 11:07:38 +01:00
|
|
|
"' | " dmenu-cmd " " dmenu-args " -p '" prompt ":'")))
|
2012-02-06 21:51:01 +01:00
|
|
|
(tag (read-line file)))
|
|
|
|
(close-port file)
|
|
|
|
tag))
|
|
|
|
|
2012-02-23 18:18:51 +01:00
|
|
|
(define (switch-to-tag tag)
|
|
|
|
(let ((tags (get-tags)))
|
2012-02-06 22:25:18 +01:00
|
|
|
(if (string? tag)
|
|
|
|
(begin
|
|
|
|
(if (not (member tag tags))
|
2012-02-07 00:53:01 +01:00
|
|
|
(system (string-append "herbstclient add " tag)))
|
2012-02-08 00:55:02 +01:00
|
|
|
(set! previous-tag current-tag)
|
|
|
|
(set! current-tag tag)
|
2012-02-23 18:18:51 +01:00
|
|
|
(run-command (string-append "herbstclient use " tag))))))
|
|
|
|
|
|
|
|
(define (switch-tags)
|
|
|
|
"Switch to another tag"
|
|
|
|
(let* ((tags (get-tags))
|
|
|
|
(tag (choose-tag "Switch to tag" tags)))
|
|
|
|
(switch-to-tag tag)
|
2012-02-06 22:25:18 +01:00
|
|
|
(reset-main-binding)))
|
|
|
|
|
2012-02-23 18:18:51 +01:00
|
|
|
(define (switch-and-run)
|
|
|
|
"Ask for a command to run, switch to a tag with that name and run
|
|
|
|
the command."
|
|
|
|
(let* ((file (open-input-pipe
|
|
|
|
(string-append "dmenu_pick -p 'Run:' " dmenu-args)))
|
|
|
|
(prog (read-line file)))
|
|
|
|
(close-port file)
|
2012-03-11 11:08:03 +01:00
|
|
|
(if (string? prog)
|
|
|
|
(begin
|
|
|
|
(switch-to-tag prog)
|
|
|
|
(run-command prog)))
|
|
|
|
(reset-main-binding)))
|
2012-02-23 18:18:51 +01:00
|
|
|
|
2012-02-06 22:25:18 +01:00
|
|
|
(define (kill-tag)
|
|
|
|
"Kill a selected tag"
|
|
|
|
(let* ((tags (get-tags))
|
|
|
|
(tag (choose-tag "Kill tag" tags)))
|
|
|
|
(if (string? tag)
|
|
|
|
(begin
|
|
|
|
(if (member tag tags)
|
2012-02-07 00:54:15 +01:00
|
|
|
(run-command (string-append "herbstclient merge_tag " tag)))))
|
2012-02-06 22:25:18 +01:00
|
|
|
(reset-main-binding)))
|
|
|
|
|
|
|
|
(define (move-to-tag)
|
|
|
|
"Move selected window to another tag"
|
|
|
|
(let* ((tags (get-tags))
|
|
|
|
(tag (choose-tag "Move to tag" tags)))
|
|
|
|
(if (string? tag)
|
|
|
|
(begin
|
|
|
|
(if (not (member tag tags))
|
2012-02-07 00:53:01 +01:00
|
|
|
(system (string-append "herbstclient add " tag)))
|
2012-02-06 22:25:18 +01:00
|
|
|
(run-command (string-append "herbstclient move " tag))))
|
2012-02-06 21:51:01 +01:00
|
|
|
(reset-main-binding)))
|
|
|
|
|
2012-02-07 18:29:46 +01:00
|
|
|
(define (text-width font text)
|
|
|
|
(let* ((pipe (open-input-pipe (string-append "textwidth '" font "' '" text "'")))
|
|
|
|
(width (read-line pipe)))
|
|
|
|
(close-port pipe)
|
|
|
|
(if (string? width)
|
|
|
|
(string->number width)
|
|
|
|
-1)))
|
|
|
|
|
|
|
|
(define (gui-print text)
|
2012-02-07 22:10:35 +01:00
|
|
|
(close-gui-window)
|
2012-02-09 09:11:43 +01:00
|
|
|
(let ((width (+ (text-width dzen-font text) 10)))
|
2012-02-07 18:29:46 +01:00
|
|
|
(set! dzen-pipe (open-output-pipe
|
2012-02-07 20:07:39 +01:00
|
|
|
(string-append dzen-cmd " -w " (number->string width)
|
|
|
|
" " dzen-args))))
|
2012-02-07 18:29:46 +01:00
|
|
|
(display text dzen-pipe)
|
|
|
|
(newline dzen-pipe))
|
|
|
|
|
|
|
|
(define (close-gui-window)
|
|
|
|
(if (and (not (null? dzen-pipe))
|
|
|
|
(not (port-closed? dzen-pipe)))
|
|
|
|
(close-pipe dzen-pipe)
|
|
|
|
(set! dzen-pipe '())))
|
|
|
|
|
2012-02-23 17:02:11 +01:00
|
|
|
;;;_ Maps
|
2012-01-30 00:04:07 +01:00
|
|
|
(define (main-binding)
|
|
|
|
"First binding"
|
2012-02-07 11:08:54 +01:00
|
|
|
(xbindkey `(,modkey shift "1") (string-append "dmenu_run -p 'Run:' " dmenu-args))
|
2012-03-15 14:25:09 +01:00
|
|
|
(xbindkey `(,modkey "0") "herbstclient remove")
|
|
|
|
(xbindkey `(,modkey "2") "herbstclient split vertical 0.5")
|
|
|
|
(xbindkey `(,modkey "3") "herbstclient split horizontal 0.5")
|
2012-02-07 22:10:35 +01:00
|
|
|
(xbindkey-function `(,modkey x) X-function-map)
|
|
|
|
(xbindkey-function `(,modkey w) W-function-map)
|
|
|
|
(xbindkey-function `(,modkey s) S-function-map)
|
2012-03-28 11:55:49 +02:00
|
|
|
(xbindkey `(,modkey Return) terminal)
|
2012-01-30 00:04:07 +01:00
|
|
|
(xbindkey '(control alt l) "i3lock -c 000000")
|
|
|
|
(xbindkey '(XF86HomePage) "conkeror")
|
|
|
|
(xbindkey '(XF86Mail) "mutt")
|
|
|
|
(xbindkey '(XF86AudioPlay) "mpc toggle")
|
|
|
|
(xbindkey '(XF86AudioStop) "mpc stop")
|
|
|
|
(xbindkey '(XF86AudioMute) "amixer sset Master toggle")
|
|
|
|
(xbindkey '(XF86AudioLowerVolume) "mcp volume -5")
|
|
|
|
(xbindkey '(XF86AudioRaiseVolume) "mcp volume +5")
|
|
|
|
(xbindkey '(XF86AudioPrev) "mpc prev")
|
|
|
|
(xbindkey '(XF86AudioNext) "mpc next")
|
|
|
|
(xbindkey '(XF86Tools) "ncmpcpp")
|
2012-02-23 09:29:46 +01:00
|
|
|
(xbindkey `(,modkey b) "herbstclient focus left")
|
|
|
|
(xbindkey `(,modkey n) "herbstclient focus down")
|
|
|
|
(xbindkey `(,modkey p) "herbstclient focus up")
|
|
|
|
(xbindkey `(,modkey f) "herbstclient focus right")
|
2012-01-30 00:04:07 +01:00
|
|
|
(xbindkey-function `(,modkey g) reset-main-binding))
|
|
|
|
|
2012-02-07 22:10:35 +01:00
|
|
|
(create-map X-function-map
|
|
|
|
(gui-print "S-x")
|
|
|
|
(xbindkey-function '(b) switch-tags)
|
|
|
|
(xbindkey-function `(,modkey c) (cmd "herbstclient quit"))
|
|
|
|
(xbindkey-function `(,modkey r) (cmd "herbstclient reload"))
|
|
|
|
(xbindkey-function '(k) kill-tag)
|
|
|
|
(xbindkey-function '("0") (cmd "herbstclient remove"))
|
|
|
|
(xbindkey-function '("3") (cmd "herbstclient split horizontal 0.5"))
|
|
|
|
(xbindkey-function '("2") (cmd "herbstclient split vertical 0.5"))
|
|
|
|
(xbindkey-function '(space) (cmd "herbstclient cycle_layout 1"))
|
2012-02-23 18:20:38 +01:00
|
|
|
(xbindkey-function '(f) (cmd "herbstclient floating toggle"))
|
2012-02-07 22:10:35 +01:00
|
|
|
(xbindkey-function '(shift f) (cmd "herbstclient fullscreen toggle"))
|
|
|
|
(xbindkey-function '(p) (cmd "herbstclient pseudotile toggle"))
|
|
|
|
(xbindkey-function '(r) resize-map)
|
2012-02-23 18:20:00 +01:00
|
|
|
(xbindkey-function '(m) move-to-tag)
|
2012-02-23 18:20:38 +01:00
|
|
|
(xbindkey-function `(,modkey f) switch-and-run))
|
2012-02-07 22:10:35 +01:00
|
|
|
|
|
|
|
(create-map W-function-map
|
|
|
|
(gui-print "S-w")
|
|
|
|
(xbindkey-function '(k) (cmd "herbstclient close"))
|
|
|
|
(xbindkey-function '(w) (cmd "herbstclient cycle"))
|
|
|
|
(xbindkey-function '(o) (cmd "herbstclient cycle_all +1"))
|
|
|
|
(xbindkey-function '(b) (cmd "herbstclient focus left"))
|
|
|
|
(xbindkey-function '(n) (cmd "herbstclient focus down"))
|
|
|
|
(xbindkey-function '(p) (cmd "herbstclient focus up"))
|
|
|
|
(xbindkey-function '(f) (cmd "herbstclient focus right"))
|
|
|
|
(xbindkey-function '(shift b) (cmd "herbstclient shift left"))
|
|
|
|
(xbindkey-function '(shift n) (cmd "herbstclient shift down"))
|
|
|
|
(xbindkey-function '(shift p) (cmd "herbstclient shift up"))
|
|
|
|
(xbindkey-function '(shift f) (cmd "herbstclient shift right")))
|
|
|
|
|
|
|
|
(create-map S-function-map
|
|
|
|
(gui-print "S-s")
|
|
|
|
(xbindkey-function '(o) (cmd "herbstclient cycle_monitor")))
|
|
|
|
|
|
|
|
(create-map resize-map
|
|
|
|
(gui-print "Resizing")
|
|
|
|
(xbindkey `(,modkey b) "herbstclient resize left +0.05")
|
|
|
|
(xbindkey `(,modkey n) "herbstclient resize down +0.05")
|
|
|
|
(xbindkey `(,modkey p) "herbstclient resize up +0.05")
|
|
|
|
(xbindkey `(,modkey f) "herbstclient resize right +0.05")
|
|
|
|
(xbindkey-function '(Return) reset-main-binding))
|
2012-01-30 00:04:07 +01:00
|
|
|
|
2012-02-23 17:02:11 +01:00
|
|
|
;;;_ Main
|
2012-01-30 00:04:07 +01:00
|
|
|
(main-binding)
|
2012-02-23 17:02:11 +01:00
|
|
|
|
|
|
|
;;;_ Local Variables
|
|
|
|
;; Local Variables:
|
|
|
|
;; eval: (git-auto-commit-mode 1)
|
|
|
|
;; End:
|