5 from i3ipc
import Connection
, Event
6 from pprint
import pprint
9 def find_parent(i3
, window_id
):
11 Find the parent of a given window id
14 def finder(con
, parent
, gp
):
15 if con
.id == window_id
:
17 for node
in con
.nodes
:
18 res
= finder(node
, con
, parent
)
23 return finder(i3
.get_tree(), None, None)
26 def focus_hook(i3
, e
):
28 Set the layout/split for the currently
29 focused window to either vertical or
30 horizontal, depending on its width/height
33 if os
.path
.isfile("/tmp/iank-i3-no-auto"):
39 parent
, gp
= find_parent(i3
, e
.container
.id)
41 # This gets rid of tabbed container with single windows.
42 #if (parent and gp and parent.layout == 'tabbed' and len(parent.nodes) == 1):
43 # This gets rid of all single window containers.
44 if (parent
and gp
and len(parent
.nodes
) == 1):
45 i3
.command('mark i3ha')
46 i3
.command('focus parent')
47 i3
.command('focus parent')
48 i3
.command('mark i3hb')
49 i3
.command('[con_mark="i3ha"] focus')
50 i3
.command('move window to mark i3hb')
51 i3
.command('unmark i3ha')
52 i3
.command('unmark i3hb')
56 i3
.on(Event
.WINDOW_FOCUS
, focus_hook
)
60 if __name__
== "__main__":