code / scripts

Lines748 Shell528 Python72 Lua67 Bourne Again Shell62 make15
1 others 4
Markdown4
(40 lines)
1 #!/usr/bin/env bash
2 # Herbstluftwm: Refocus the last-focused window
4 herbstclient \
5 chain \
6 `# quit existing instances of loop below` \
7 , emit_hook quit_focuslastwindow \
8 `# if the key is pressed` \
9 , keybind Alt-Tab \
10 `# read the content of the my_lastwin attribute` \
11 substitute LASTWIN my_lastwin \
12 `# and jump there` \
13 jumpto LASTWIN \
14 `# create necessary attributes, but do not fail if they already exist` \
15 , silent try new_attr string my_lastwin \
16 , silent try new_attr string my_curwin \
17 `# fill them with the current window id` \
18 , and ,, silent attr clients.focus \
19 ,, substitute WIN clients.focus.winid set_attr my_curwin WIN \
20 ,, substitute WIN clients.focus.winid set_attr my_lastwin WIN \
22 herbstclient -i '(focus_changed|reload|quit_focuslastwindow)' | \
23 while read -r h winid t; do
24 case "$h" in
25 focus_changed)
26 # never feed an 'unfocused' state into the queue
27 # if a window is focused, shift the content of my_curwin into
28 # my_lastwin. Note that we use $winid here and not the content
29 # of clients.focus.winid in order to avoid race conditions.
30 [[ "$winid" != "0x0" ]] && \
31 herbstclient and \
32 , substitute WIN my_curwin set_attr my_lastwin WIN \
33 , set_attr my_curwin "$winid"
34 ;;
35 *) # on any other hook, quit this loop. Note that the idling
36 # herbstclient still lives until the next time a hook arrives
37 # and then quits because it can not write to stdout anymore
38 break ;;
39 esac
40 done