diff --git a/bin/i3-companion b/bin/i3-companion index 5e09645..42c0786 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -394,35 +394,41 @@ async def quake_console(i3, event): logger.warn(f"unable to parse payload {event}: {exc}") return + # Look for the terminal or spawn it tree = await i3.get_tree() - term = tree.find_instanced(term_name) - if not term: - await i3.command(f"exec exec {term_exec} --name {term_name}") - tries = 5 - while not term and tries: - tree = await i3.get_tree() - term = tree.find_instanced(term_name) - await asyncio.sleep(0.2) - tries -= 1 - if not term: - raise RuntimeError("unable to spawn terminal") - term = term[0] + try: + term = tree.find_instanced(term_name)[0] + except IndexError: + quake_window = asyncio.get_event_loop().create_future() + + def wait_for_quake(i3, event): + w = event.container + if quake_window.done() or w.window_instance != term_name: + return + quake_window.set_result(w) + + i3.on(I3Event.WINDOW_NEW, wait_for_quake) + try: + await i3.command(f"exec exec {term_exec} --name {term_name}") + done, pending = await asyncio.wait((quake_window,), timeout=1) + finally: + i3.off(wait_for_quake) + if not done: + raise RuntimeError("unable to spawn terminal") + term = quake_window.result() + await term.command("move window to scratchpad") + workspaces = await i3.get_workspaces() workspace = [ws for ws in workspaces if ws.focused][0] - ws_x = workspace.rect.x - ws_y = workspace.rect.y - ws_width = workspace.rect.width - ws_height = workspace.rect.height - width = ws_width + ws_x, ws_y = workspace.rect.x, workspace.rect.y + ws_width, ws_height = workspace.rect.width, workspace.rect.height height = int(ws_height * height) - posx = ws_x - posy = ws_y command = ( f"[instance={term_name}] " "border none," - f"resize set {width} px {height} px," + f"resize set {ws_width} px {height} px," "scratchpad show," - f"move absolute position {posx}px {posy}px" + f"move absolute position {ws_x}px {ws_y}px" ) logger.debug("QuakeConsole: %s", command) await i3.command(command) @@ -544,14 +550,10 @@ async def output_update(i3, event): screen_resources = randr.get_screen_resources_current(window) current_setup = set() for output in screen_resources.outputs: - output_info = randr.get_output_info( - window, output, screen_resources.timestamp - ) + output_info = randr.get_output_info(window, output, screen_resources.timestamp) if output_info.crtc == 0: continue - crtc_info = randr.get_crtc_info( - window, output_info.crtc, output_info.timestamp - ) + crtc_info = randr.get_crtc_info(window, output_info.crtc, output_info.timestamp) current_setup.add( ( output_info.name, diff --git a/config b/config index 0df4b9c..9aeb501 100644 --- a/config +++ b/config @@ -152,9 +152,7 @@ bindsym $mod+Delete exec --no-startup-id exec xset s activate bindsym Print exec --no-startup-id "flameshot gui -r | xclip -selection clipboard -t image/png" # Quake window -set $quake QuakeConsoleNeedsUniqueName -for_window [instance="$quake" title=$term] move window to scratchpad -bindsym $mod+grave nop "quake-console:$term:$quake:0.3" +bindsym $mod+grave nop "quake-console:$term:QuakeConsoleNeedsUniqueName:0.3" # Get info about container/workspace bindsym $mod+i nop "container-info"