Skip to content

Commit

Permalink
fix: clean up non-existent containers to prevent errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DCsunset committed Mar 9, 2024
1 parent 372f5e8 commit 4ebde78
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions i3_focus_group/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ async def handle_client_connection(i3, reader: asyncio.StreamReader, writer: asy
cur_container = root.find_focused()
con_id = cur_container.id

# clean up non-existing container
global group
group = deque(
filter(lambda x: root.find_by_id(x) is not None, group),
maxlen=args.size
)
logging.debug(f"After cleanup: {group}")

logging.info(f"Handling request: {req}")
match req:
case "add":
Expand Down Expand Up @@ -87,11 +95,10 @@ async def handle_client_connection(i3, reader: asyncio.StreamReader, writer: asy
if len(group) == 0:
return

# promote this container to head if not at head
try:
# will raise exception if not found
idx = group.index(con_id)
# promote this container to head
# promote this container to head if not at head
group.remove(con_id)
group.appendleft(con_id)
idx = 0
Expand All @@ -109,7 +116,6 @@ async def handle_client_connection(i3, reader: asyncio.StreamReader, writer: asy
if len(group) == 0:
return

# promote this container to head if not at head
try:
idx = group.index(con_id)
# switch focus to next container
Expand All @@ -124,7 +130,6 @@ async def handle_client_connection(i3, reader: asyncio.StreamReader, writer: asy
if len(group) == 0:
return

# promote this container to head if not at head
try:
idx = group.index(con_id)
# switch focus to next container
Expand Down

0 comments on commit 4ebde78

Please sign in to comment.