code / scripts

Lines748 Shell528 Python72 Lua67 Bourne Again Shell62 make15
1 others 4
Markdown4
(38 lines)
1 #!/usr/bin/env bash
3 # a i3-like scratchpad for arbitrary applications.
4 #
5 # this lets a new monitor called "scratchpad" appear in from the top into the
6 # current monitor. There the "scratchpad" will be shown (it will be created if
7 # it doesn't exist yet). If the monitor already exists it is scrolled out of
8 # the screen and removed again.
9 #
10 # Warning: this uses much resources because herbstclient is forked for each
11 # animation step.
13 # If a tag name is supplied, this is used instead of the scratchpad
15 tag="${1:-scratch}"
16 hc() { herbstclient "$@"; }
18 read -r x y w h <<EOF
19 $(hc monitor_rect)
20 EOF
21 rect=$((w/2))x$((h/2))+$((x+w/4))+$((y+h/4))
22 monitor=scratch
24 hc add "$tag"
25 if ! hc add_monitor "$rect" "$tag" $monitor 2>/dev/null; then
26 hc substitute M monitors.by-name."$monitor".my_prev_focus \
27 and + compare monitors.focus.name = "$monitor" \
28 + focus_monitor M
29 hc remove_monitor "$monitor"
30 else
31 # remember which monitor was focused previously
32 hc chain \
33 , new_attr string monitors.by-name."$monitor".my_prev_focus \
34 , substitute M monitors.focus.index \
35 set_attr monitors.by-name."$monitor".my_prev_focus M
36 hc chain , lock , raise_monitor "$monitor" , focus_monitor "$monitor" \
37 , unlock , lock_tag "$monitor"
38 fi