i3-companion: rework a bit Quake console to use events only

This commit is contained in:
Vincent Bernat 2021-07-19 09:52:48 +02:00
parent 6cf9a784f7
commit f267250c42
2 changed files with 30 additions and 30 deletions

View file

@ -394,35 +394,41 @@ async def quake_console(i3, event):
logger.warn(f"unable to parse payload {event}: {exc}") logger.warn(f"unable to parse payload {event}: {exc}")
return return
# Look for the terminal or spawn it
tree = await i3.get_tree() tree = await i3.get_tree()
term = tree.find_instanced(term_name) try:
if not term: term = tree.find_instanced(term_name)[0]
await i3.command(f"exec exec {term_exec} --name {term_name}") except IndexError:
tries = 5 quake_window = asyncio.get_event_loop().create_future()
while not term and tries:
tree = await i3.get_tree() def wait_for_quake(i3, event):
term = tree.find_instanced(term_name) w = event.container
await asyncio.sleep(0.2) if quake_window.done() or w.window_instance != term_name:
tries -= 1 return
if not term: quake_window.set_result(w)
raise RuntimeError("unable to spawn terminal")
term = term[0] 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() workspaces = await i3.get_workspaces()
workspace = [ws for ws in workspaces if ws.focused][0] workspace = [ws for ws in workspaces if ws.focused][0]
ws_x = workspace.rect.x ws_x, ws_y = workspace.rect.x, workspace.rect.y
ws_y = workspace.rect.y ws_width, ws_height = workspace.rect.width, workspace.rect.height
ws_width = workspace.rect.width
ws_height = workspace.rect.height
width = ws_width
height = int(ws_height * height) height = int(ws_height * height)
posx = ws_x
posy = ws_y
command = ( command = (
f"[instance={term_name}] " f"[instance={term_name}] "
"border none," "border none,"
f"resize set {width} px {height} px," f"resize set {ws_width} px {height} px,"
"scratchpad show," "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) logger.debug("QuakeConsole: %s", command)
await i3.command(command) await i3.command(command)
@ -544,14 +550,10 @@ async def output_update(i3, event):
screen_resources = randr.get_screen_resources_current(window) screen_resources = randr.get_screen_resources_current(window)
current_setup = set() current_setup = set()
for output in screen_resources.outputs: for output in screen_resources.outputs:
output_info = randr.get_output_info( output_info = randr.get_output_info(window, output, screen_resources.timestamp)
window, output, screen_resources.timestamp
)
if output_info.crtc == 0: if output_info.crtc == 0:
continue continue
crtc_info = randr.get_crtc_info( crtc_info = randr.get_crtc_info(window, output_info.crtc, output_info.timestamp)
window, output_info.crtc, output_info.timestamp
)
current_setup.add( current_setup.add(
( (
output_info.name, output_info.name,

4
config
View file

@ -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" bindsym Print exec --no-startup-id "flameshot gui -r | xclip -selection clipboard -t image/png"
# Quake window # Quake window
set $quake QuakeConsoleNeedsUniqueName bindsym $mod+grave nop "quake-console:$term:QuakeConsoleNeedsUniqueName:0.3"
for_window [instance="$quake" title=$term] move window to scratchpad
bindsym $mod+grave nop "quake-console:$term:$quake:0.3"
# Get info about container/workspace # Get info about container/workspace
bindsym $mod+i nop "container-info" bindsym $mod+i nop "container-info"