1#!/usr/local/bin/bash
2
3monitor=floatmon
4tag=fl
5Mod=${Mod:-Mod1}
6Floatkey=${Floatkey:-Shift-f}
7
8hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;}
9
10if which xwininfo &> /dev/null; then
11    size=$(xwininfo -root |
12           sed -n -e '/^  Width: / {
13                          s/.*: //;
14                          h
15                      }
16                      /^  Height: / {
17                          s/.*: //g;
18                          H;
19                          x;
20                          s/\n/x/p
21                      }')
22else
23    echo "This script requires the xwininfo binary."
24    exit 1
25fi
26
27hc chain , add "$tag" , floating "$tag" on
28hc or , add_monitor "$size"+0+0 "$tag" "$monitor" \
29      , move_monitor "$monitor" "$size"+0+0
30hc raise_monitor "$monitor"
31hc lock_tag "$monitor"
32
33cmd=(
34or  case: and
35        # if not on floating monitor
36        . compare monitors.focus.name != "$monitor"
37        # and if a client is focused
38        . get_attr clients.focus.winid
39        # then remember the last monitor of the client
40        . chain try new_attr string clients.focus.my_lastmon
41                try true
42        . substitute M monitors.focus.index
43            set_attr clients.focus.my_lastmon M
44        # and then move the client to the floating tag
45        . shift_to_monitor "$monitor"
46        . focus_monitor "$monitor"
47        . true
48    case: and
49        # if on the floating monitor
50        . compare monitors.focus.name = "$monitor"
51        # and if a client is focused
52        . get_attr clients.focus.winid
53        # then send it back to the original monitor
54        . substitute M clients.focus.my_lastmon chain
55            , shift_to_monitor M
56            , focus_monitor M
57        . true
58    case: and
59        # if the previous things fail,
60        # just move to the first monitor
61        . shift_to_monitor 0
62        . focus_monitor 0
63)
64
65hc keybind $Mod-$Floatkey "${cmd[@]}"
66
67