improve licensing
[distro-setup] / i3-split-maybe
1 #!/bin/bash
2
3 set -e; . /usr/local/lib/bash-bear; set +e
4
5 # We use this along with
6 # /a/opt/i3-alternating-layout/alternating_layouts.py to anticipate when
7 # we want to split/tab windows. There are 2 options of when to do it:
8 # just after a window is created, or just before a window is
9 # created. Doing it after a window is created allows you to move a
10 # window into the split that only has 1 window, whereas the other way
11 # doesn't. For my use cases, I think I don't really want to move it into
12 # the split if it is a tabbed split.
13 #
14 # I have a keybind which disables both, it runs /b/ds/i3-auto-layout-toggle
15
16 if [[ -e /tmp/iank-i3-no-auto ]]; then
17 exit 0
18 fi
19
20
21 tmp=$(mktemp)
22
23 i3-msg -t get_workspaces | jq ".[]| select(.focused==true) | .rect | .width" >$tmp
24
25 { read -r screen_width; read -r screen_height; } <$tmp
26
27 i3-msg -t get_tree | jq -r ".. | select(.focused? == true).rect | .width, .height" >$tmp
28
29 half_w=$(( screen_width / 2 + 100 ))
30 half_h=$(( screen_height / 2 + 100 ))
31
32
33 { read -r w; read -r h; } <$tmp
34
35
36 if (( screen_width < 1920 )); then
37 # haven't considered this case yet
38 exit 0
39 fi
40
41 if (( w < half_w && h < half_h )); then
42 i3-msg "split vertical, layout tabbed"
43 fi
44
45 rm -f $tmp