repos / zmx

session persistence for terminal processes
git clone https://github.com/neurosnap/zmx.git

commit
dd289a7
parent
be56a39
author
Eric Bower
date
2025-10-15 18:52:45 -0400 EDT
feat: in-band resize window events

https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83
1 files changed,  +25, -0
M src/daemon.zig
+25, -0
 1@@ -810,6 +810,9 @@ fn handleAttachSession(ctx: *ServerContext, client: *Client, session_name: []con
 2             if (result < 0) {
 3                 return error.IoctlFailed;
 4             }
 5+
 6+            // Send in-band size report if mode 2048 is enabled
 7+            try sendInBandSizeReportIfEnabled(session, rows, cols);
 8         }
 9     } else if (!is_reattach and rows > 0 and cols > 0) {
10         // New session: just resize normally
11@@ -825,6 +828,9 @@ fn handleAttachSession(ctx: *ServerContext, client: *Client, session_name: []con
12         if (result < 0) {
13             return error.IoctlFailed;
14         }
15+
16+        // Send in-band size report if mode 2048 is enabled
17+        try sendInBandSizeReportIfEnabled(session, rows, cols);
18     }
19 
20     // Only start PTY reading if not already started
21@@ -872,6 +878,22 @@ fn handlePtyInput(client: *Client, text: []const u8) !void {
22     _ = written;
23 }
24 
25+fn sendInBandSizeReportIfEnabled(session: *Session, rows: u16, cols: u16) !void {
26+    // Check if in-band size reports mode (2048) is enabled
27+    if (!session.vt.modes.get(.in_band_size_reports)) {
28+        return;
29+    }
30+
31+    // Format: CSI 48 ; height_chars ; width_chars ; height_pix ; width_pix t
32+    // We don't track pixel sizes, so report 0 for pixels
33+    var buf: [128]u8 = undefined;
34+    const size_report = try std.fmt.bufPrint(&buf, "\x1b[48;{d};{d};0;0t", .{ rows, cols });
35+
36+    // Write directly to PTY master so app receives it
37+    _ = try posix.write(session.pty_master_fd, size_report);
38+    std.debug.print("Sent in-band size report: {s}\n", .{size_report});
39+}
40+
41 fn handleWindowResize(client: *Client, rows: u16, cols: u16) !void {
42     const session_name = client.attached_session orelse {
43         std.debug.print("Client fd={d} not attached to any session\n", .{client.fd});
44@@ -899,6 +921,9 @@ fn handleWindowResize(client: *Client, rows: u16, cols: u16) !void {
45     if (result < 0) {
46         return error.IoctlFailed;
47     }
48+
49+    // Send in-band size report if mode 2048 is enabled
50+    try sendInBandSizeReportIfEnabled(session, rows, cols);
51 }
52 
53 fn readFromPty(ctx: *ServerContext, client: *Client, session: *Session) !void {