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}")
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,