Skip to content

Commit

Permalink
destroy swallow windows before layout change to prevent i3 crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
TyberiusPrime committed Aug 31, 2020
1 parent fa40c56 commit 748c523
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/i3_instant_layout/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import i3ipc
import datetime
import json
import math
Expand All @@ -23,6 +24,23 @@ def append_layout(layout_dict, window_count):
tf.close()


def nuke_swallow_windows():
"""Remove swallow windows before changing layout"""
to_nuke = set()

def walk_tree(con):
if con.ipc_data.get("swallows", False):
to_nuke.add(con.ipc_data["window"])
for d in con.descendants():
walk_tree(d)

i3 = i3ipc.Connection()
tree = i3.get_tree().find_focused().workspace()
walk_tree(tree)
for window_id in to_nuke:
subprocess.check_call(["xdotool", "windowclose", str(window_id)])


def get_window_ids():
"""use xprop to list windows on current screen.
Expand Down Expand Up @@ -205,6 +223,7 @@ def main():
query = query[: query.find(" ")]
for layout_class in layouts.layouts:
if query == layout_class.name or query in layout_class.aliases:
nuke_swallow_windows()
apply_layout(layout_class(), "--dry-run" in sys.argv)
count_usage(query)
sys.exit(0)
Expand Down

0 comments on commit 748c523

Please sign in to comment.