-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi3zen
More file actions
executable file
·108 lines (100 loc) · 3.85 KB
/
i3zen
File metadata and controls
executable file
·108 lines (100 loc) · 3.85 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# i3zen - move current window to a "clean" workspace,
# put the window between two ghosts (centered).
# if the window already is "zen", move it back to its
# original workspace. If the window is not in zen but
# another window is, both of them will be zen in a tabbed
# container.
#
# https://www.reddit.com/r/i3wm/comments/6x8ajm/oc_i3zen/
# https://gist.github.com/budRich/16765b5468201aa734d0ec1c0870fd0c
I3GET_PATH=$HOME/bin/i3get # this script requires i3get
I3GW_PATH=$HOME/bin/i3gw # this script requires i3gw
# https://www.reddit.com/r/i3wm/comments/6wyarw/oc_i3get/
# https://www.reddit.com/r/i3wm/comments/6x5vgp/oc_i3gw/
# ZEN_WORKSPACE - set this to the workspace number you want to use for zen
# leave it empty if you want the script to use the next empty ws.
ZEN_WORKSPACE=
ZEN_SIZE=75 # how many percent of the screenwidth the zen window is
current=($(${I3GET_PATH} -r nwf)) # id,ws and floating state of current window.
zws=$(${I3GET_PATH} -m centerzen -r w) # check if zen already exist
# if zen ws doesnt exist, create zen layout.
if [[ -z $zws ]]; then
wrks=$(i3-msg -t get_workspaces)
[[ -n $ZEN_WORKSPACE ]] && zws=$ZEN_WORKSPACE || \
zws=$(($(printf "$wrks" | awk -F':' -v RS=',' \
'$1~"num"{fws=$2}
END{print fws}')+1))
${I3GW_PATH} leftzen
${I3GW_PATH} centerzen
${I3GW_PATH} rightzen
i3-msg [con_mark=leftzen] \
move to workspace $zws, layout splith
i3-msg [con_mark=rightzen] \
move to workspace $zws, move to mark leftzen
i3-msg [con_mark=centerzen] \
move to workspace $zws, move to mark leftzen
i3-msg [con_mark=leftzen] move left
i3-msg [con_mark=rightzen] move right
i3-msg [con_mark=centerzen] split h, layout tabbed
[[ ${current[2]#*_} != 'on"' ]] && fs=t || fs=f
i3-msg [con_id=${current[0]}] \
move to workspace $zws, floating disable, \
move to mark centerzen, \
mark "$fs-${current[0]}-${current[1]}"
i3-msg [con_mark=centerzen] \
mark tmpzen, focus, focus parent
i3-msg mark centerzen
i3-msg [con_mark=tmpzen] kill
i3-msg [con_id=${current[0]}] focus
i3-msg workspace $zws
# size the container.
# 33% is the initial width of the container
# if ZEN_SIZE equals 33, don't resize
if [[ $ZEN_SIZE -ne 33 ]]; then
perca=$((ZEN_SIZE-33))
# if perca is less then 0, shrink the container, invert perca
dir=grow
[[ $perca -lt 0 ]] && perca=$((perca*-1)) && dir=shrink
i3-msg [con_id=${current[0]}] \
resize $dir width $perca or $perca ppt
fi
# zen exist but current window isn't there. Send it to zen.
elif [[ $zws != ${current[1]} ]]; then
i3-msg [con_id=${current[0]}] \
move to workspace $zws, \
floating disable, \
move to mark centerzen, \
mark "${current[0]}-${current[1]}", focus
i3-msg workspace $zws
# window is already in zen, send it back to its original ws
elif [[ ${current[2]#*_} != 'on"' ]]; then
mrk=$(${I3GET_PATH} -r m)
mrk=${mrk:2:-2}
ows=${mrk##*${current[0]}'-'}
ofs=${mrk%%'-'${current[0]}*}
i3-msg [con_id=${current[0]}] floating enable, move to workspace $ows
# if zen is empty, kill the zen, let it die
zct=$(i3-msg -t get_tree | awk -v RS=',' -F':' \
' BEGIN{hit="0"}
hit=="2" && $1=="\"focus\"" {print $2;exit}
hit=="1" && $1=="\"swallows\"" && $2=="[]}]"{hit="2"}
$1=="\"marks\"" && $2 ~ "centerzen" {hit="1"}
')
echo the rich "${zct}"
if [[ $zct = '[]' ]] || [[ -z $zct ]]; then
i3-msg [con_mark=leftzen] kill
i3-msg [con_mark=rightzen] kill
i3-msg [con_mark=centerzen] kill
# echo the poor
fi
i3-msg workspace $ows
[[ $ofs != f ]] && i3-msg [con_id=${current[0]}] floating disable
i3-msg [con_id=${current[0]}] focus
# window is on zen ws, but not in zen container (floating)
else
[[ ${current[2]#*_} != 'on"' ]] && fs=t || fs=f
i3-msg [con_id=${current[0]}] \
floating disable, move to mark centerzen, \
mark "$fs-${current[0]}-${current[1]}", focus
fi