File: floatmon.sh

package info (click to toggle)
herbstluftwm 0.9.5-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,164 kB
  • sloc: cpp: 20,691; python: 10,830; sh: 1,023; ansic: 622; makefile: 98
file content (66 lines) | stat: -rwxr-xr-x 1,914 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/env bash

monitor=floatmon
tag=fl
Mod=${Mod:-Mod1}
Floatkey=${Floatkey:-Shift-f}

hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;}

if which xwininfo &> /dev/null; then
    size=$(xwininfo -root |
           sed -n -e '/^  Width: / {
                          s/.*: //;
                          h
                      }
                      /^  Height: / {
                          s/.*: //g;
                          H;
                          x;
                          s/\n/x/p
                      }')
else
    echo "This script requires the xwininfo binary."
    exit 1
fi

hc chain , add "$tag" , floating "$tag" on
hc or , add_monitor "$size"+0+0 "$tag" "$monitor" \
      , move_monitor "$monitor" "$size"+0+0
hc raise_monitor "$monitor"
hc lock_tag "$monitor"

cmd=(
or  case: and
        # if not on floating monitor
        . compare monitors.focus.name != "$monitor"
        # and if a client is focused
        . get_attr clients.focus.winid
        # then remember the last monitor of the client
        . chain try new_attr string clients.focus.my_lastmon
                try true
        . substitute M monitors.focus.index
            set_attr clients.focus.my_lastmon M
        # and then move the client to the floating tag
        . shift_to_monitor "$monitor"
        . focus_monitor "$monitor"
        . true
    case: and
        # if on the floating monitor
        . compare monitors.focus.name = "$monitor"
        # and if a client is focused
        . get_attr clients.focus.winid
        # then send it back to the original monitor
        . substitute M clients.focus.my_lastmon chain
            , shift_to_monitor M
            , focus_monitor M
        . true
    case: and
        # if the previous things fail,
        # just move to the first monitor
        . shift_to_monitor 0
        . focus_monitor 0
)

hc keybind $Mod-$Floatkey "${cmd[@]}"