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
, gp
):
13 if con
.id == window_id
:
15 for node
in con
.nodes
:
16 res
= finder(node
, con
, parent
)
21 return finder(i3
.get_tree(), None, None)
26 Set the layout/split for the currently
27 focused window to either vertical or
28 horizontal, depending on its width/height
31 win
= i3
.get_tree().find_focused()
32 # i don't use gp: todo: revert to original alternating_layout function
33 # which did not return gp.
34 parent
, gp
= 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, we could first focus the parent, but I think when
43 # layout changes, we expect new windows to be created within that
46 # Todo: if the direction we are moving has a split/tabbed container
47 # as a peer to parent, this will move our window into that container
48 # instead of what we want. And in fact, the whole logic below is
49 # incorrect and based on testing which did not realize that fact.
51 if (parent
and parent
.type == 'con' and len(parent
.nodes
) == 1):
52 # https://unix.stackexchange.com/questions/173754/how-to-move-a-window-up-to-the-level-of-its-parent-window-in-i3wm
53 i3
.command('mark i3ha')
54 i3
.command('focus parent')
55 i3
.command('focus parent')
56 i3
.command('mark i3hb')
57 i3
.command('[con_mark="i3ha"] focus')
58 i3
.command('move window to mark i3hb')
59 i3
.command('unmark i3ha')
60 i3
.command('unmark i3hb')
61 i3
.command('layout ' + sys
.argv
[1])
68 if __name__
== "__main__":