From c3f12f311faf8937e651a17363b544e2a10a0feb Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Mon, 5 Jul 2021 14:58:48 +0200 Subject: [PATCH] i3-companion: tentative to display workspace layout Unfortunately, we don't modify workspace layout, we modify container layout. We could modify workspace layout, but this seems a bit useless. --- bin/i3-companion | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/bin/i3-companion b/bin/i3-companion index 0c1423b..78b23e1 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -110,6 +110,43 @@ def workspace_rename(i3, event): i3.command(';'.join(commands)) +workspace_layouts = { + "splith": "", + "splitv": "", + "stacked": "", + "tabbed": "", +} + + +def workspace_layout(i3, event): + uid = os.getuid() + if hasattr(event, 'payload') and event.payload != 'ws-layout-change': + return + workspaces = i3.get_tree().workspaces() + for w in i3.get_workspaces(): + if not w.visible: + continue + layout = None + for ow in workspaces: + if w.num == ow.num: + layout = workspace_layouts.get(ow.layout, "?").encode('utf-8') + break + if layout is None: + continue + logger.debug(f"workspace {w.num} layout {ow.layout}") + fifo = f"/run/user/{uid}/i3/ws-{w.output}" + try: + fd = os.open(fifo, os.O_WRONLY | os.O_NONBLOCK) + try: + os.write(fd, layout + b"\n") + finally: + os.close(fd) + except (FileNotFoundError, BrokenPipeError, OSError): + logger.warning(f"workspace {w.num} layout {ow.layout} " + f"but not able to send to {fifo}") + continue + + if __name__ == "__main__": options = parse_args() setup_logging(options) @@ -123,6 +160,12 @@ if __name__ == "__main__": Event.WINDOW_CLOSE}: i3.on(event, workspace_rename) + # Update current workspace layout + for event in {Event.WORKSPACE_INIT, + Event.WORKSPACE_FOCUS, + Event.TICK}: + i3.on(event, workspace_layout) + i3.main() except Exception as e: logger.exception("%s", e)