tabbed-casilda/tabbed_protocol.py
Andrew Hamilton 7a35873e60 Run tabbed-run commands via exec so they block like a normal foreground command
tabbed-run now requests a new tab, blocks for a reply containing the tab id
and the compositor's Wayland socket path, then execs the command with
WAYLAND_DISPLAY pointing at the new tab.  The command's stdout/stderr and
exit status stay in the invoking tab.  Each compositor gets a stable socket
path under XDG_RUNTIME_DIR; startup tabs still use spawn_async against that
path.
2026-08-13 12:36:19 +10:00

27 lines
728 B
Python

import shlex
def serialize(creator_id: str, argv: list[str]) -> bytes:
return f"{creator_id}\n{shlex.join(argv)}\n".encode()
def parse(creator_line: str, command_line: str) -> tuple[int | None, str]:
creator_id = None
if creator_line.isdigit():
creator_id = int(creator_line)
return creator_id, command_line
def serialize_reply(tab_id: int, socket_path: str) -> str:
return f"{tab_id}\n{socket_path}\n"
def parse_reply(data: str) -> tuple[int | None, str | None]:
lines = data.strip().split("\n")
if len(lines) < 2:
return None, None
tab_id = None
if lines[0].isdigit():
tab_id = int(lines[0])
socket_path = lines[1] or None
return tab_id, socket_path