This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-12-session-parity
in repository terminology.
View the commit online.
commit 98f2b6c2c46343ab2a18be0b958b86a6858ca00e
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 22 21:49:17 2026 -0600
tymux: forward the application's input modes
The inline proxy only redrew the session's screen, so mouse reporting,
bracketed paste, focus reporting and the application cursor and keypad
modes never reached the terminal it runs in. It now sets them there as
the application changes them, and the outer terminal encodes the
events.
A paused proxy and one that exits clear every mode, whatever it thinks
it had set, as a proxy killed earlier may have left one on. A read-only
proxy enables none, since its input is ignored.
---
man/tymux.1 | 6 +++
src/bin/tymux.c | 121 ++++++++++++++++++++++++++++++++++++++++++++--
tests/tymux.py | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 271 insertions(+), 3 deletions(-)
diff --git a/man/tymux.1 b/man/tymux.1
index 90601e7a..37445422 100644
--- a/man/tymux.1
+++ b/man/tymux.1
@@ -34,6 +34,12 @@ prints
where the shell's screen was, and a terminal that took the session over
natively (see \fBNATIVE HAND\-OFF\fP) dims it instead.
.PP
+The inline proxy asks the terminal it runs in for what the program in the
+session asks for: application cursor keys and keypad, mouse reporting,
+bracketed paste and focus reporting.
+It switches them off again when it detaches, exits or is paused. A read-only
+attach switches none of them on.
+.PP
The size of the terminal in control is the size of the shell's screen.
.PP
When
diff --git a/src/bin/tymux.c b/src/bin/tymux.c
index dc2c2593..79526ed6 100644
--- a/src/bin/tymux.c
+++ b/src/bin/tymux.c
@@ -39,6 +39,10 @@ typedef struct
Ecore_Timer *strip_timer, *strip_expire;
bool paused;
bool running;
+ bool readonly;
+ /* the modes written to the outer terminal; wanted is the latest the
+ * application asked for, kept while paused */
+ TermSrvMsgNotify modes, wanted;
TermSrvReader reader;
int exit_code;
Ecore_Fd_Handler *fdh_stdin, *fdh_sock, *fdh_winch;
@@ -372,6 +376,110 @@ _paused_draw(void)
_write_str(buf);
}
+/* termpty.h pulls in more than tymux links, so the MOUSE_* and MOUSE_EXT_*
+ * values it defines, which TermSrvMsgNotify carries, are repeated here */
+#define TYMUX_MOUSE_X10 1
+#define TYMUX_MOUSE_NORMAL 2
+#define TYMUX_MOUSE_NORMAL_BTN_MOVE 3
+#define TYMUX_MOUSE_NORMAL_ALL_MOVE 4
+#define TYMUX_MOUSE_EXT_UTF8 1
+#define TYMUX_MOUSE_EXT_SGR 2
+#define TYMUX_MOUSE_EXT_URXVT 3
+
+/* DECSET/DECRST parameter of a termpty MOUSE_* value, 0 for none */
+static unsigned int
+_mouse_param(uint8_t mouse_mode)
+{
+ switch (mouse_mode)
+ {
+ case TYMUX_MOUSE_X10: return 9;
+ case TYMUX_MOUSE_NORMAL: return 1000;
+ case TYMUX_MOUSE_NORMAL_BTN_MOVE: return 1002;
+ case TYMUX_MOUSE_NORMAL_ALL_MOVE: return 1003;
+ default: return 0;
+ }
+}
+
+/* DECSET/DECRST parameter of a termpty MOUSE_EXT_* value, 0 for none */
+static unsigned int
+_mouse_ext_param(uint8_t mouse_ext)
+{
+ switch (mouse_ext)
+ {
+ case TYMUX_MOUSE_EXT_UTF8: return 1005;
+ case TYMUX_MOUSE_EXT_SGR: return 1006;
+ case TYMUX_MOUSE_EXT_URXVT: return 1015;
+ default: return 0;
+ }
+}
+
+static void
+_mode_put(Eina_Strbuf *out, unsigned int param, bool on)
+{
+ if (param)
+ _out_printf(out, "\033[?%u%c", param, on ? 'h' : 'l');
+}
+
+/* Write what differs between the modes set on the outer terminal and want.
+ * The mouse mode is switched off before its encoding and on after it, so that
+ * switching the mouse off never leaves it reporting. */
+static void
+_modes_write(Proxy *proxy, const TermSrvMsgNotify *want)
+{
+ const TermSrvMsgNotify *had = &proxy->modes;
+ unsigned int had_mouse = _mouse_param(had->mouse_mode);
+ unsigned int new_mouse = _mouse_param(want->mouse_mode);
+ unsigned int had_ext = _mouse_ext_param(had->mouse_ext);
+ unsigned int new_ext = _mouse_ext_param(want->mouse_ext);
+ Eina_Strbuf *out = eina_strbuf_new();
+
+ EINA_SAFETY_ON_NULL_RETURN(out);
+ if (had_mouse != new_mouse)
+ _mode_put(out, had_mouse, false);
+ if (had_ext != new_ext)
+ {
+ _mode_put(out, had_ext, false);
+ _mode_put(out, new_ext, true);
+ }
+ if (had_mouse != new_mouse)
+ _mode_put(out, new_mouse, true);
+ if (!had->appcursor != !want->appcursor)
+ _mode_put(out, 1, want->appcursor);
+ if (!had->appkeypad != !want->appkeypad)
+ _out_printf(out, want->appkeypad ? "\033=" : "\033>");
+ if (!had->focus_reporting != !want->focus_reporting)
+ _mode_put(out, 1004, want->focus_reporting);
+ if (!had->bracketed_paste != !want->bracketed_paste)
+ _mode_put(out, 2004, want->bracketed_paste);
+ _out_flush(out);
+ eina_strbuf_free(out);
+ proxy->modes = *want;
+}
+
+/* Forward the input modes of the application to the outer terminal. Nothing
+ * is written while paused or read-only: what is wanted is kept, to be applied
+ * on resume. */
+static void
+_modes_apply(Proxy *proxy, const TermSrvMsgNotify *notify)
+{
+ proxy->wanted = *notify;
+ if (proxy->paused || proxy->readonly)
+ return;
+ _modes_write(proxy, notify);
+}
+
+/* Switch off every mode the proxy can set, whatever it believes it set: a
+ * proxy killed earlier may have left some on. The mouse modes come before the
+ * encodings, so that it stops reporting first. */
+static void
+_modes_reset(Proxy *proxy)
+{
+ _write_str("\033[?9l\033[?1000l\033[?1002l\033[?1003l"
+ "\033[?1005l\033[?1006l\033[?1015l"
+ "\033[?1l\033>\033[?1004l\033[?2004l");
+ memset(&proxy->modes, 0, sizeof(proxy->modes));
+}
+
static void
_resize_send(Proxy *proxy)
{
@@ -526,6 +634,8 @@ _msg_handle(Proxy *proxy, int type, void *payload, uint32_t size)
switch (type)
{
case TSRV_MSG_NOTIFY:
+ if (size == sizeof(TermSrvMsgNotify))
+ _modes_apply(proxy, payload);
return true;
case TSRV_MSG_TITLE:
_title_set(payload, size);
@@ -540,6 +650,7 @@ _msg_handle(Proxy *proxy, int type, void *payload, uint32_t size)
break;
case TSRV_MSG_PAUSE:
proxy->paused = true;
+ _modes_reset(proxy);
_paused_draw();
break;
case TSRV_MSG_RESUME:
@@ -554,6 +665,7 @@ _msg_handle(Proxy *proxy, int type, void *payload, uint32_t size)
proxy->paused = false;
_resize_send(proxy);
_screen_draw(proxy, true);
+ _modes_apply(proxy, &proxy->wanted);
break;
default:
break;
@@ -657,9 +769,10 @@ _cb_sig_exit(void *data, int type __attribute__((unused)),
* answer in time, or empty: its answer, should it come later, is not
* typed text. Returns the exit code of the shell. */
static int
-_proxy_run(int sock, const char *nonce, const char *typed, size_t typed_len)
+_proxy_run(int sock, const char *nonce, const char *typed, size_t typed_len,
+ bool readonly)
{
- Proxy proxy = { .sock = sock, .running = true };
+ Proxy proxy = { .sock = sock, .running = true, .readonly = readonly };
TermSrvMsgAttached attached;
void *shm;
int shm_fd;
@@ -749,6 +862,7 @@ _proxy_run(int sock, const char *nonce, const char *typed, size_t typed_len)
if (proxy.running)
ecore_main_loop_begin();
+ _modes_reset(&proxy);
_raw_mode_leave();
_winch_handler_set(SIG_DFL);
_winch_pipe_write_fd = -1;
@@ -1031,7 +1145,8 @@ _attach(const char *name, TermSrvAttachMode mode, bool new_tab)
* and it would open a D-Bus connection on every attach */
ecore_app_no_system_modules();
ecore_init();
- ret = _proxy_run(sock, nonce, typed.data, typed.len);
+ ret = _proxy_run(sock, nonce, typed.data, typed.len,
+ mode == TSRV_ATTACH_READONLY);
ecore_shutdown();
close(sock);
_raw_mode_leave();
diff --git a/tests/tymux.py b/tests/tymux.py
index 3ac39def..f3a5aa4b 100644
--- a/tests/tymux.py
+++ b/tests/tymux.py
@@ -168,6 +168,7 @@ class Client:
pid, status = os.waitpid(self.pid, os.WNOHANG)
if pid:
self.status = os.waitstatus_to_exitcode(status)
+ self.idle(0.1)
return self.status
return None
@@ -189,6 +190,150 @@ def cpu_time(pid):
return (int(fields[11]) + int(fields[12])) / os.sysconf("SC_CLK_TCK")
+def emit(client, octal):
+ """make the shell of client write octal escapes, such as \\033[?1h: the
+ echo of the command holds the backslashes, not the sequence. Setting
+ focus reporting makes the session type a focus-out into the shell, which
+ Ctrl+U drops along with it."""
+ client.idle(0.3)
+ client.send("\x15printf '%s'\r" % octal)
+
+
+def expect_after(client, mark, text, timeout=5):
+ text = text.encode("utf-8")
+ end = time.time() + timeout
+ while text not in client.out[mark:] and time.time() < end:
+ client._read(0.05)
+ return text in client.out[mark:]
+
+
+MODES_ON = ("\\033[?1h\\033=\\033[?1000h\\033[?1006h"
+ "\\033[?1004h\\033[?2004h")
+MODES_OFF = ["\033[?1l", "\033>", "\033[?1000l", "\033[?1006l",
+ "\033[?1004l", "\033[?2004l"]
+
+
+def modes_session(name):
+ """a session whose proxy has forwarded every input mode"""
+ client = Client(["new", name])
+ check(client.expect("$ "), "modes: new session %s" % name)
+ emit(client, MODES_ON)
+ check(client.expect("\033[?2004h"), "modes: %s sets its modes" % name)
+ return client
+
+
+def check_modes():
+ name = "m%d" % os.getpid()
+ c = Client(["new", name])
+ check(c.expect("$ "), "modes: the shell prompt is shown")
+
+ emit(c, "\\033[?1h")
+ check(c.expect("\033[?1h"), "modes: application cursor keys are set")
+ emit(c, "\\033=")
+ check(c.expect("\033="), "modes: application keypad is set")
+ emit(c, "\\033[?1002h\\033[?1006h")
+ check(c.expect("\033[?1002h") and c.expect("\033[?1006h"),
+ "modes: the mouse and its encoding are set")
+ emit(c, "\\033[?1004h")
+ check(c.expect("\033[?1004h"), "modes: focus reporting is set")
+ emit(c, "\\033[?2004h")
+ check(c.expect("\033[?2004h"), "modes: bracketed paste is set")
+ c.send("echo unrelated-$((3+4))\r")
+ check(c.expect("unrelated-7"), "modes: an unrelated frame is drawn")
+ c.idle(0.3)
+ check(all(c.out.count(seq.encode()) == 1 for seq in
+ ("\033[?1h", "\033=", "\033[?1002h", "\033[?1006h",
+ "\033[?1004h", "\033[?2004h")),
+ "modes: each sequence is written once")
+
+ mark = len(c.out)
+ emit(c, "\\033[?1003h")
+ check(expect_after(c, mark, "\033[?1003h"), "modes: the mouse changes")
+ tail = c.out[mark:]
+ check(b"\033[?1002l" in tail and
+ tail.index(b"\033[?1002l") < tail.index(b"\033[?1003h"),
+ "modes: the old mouse mode is reset before the new one is set")
+ mark = len(c.out)
+ emit(c, "\\033[?1015h")
+ check(expect_after(c, mark, "\033[?1015h"), "modes: the encoding changes")
+ tail = c.out[mark:]
+ check(b"\033[?1006l" in tail and
+ tail.index(b"\033[?1006l") < tail.index(b"\033[?1015h"),
+ "modes: the old encoding is reset before the new one is set")
+
+ # a pause resets them, and no mode is set while paused
+ mark = len(c.out)
+ hijack = Client(["attach", name])
+ check(expect_after(c, mark, "PAUSED"), "modes: the proxy is paused")
+ tail = c.out[mark:]
+ check(all(seq.encode() in tail for seq in
+ ("\033[?1l", "\033>", "\033[?1003l", "\033[?1015l",
+ "\033[?1004l", "\033[?2004l")),
+ "modes: a pause resets the modes that were set")
+ hijack.idle(0.3)
+ emit(hijack, "\\033[?1003l\\033[?1000h")
+ check(hijack.expect("\033[?1000h"), "modes: the hijacker sets the mouse")
+ c.idle(0.5)
+ check(b"\033[?1000h" not in c.out[mark:],
+ "modes: a paused proxy sets no mode")
+ mark = len(c.out)
+ hijack.send("\x02d")
+ check(hijack.wait() == 0, "modes: the hijacker detaches")
+ check(expect_after(c, mark, "\033[?1000h"),
+ "modes: a resume sets the latest mouse mode")
+ c.idle(0.3)
+ tail = c.out[mark:]
+ check(all(seq.encode() in tail for seq in
+ ("\033[?1h", "\033=", "\033[?1015h", "\033[?1004h",
+ "\033[?2004h")) and b"\033[?1003h" not in tail,
+ "modes: a resume sets the modes again")
+
+ mark = len(c.out)
+ c.send("\x02d")
+ check(c.wait() == 0, "modes: detaching succeeds")
+ tail = c.out[mark:]
+ check(all(seq.encode() in tail for seq in
+ ("\033[?1l", "\033>", "\033[?1000l", "\033[?1002l",
+ "\033[?1003l", "\033[?1004l", "\033[?2004l")),
+ "modes: detach resets every mode, set or not")
+ tymux("kill", name)
+
+ for signum, label in ((signal.SIGTERM, "SIGTERM"), (signal.SIGHUP, "SIGHUP")):
+ name = "m%d%s" % (os.getpid(), label.lower())
+ c = modes_session(name)
+ mark = len(c.out)
+ os.kill(c.pid, signum)
+ c.wait()
+ check(all(seq.encode() in c.out[mark:] for seq in MODES_OFF),
+ "modes: %s resets the modes" % label)
+ tymux("kill", name)
+
+ name = "m%dexit" % os.getpid()
+ c = modes_session(name)
+ mark = len(c.out)
+ c.idle(0.3)
+ c.send("\x15exit 0\r")
+ c.wait()
+ check(all(seq.encode() in c.out[mark:] for seq in MODES_OFF),
+ "modes: the shell exiting resets the modes")
+
+ name = "m%dro" % os.getpid()
+ c = Client(["new", name])
+ check(c.expect("$ "), "modes: new session for a read-only proxy")
+ ro = Client(["attach", "--readonly", name])
+ check(ro.expect("$ "), "modes: read-only proxy attached")
+ emit(c, MODES_ON)
+ check(c.expect("\033[?2004h"), "modes: the primary sets its modes")
+ ro.idle(0.5)
+ check(not any(seq.encode() in ro.out for seq in
+ ("\033[?1h", "\033=", "\033[?1000h", "\033[?1006h",
+ "\033[?1004h", "\033[?2004h")),
+ "modes: a read-only proxy sets no mode")
+ tymux("kill", name)
+ c.wait()
+ ro.wait()
+
+
def main():
a = Client(["new", NAME])
check(a.expect("$ "), "new: the shell prompt is shown")
@@ -351,6 +496,8 @@ def main():
time.sleep(0.05)
check(not daemons(), "tymuxd exits with its shell")
+ check_modes()
+
# a client that stops reading is dropped instead of blocking tymuxd
a = Client(["new", NAME])
check(a.expect("$ "), "new for the stuck client test")
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.