summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorChristoph Egger <christoph@debian.org>2016-02-08 22:20:48 +0100
committerChristoph Egger <christoph@debian.org>2016-02-08 22:20:48 +0100
commita00c6531e911ed7c0fa711843e3ef428489ce70c (patch)
tree79a42e22297ea374fbe1e42553d13cadfad3275f /scripts
parent03c24961fb1b9e6b238a531017746bd1dbc453ba (diff)
Imported Upstream version 0.6.2
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/scratchpad.sh64
1 files changed, 64 insertions, 0 deletions
diff --git a/scripts/scratchpad.sh b/scripts/scratchpad.sh
new file mode 100755
index 00000000..06ba00a1
--- /dev/null
+++ b/scripts/scratchpad.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+# a i3-like scratchpad for arbitrary applications.
+#
+# this lets a new monitor called "scratchpad" appear 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:-scratchpad}"
+hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;}
+
+mrect=( $(hc monitor_rect "" ) )
+
+width=${mrect[2]}
+height=${mrect[3]}
+
+rect=(
+ $((width/2))
+ $((height/2))
+ $((${mrect[0]}+(width/4)))
+ $((${mrect[1]}+(height/4)))
+)
+
+hc add "$tag"
+
+monitor=scratchpad
+
+exists=false
+if ! hc add_monitor $(printf "%dx%d%+d%+d" "${rect[@]}") \
+ "$tag" $monitor 2> /dev/null ; then
+ exists=true
+else
+ # remember which monitor was focused previously
+ hc chain \
+ , new_attr string monitors.by-name."$monitor".my_prev_focus \
+ , substitute M monitors.focus.index \
+ set_attr monitors.by-name."$monitor".my_prev_focus M
+fi
+
+show() {
+ hc lock
+ hc raise_monitor "$monitor"
+ hc focus_monitor "$monitor"
+ hc unlock
+ hc lock_tag "$monitor"
+}
+
+hide() {
+ # if q3terminal still is focused, then focus the previously focused monitor
+ # (that mon which was focused when starting q3terminal)
+ hc substitute M monitors.by-name."$monitor".my_prev_focus \
+ and + compare monitors.focus.name = "$monitor" \
+ + focus_monitor M
+ hc remove_monitor "$monitor"
+}
+
+[ $exists = true ] && hide || show
+