3 # This anticipates when we want to tab windows. There are 2 options of
4 # when to do it: just after a window is created, or just before a window
7 # * Doing it after a window is created allows you to move a window into
8 # the split that only has 1 window, whereas the other way doesn't. For
9 # my use cases, I think I don't really want to move it into the split if
10 # it is a tabbed split. upon further reflection, I've determined that
11 # single window containers are inherently confusing because they tend to
12 # exist and get nested at unexpected times and then it is unclear how to
13 # get rid of them and what is going on and the benefit is generally not
14 # worth it. This command helps identify single window containers during
15 # testing: /a/opt/i3ipc-python/examples/i3-debug-console.py
17 # * Doing it just before a windows is created, you need to call this
18 # script, which means wrapping launch of a program, which I have no way
19 # to do for all cases, I just do it for the common programs I have bound
22 # * Note: doing it just before a window is created also leaves that split behind if
23 # the window is closed, and I don't want single window splits hanging around,
24 # so I close them out in
26 # I have a keybind which disables both, it runs /b/ds/i3-auto-layout-toggle
31 from i3ipc
import Connection
, Event
33 #from pprint import pprint
36 def find_parent(i3
, window_id
):
38 Find the parent of a given window id
41 def finder(con
, parent
, gp
):
42 if con
.id == window_id
:
44 for node
in con
.nodes
:
45 res
= finder(node
, con
, parent
)
50 return finder(i3
.get_tree(), None, None)
55 Set the layout/split for the currently
56 focused window to either vertical or
57 horizontal, depending on its width/height
60 if os
.path
.isfile("/tmp/iank-i3-no-auto"):
63 win
= i3
.get_tree().find_focused()
64 parent
, gp
= find_parent(i3
, win
.id)
67 workspace
= win
.workspace()
68 #pprint(vars(workspace.rect))
70 screen_width
= workspace
.rect
.width
71 screen_height
= workspace
.rect
.height
72 half_w
= screen_width
/ 2 + 1
73 half_h
= screen_height
/ 2 + 1
77 ph
= parent
.rect
.height
78 pw
= parent
.rect
.width
80 # There is potential for future use with < 1920, but I'm
81 # not thinking about it yet.
82 if ( screen_width
< 1920 or parent
.layout
== 'tabbed' or gp
.layout
== 'tabbed'):
85 # print('d2: len(parent.nodes)', len(parent.nodes),' > 1',
86 # 'and ( ph ',ph,' > h + 10',h + 10,' or pw',pw,' > w',w,' )',
87 # 'and w <= half_w',half_w,'+ and h <= half_h',half_h)
89 # h + 10 because a tabbed window loses high compared to its parent.
90 # Note, it is redundant since we check above if the parent is tabbed,
91 # but just being cautious.
92 if (len(parent
.nodes
) > 1
93 and ( ph
> h
+ 10 or pw
> w
)
94 and w
<= half_w
and h
<= half_h
):
95 i3
.command('split vertical, layout tabbed')
99 ### further potential use cases:
101 # We could automatically do a vertical split when there are 2 or 3
102 # horizontal windows.
104 # We could undo a vertical split when we close out windows.
105 # elif (( w == screen_width )); then
106 # # if we had 2 windows on screen, made them vertical splits, then
107 # # closed one, it stays vertical split, but we want it horizontal at
108 # # that point. So, make it horizontal here.
109 # m i3-msg "split horizontal"
117 if __name__
== "__main__":