From f95d1e2b9273fac5356c020413c0531bc94517bb Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 18 Jul 2021 00:35:59 +0200 Subject: [PATCH] i3-companion: make i3-tabbed work by inhibiting exclusive workspaces --- bin/i3-companion | 29 +++++++++++++++++++++++++++-- bin/i3-tabbed | 11 +++++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/bin/i3-companion b/bin/i3-companion index d774428..dcb5621 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -320,10 +320,23 @@ async def new_workspace(i3, event): await current.command(f"move container to workspace " f'number "{num}"') -@on(I3Event.WINDOW_NEW) -async def worksplace_exclusive(i3, event): +@on(I3Event.WINDOW_NEW, CommandEvent("inhibit-exclusive")) +@static(inhibited_by=False) +async def workspace_exclusive(i3, event): """Move new windows on a new workspace instead of sharing a workspace with an exclusive app.""" + if event == "inhibit-exclusive": + logger.debug("inhibit exclusive workspace") + me = object() + workspace_exclusive.inhibited_by = me + await asyncio.sleep(1) + if workspace_exclusive.inhibited_by is me: + logger.info("cancel exclusive workspace inhibition") + workspace_exclusive.inhibited_by = None + return + if workspace_exclusive.inhibited_by: + workspace_exclusive.inhibited_by = None + return w = event.container # Can the current window intrude the workspace? @@ -905,6 +918,18 @@ async def main(options): i3.on(I3Event.BINDING, binding_event) + # React to ticks + async def tick_event(i3, event): + """Process tick events.""" + kind = event.payload.split(":")[0] + for fn, events in on.functions.items(): + for e in events: + if isinstance(e, CommandEvent) and e.name == kind: + logger.debug("received command event %s for %s", event, fn) + await fn(i3, event.payload) + + i3.on(I3Event.TICK, tick_event) + # Listen to DBus events for fn, events in on.functions.items(): for event in events: diff --git a/bin/i3-tabbed b/bin/i3-tabbed index ad35050..b24ad72 100755 --- a/bin/i3-tabbed +++ b/bin/i3-tabbed @@ -1,12 +1,12 @@ #!/usr/bin/env python3 # -# Splits the current terminal into a tab layout, runs a command, then restores the original layout. -# Handy for opening images and videos "inside" a terminal. +# Splits the current terminal into a tab layout, runs a command, then +# restores the original layout. Handy for opening images and videos +# "inside" a terminal. # # This effect is similar to dwm's window swallowing patch: https://www.youtube.com/watch?v=92uo5OBOKfY # -# To be super minimal, configure i3 to use a 0px font size to hide the tab title bars. With the -# unfortunate caveat that this will cause i3 error messages to become unreadable. +# Stolen from https://github.com/aduros/dotfiles/blob/master/home/bin/i3-tabbed from i3ipc import Connection import subprocess @@ -28,6 +28,9 @@ elif layout == "splitv": orig.command("split h") orig.command("layout tabbed") +# Ensure we don't collide with exclusive app handling +i3.send_tick("inhibit-exclusive") + try: # Run the given command code = subprocess.run(sys.argv[1:]).returncode