4 from i3ipc
import Connection
, Event
7 def find_parent(i3
, window_id
):
9 Find the parent of a given window id
12 def finder(con
, parent
):
13 if con
.id == window_id
:
15 for node
in con
.nodes
:
16 res
= finder(node
, con
)
21 return finder(i3
.get_tree(), None)
26 Set the layout/split for the currently
27 focused window to either vertical or
28 horizontal, depending on its width/height
33 win
= i3
.get_tree().find_focused()
34 parent
= find_parent(i3
, win
.id)
37 # We never want to set the layout of a single window container,
38 # there are already keys for that. I don't know why i3 even does
39 # this, it is stupid. So, eliminate single window container if we
42 # Alternatively, it could first focus the parent, but I think when
43 # layout changes, we expect new windows to be created within that
45 if (parent
and len(parent
.nodes
) == 1):
46 gp
= find_parent(i3
, parent
.id)
47 if (gp
.nodes
[0].id == parent
.id):
48 if (gp
.layout
== 'splitv'):
49 i3
.command('move down')
50 else: # splith or tabbed
51 i3
.command('move right')
53 if (gp
.layout
== 'splitv'):
56 i3
.command('move left')
57 i3
.command('layout ' + sys
.argv
[1])
64 if __name__
== "__main__":