-
Notifications
You must be signed in to change notification settings - Fork 0
/
i3_autotiling.sh
executable file
·79 lines (68 loc) · 1.8 KB
/
i3_autotiling.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
#!/bin/sh
# path: /home/klassiker/.local/share/repos/i3/i3_autotiling.sh
# author: klassiker [mrdotx]
# github: https://github.com/mrdotx/i3
# date: 2024-10-26T08:09:37+0200
# speed up script by using standard c
LC_ALL=C
LANG=C
script=$(basename "$0")
help="$script [-h/--help] -- script for optimal tiling of focused windows
Usage:
$script [-w/-t] [command]
Settings:
without options, the script runs in the background and divides the focused
window automatically
[-t] = auto tiling once with defined command
[-w] = auto tiling only on defined workspaces
[command] = application to start
Examples:
$script
$script -w 1 4 5 7 8 9
$script -t $TERMINAL"
autotiling() {
active_workspace=$(wmctrl -d \
| awk '$2=="*" {print $9}' \
)
for workspace in "$@"; do
[ "$active_workspace" -eq "$workspace" ] \
&& break
done
}
set_orientation() {
tmp_file="/tmp/window_event.i3"
i3-msg -t subscribe '[ "window" ]' > "$tmp_file"
# window event change type (https://i3wm.org/docs/ipc.html#_window_event)
case "$(sed -e 's/",.*//' -e 's/{"change":"//' "$tmp_file")" in
new | close | focus)
eval "$(xdotool getwindowfocus getwindowgeometry --shell)" \
&& if [ "$WIDTH" -ge "$HEIGHT" ]; then
i3-msg -q split h
else
i3-msg -q split v
fi
;;
esac
}
case "$1" in
-h | --help)
printf "%s\n" "$help"
;;
-t)
shift
set_orientation
"$@" &
;;
-w)
shift
while true; do
autotiling "$@" \
&& set_orientation
done
;;
*)
while true; do
set_orientation
done
;;
esac