2 # Herbstluftwm: Refocus the last-focused window
6 `# quit existing instances of loop below` \
7 , emit_hook quit_focuslastwindow \
8 `# if the key is pressed` \
10 `# read the content of the my_lastwin attribute` \
11 substitute LASTWIN my_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
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" ]] && \
32 , substitute WIN my_curwin set_attr my_lastwin WIN \
33 , set_attr my_curwin "$winid"
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