-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsidebar.sh
executable file
·94 lines (73 loc) · 1.82 KB
/
sidebar.sh
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# a q3-like (or yakuake-like) terminal for arbitrary applications.
#
# this lets a new monitor called "q3terminal" scroll in from the top into the
# current monitor. There the "scratchpad" will be shown (it will be created if
# it doesn't exist yet). If the monitor already exists it is scrolled out of
# the screen and removed again.
#
# Warning: this uses much resources because herbstclient is forked for each
# animation step.
#
# If a tag name is supplied, this is used instead of the scratchpad
tag="${1:-sidebar}"
cur_mon="${2:-0}"
hc() {
#echo "hc $@" >&2 ;
herbstclient "$@" ;
}
mrect=( $(hc monitor_rect -p ${cur_mon} ) )
termwidth=$((${mrect[2]}*3/10))
termheight=${mrect[3]}
rect=(
$termwidth
$termheight
$((${mrect[2]}-$termwidth))
${mrect[1]}
)
x_line=$((${mrect[2]}-$termwidth))
hc add sidebar
monitor=sidebar
exists=false
if ! hc add_monitor $(printf "%dx%d%+d%+d" "${rect[@]}") \
"$tag" $monitor 2> /dev/null ; then
exists=true
fi
update_geom() {
local geom=$(printf "%dx%d%+d%+d" "${rect[@]}")
hc move_monitor "$monitor" $geom
}
steps=5
interval=0.01
animate() {
progress=( "$@" )
for i in "${progress[@]}" ; do
echo $i
rect[2]=$((${x_line}+(i*termwidth)/$steps))
#echo ${rect[@]}
update_geom
sleep "$interval"
done
}
show() {
hc lock
hc raise_monitor $monitor
hc focus_monitor $monitor
hc unlock
hc lock_tag $monitor
#animate $(seq $steps -1 0)
update_geom
}
hide() {
rect=( $(hc monitor_rect "$monitor" ) )
local tmp=${rect[0]}
rect[0]=${rect[2]}
rect[2]=${tmp}
local tmp=${rect[1]}
rect[1]=${rect[3]}
rect[3]=${tmp}
termheight=${rect[1]}
#animate $(seq 0 +1 $steps)
hc remove_monitor $monitor
}
[ $exists = true ] && hide || show