diff --git a/bin/i3-companion b/bin/i3-companion index 667d5f2..3b41ef3 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -219,9 +219,16 @@ async def quake_console(i3, event): await i3.command(command) -@on("info") -async def window_info(i3, event): - """Show information about the focused window.""" +async def notify(*args): + """Send a notification with notify-send.""" + proc = await asyncio.create_subprocess_exec( + "notify-send", *args) + await proc.communicate() + + +@on("container-info") +async def container_info(i3, event): + """Show information about the focused container.""" tree = await i3.get_tree() window = tree.find_focused() if not window: @@ -247,12 +254,56 @@ async def window_info(i3, event): body = "\n".join((f"{k:10} {html.escape(str(v))}" for k, v in info.items() if v is not None)) - proc = await asyncio.create_subprocess_exec( - "notify-send", + await notify( "-i", "system-search", + "-t", "10000", + summary, + body) + + +@on("workspace-info") +async def workspace_info(i3, event): + """Show information about the focused workspace.""" + workspaces = await i3.get_workspaces() + focused = [w for w in workspaces if w.focused] + if not focused: + return + workspace = focused[0] + summary = f"About workspace {workspace.num} on {workspace.output}" + tree = await i3.get_tree() + workspace = [w for w in tree.workspaces() + if w.num == workspace.num] + + def format(container): + if container.focused: + style = 'foreground="#ffaf00"' + else: + style = 'foreground="#6c98ee"' + root = (f"" + f"({container.layout})" + "") + if container.window_title: + root += (f" {html.escape(container.window_class.lower())}:" + f" {html.escape(container.window_title)}") + children = [] + for child in container.nodes: + if child == container.nodes[-1]: + first = "└─" + others = " " + else: + first = "├─" + others = "│ " + content = format(child).replace("\n", f"\n{others}") + children.append(f"{first}{content}") + children.insert(0, root) + return "\n".join(children) + + body = format(workspace[0]) + await notify( + "-i", "system-search", + "-t", "15000", summary, body) - await proc.communicate() output_update_running = None diff --git a/config b/config index 05f9ceb..23a6c08 100644 --- a/config +++ b/config @@ -153,8 +153,9 @@ set $quake QuakeConsoleNeedsUniqueName for_window [instance="$quake" title=$term] move window to scratchpad bindsym $mod+grave nop "quake-console:$term:$quake:0.3" -# Get info about an app (like xprop) -bindsym $mod+i nop "info" +# Get info about container/workspace +bindsym $mod+i nop "container-info" +bindsym $mod+Shift+i nop "workspace-info" # Random rules no_focus [window_type="splash"]