a9f76e52afece96693ddfb3b876b0d56d289de76
3 # There are only 2 cases where I want single window split containers.
5 # * just before creating a new window in it.
7 # * When I want to make 1 window a split container and bring an existing
8 # window into it. In vanilla i3, this is super awkward. Usually, you are
9 # starting out focused on the window you want to move into the
10 # container. So, you focus the window which is to become a container,
11 # split it, focus the window you want to join the container, move it
12 # into that container. 4 actions, totally annoying. Lets simplify this
13 # to 2 actions, a key to say what split we want, then a key to say which
14 # direction to move the current window. Since we have a hook that erases
15 # all single window split containers on focus change, we can consider a
16 # single window split container to indicate the split we want.
19 from i3ipc
import Connection
, Event
21 from pprint
import pprint
25 def find_parent(i3
, window_id
):
27 Find the parent of a given window id
30 def finder(con
, parent
, gp
):
31 if con
.id == window_id
:
33 for node
in con
.nodes
:
34 res
= finder(node
, con
, parent
)
39 return finder(i3
.get_tree(), None, None)
44 Set the layout/split for the currently
45 focused window to either vertical or
46 horizontal, depending on its width/height
49 direction
= sys
.argv
[1]
51 win
= i3
.get_tree().find_focused()
52 parent
, gp
= find_parent(i3
, win
.id)
53 layout
= parent
.layout
55 if (parent
and gp
and len(parent
.nodes
) == 1):
56 i3
.command('focus ' + direction
)
59 if os
.path
.exists('/tmp/iank-i3-no-auto'):
62 open('/tmp/iank-i3-no-auto', 'a')
64 if (layout
== 'splith'):
65 i3
.command('split horizontal')
66 elif (layout
== 'splitv'):
67 i3
.command('split vertical')
68 elif (layout
== 'tabbed'):
69 i3
.command('split vertical')
70 i3
.command('layout tabbed')
72 i3
.command('[con_id=%s] focus' % win
.id)
73 i3
.command('move ' + direction
)
75 os
.remove('/tmp/iank-i3-no-auto')
77 i3
.command('move ' + direction
)
86 if __name__
== "__main__":