From e1fcaede3fbe22c89d1fe5f45dc38bb7ca89c47b Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 7 Jul 2021 12:30:14 +0200 Subject: [PATCH] i3-companion: add a binding to show window info --- bin/i3-companion | 39 +++++++++++++++++++++++++++++++++++++++ config | 3 +++ 2 files changed, 42 insertions(+) diff --git a/bin/i3-companion b/bin/i3-companion index 9ccd748..a351eda 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -15,6 +15,7 @@ import re import asyncio import shlex import subprocess +import html from i3ipc.aio import Connection from i3ipc import Event @@ -186,6 +187,41 @@ async def quake_console(i3, event): await i3.command(command) +async def window_info(i3, event): + """Show information about the focused window.""" + if event.payload != "info": + return + tree = await i3.get_tree() + window = tree.find_focused() + if not window: + return + logger.info(f"window raw information: {window.ipc_data}") + summary = f"Information about window {window.window}" + r = window.rect + w = window + info = { + "name": w.name, + "title": w.window_title, + "class": w.window_class, + "instance": w.window_instance, + "role": w.window_role, + "sticky": w.sticky, + "floating": w.floating, + "geometry": f"{r.width}×{r.height}+{r.x}+{r.y}", + "layout": w.layout, + "marks": ", ".join(w.marks) or "(none)" + } + 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", + "-i", "system-search", + summary, + body) + await proc.communicate() + + output_update_running = None async def output_update(i3, event): """React to a XRandR change.""" @@ -229,6 +265,9 @@ async def main(options): # Create/display a quake console i3.on(Event.TICK, quake_console) + # Get information about focused window + i3.on(Event.TICK, window_info) + # React to XRandR changes i3.on(Event.OUTPUT, output_update) diff --git a/config b/config index 8b48ad3..3e828c7 100644 --- a/config +++ b/config @@ -154,6 +154,9 @@ set $quake "QuakeConsoleNeedsUniqueName" for_window [instance=$quake title=$term] move window to scratchpad bindsym $mod+grave exec --no-startup-id i3-msg -t send_tick "quake-console:$term:$quake:0.3" +# Get info about an app (like xprop) +bindsym $mod+i exec --no-startup-id i3-msg -t send_tick "info" + # Random rules no_focus [class="zoom" window_type="dialog"] for_window [class="Shadow"] fullscreen enable