X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=i3-event-hook;fp=i3-event-hook;h=01514a648d6017aa0b2f5bf58f9c6b38433946d7;hb=dab96f8fa4c701db13ba734fa0c07b5d12fc8fae;hp=0000000000000000000000000000000000000000;hpb=e6cd2e555df3af0cf23da016b833529a34ffc84c;p=distro-setup diff --git a/i3-event-hook b/i3-event-hook new file mode 100755 index 0000000..01514a6 --- /dev/null +++ b/i3-event-hook @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import sys +import os +from i3ipc import Connection, Event +from pprint import pprint + + +def find_parent(i3, window_id): + """ + Find the parent of a given window id + """ + + def finder(con, parent, gp): + if con.id == window_id: + return (parent, gp) + for node in con.nodes: + res = finder(node, con, parent) + if res: + return res + return None + + return finder(i3.get_tree(), None, None) + + +def focus_hook(i3, e): + """ + Set the layout/split for the currently + focused window to either vertical or + horizontal, depending on its width/height + """ + + if os.path.isfile("/tmp/iank-i3-no-auto"): + return + + # debugging + #pprint(vars(e)) + + parent, gp = find_parent(i3, e.container.id) + + # This gets rid of tabbed container with single windows. + #if (parent and gp and parent.layout == 'tabbed' and len(parent.nodes) == 1): + # This gets rid of all single window containers. + if (parent and gp and len(parent.nodes) == 1): + i3.command('mark i3ha') + i3.command('focus parent') + i3.command('focus parent') + i3.command('mark i3hb') + i3.command('[con_mark="i3ha"] focus') + i3.command('move window to mark i3hb') + i3.command('unmark i3ha') + i3.command('unmark i3hb') + +def main(): + i3 = Connection() + i3.on(Event.WINDOW_FOCUS, focus_hook) + i3.main() + + +if __name__ == "__main__": + main()