Find the parent of a given window id
"""
- def finder(con, parent):
+ def finder(con, parent, gp):
if con.id == window_id:
- return parent
+ return (parent, gp)
for node in con.nodes:
- res = finder(node, con)
+ res = finder(node, con, parent)
if res:
return res
return None
- return finder(i3.get_tree(), None)
+ return finder(i3.get_tree(), None, None)
def set_layout(i3):
horizontal, depending on its width/height
"""
-
-
win = i3.get_tree().find_focused()
- parent = find_parent(i3, win.id)
+ # i don't use gp: todo: revert to original alternating_layout function
+ # which did not return gp.
+ parent, gp = find_parent(i3, win.id)
# We never want to set the layout of a single window container,
# this, it is stupid. So, eliminate single window container if we
# are focused on one.
#
- # Alternatively, it could first focus the parent, but I think when
+ # Alternatively, we could first focus the parent, but I think when
# layout changes, we expect new windows to be created within that
# layout.
- if (parent and len(parent.nodes) == 1):
- gp = find_parent(i3, parent.id)
- if (gp.nodes[0].id == parent.id):
- if (gp.layout == 'splitv'):
- i3.command('move down')
- else: # splith or tabbed
- i3.command('move right')
- else:
- if (gp.layout == 'splitv'):
- i3.command('move up')
- else:
- i3.command('move left')
+ #
+ # Todo: if the direction we are moving has a split/tabbed container
+ # as a peer to parent, this will move our window into that container
+ # instead of what we want. And in fact, the whole logic below is
+ # incorrect and based on testing which did not realize that fact.
+ #
+ if (parent and parent.type == 'con' and len(parent.nodes) == 1):
+ # https://unix.stackexchange.com/questions/173754/how-to-move-a-window-up-to-the-level-of-its-parent-window-in-i3wm
+ 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')
i3.command('layout ' + sys.argv[1])
def main():