diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 15:14:30 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 15:56:38 -0300 |
| commit | 36dab7187fa0322c728848532638d549af02f746 (patch) | |
| tree | 34614c46c9475b3e103e4e266e2b8d76262c0a69 | |
| parent | 62c6caf414fd5a2be556f76eb21d1d6d8d3beadb (diff) | |
| download | pardes-36dab7187fa0322c728848532638d549af02f746.tar.gz pardes-36dab7187fa0322c728848532638d549af02f746.zip | |
upgrade: a window comes back from an Upgrade the size it had (the user's two windows went from 140 x 74 cells to 112 x 32 and from 343 columns to 193 at the 15:11 install): a window session's Upgrade is an exec, and its record said only that there was a window (runtime/upgrade.zig `Record.window`), so the new image made it the default 1120 x 720 points, or the `--geometry` it was started with (its arguments are passed again), never the size the user had given it since; now `upgradeNow` (dev/gui/gui.zig) puts the window's size in points as SDL_GetWindowSize says it then in the record, a line `size WxH` after `window 1` (`Record.size`), and the new image takes it as its `--geometry`, ahead of the one it was started with: the pair's road (a client window's PARDES_JOIN_SIZE, runtime/client.zig `execAgain`, read by the same parse), size only as the pair's (no place: an X11 window started at `+X+Y` is placed by the window manager after an Upgrade now); an older build's record has no such line (the word is passed over by a build before this one): the default, as before; a test window keeps a carried size over PARDES_TEST_COLS and ROWS; test: test/daemon.py `gui_upgrades` resizes the session's window to 100 x 30 cells (the test feed's in-band resize) before the Upgrade and reads the new image's first frame's size from its capture: on the base 1280x840 (80 x 24, the default) where it had been 1600x1050; now 1600x1050 from a build that writes the line, the default from one that does not (the record on the new process's command line says which), and upgrade.zig's record test reads the line back and an older record's none; core-test 934/1100 (166 skipped), shell-test 1142/1145 (3 skipped), gui unit-test 1739/1743 (4 skipped; its perf step's known BaselineHarnessMismatch), test/daemon.py `--upgrade --gui` between this tree's builds (Debug, unstamped and -Dstamp-commit: two semantics) 3/3 and from the installed build (62c6caf414fd) 3/3, `--upgrade` from it 1/1, plain 1/1
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
| -rw-r--r-- | dev/gui/gui.zig | 17 | ||||
| -rw-r--r-- | runtime/upgrade.zig | 15 | ||||
| -rw-r--r-- | test/daemon.py | 29 |
3 files changed, 52 insertions, 9 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 76af0ec8..2756f69b 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -809,9 +809,12 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di var want_w: c_int = 1120; var want_h: c_int = 720; var want_at: ?[2]c_int = null; - // ...or the size an Upgrade's exec says its window had (client.zig + // ...or the size an Upgrade's exec says its window had: a session's in + // its record (upgrade.zig `Record.size`), ahead of the `--geometry` it + // was started with, a client's in PARDES_JOIN_SIZE (client.zig // `execAgain`). - if (opts_in.geometry orelse if (std.c.getenv("PARDES_JOIN_SIZE")) |e| std.mem.span(e) else null) |spec| geometry: { + const kept = if (upgrade.resumed) |rec| rec.size else null; + if (kept orelse opts_in.geometry orelse if (std.c.getenv("PARDES_JOIN_SIZE")) |e| std.mem.span(e) else null) |spec| geometry: { const x_at = std.mem.indexOfScalar(u8, spec, 'x') orelse break :geometry; const plus = std.mem.indexOfAnyPos(u8, spec, x_at, "+-") orelse spec.len; want_w = std.math.clamp(std.fmt.parseInt(c_int, spec[0..x_at], 10) catch break :geometry, 200, 16384); @@ -881,7 +884,8 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di const cell_w: u32 = @intCast(@max(cw, 1)); const cell_h: u32 = @intCast(@max(chh, 1)); const tagline = taglineRaster(&atlas, px, cell_w, cell_h, config.gui_tagline_font_percent); - if (test_mode) { + // An upgraded window keeps its size in a test too. + if (test_mode and kept == null) { const cols = envU16(env, "PARDES_TEST_COLS") orelse 80; const rows = envU16(env, "PARDES_TEST_ROWS") orelse 24; // PARDES_TEST_PAD: extra pixels past the grid, as a real window has. @@ -2535,6 +2539,13 @@ const Shell = struct { // dials the session again once it is back. s.peers.refuseAll(core); var rec: upgrade.Record = .{ .link = daemon.link, .window = s.gui != null, .exe = path }; + // Its window's size now, the new one's (the user's since its start). + var size_buf: [32]u8 = undefined; + if (s.gui) |g| { + var w: c_int = 0; + var h: c_int = 0; + if (c.SDL_GetWindowSize(g.window, &w, &h)) rec.size = std.fmt.bufPrint(&size_buf, "{d}x{d}", .{ w, h }) catch null; + } s.ptys.record(&rec); var at_buf: [1024:0]u8 = undefined; const failed = upgrade.dumpInto(core, &rec, &at_buf, &why) orelse upgrade.execAs(s.gpa, path, &rec, &at_buf, s.fs, &why); diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index 510c50ea..b385556c 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -134,6 +134,10 @@ pub const Record = struct { old: c_int = -1, /// A window was open (the GUI). window: bool = false, + /// Its size in points at the Upgrade, `WxH` (SDL_GetWindowSize then: the + /// user's since its start), the new window's `--geometry` (gui.zig). + /// None, an older build's record: the default. + size: ?[]const u8 = null, ptys: [pardes.MAX_PANES]Pty = undefined, nptys: usize = 0, ttys: [pardes.views.max]Tty = undefined, @@ -187,6 +191,7 @@ pub const Record = struct { /// One `word value` a line, the dump's path last (its line is all of it). pub fn encode(rec: *const Record, w: *std.Io.Writer) !void { try w.print("link {d}\nstub {d}\nold {d}\nwindow {d}\n", .{ rec.link, rec.stub, rec.old, @intFromBool(rec.window) }); + if (rec.size) |wh| try w.print("size {s}\n", .{wh}); for (rec.ptys[0..rec.nptys]) |p| try w.print("pty {d} {d} {d}\n", .{ p.pane, p.pid, p.fd }); for (rec.ttys[0..rec.nttys]) |t| try w.print("tty {d} {d} {d} {d} {x}\n", .{ t.view, t.fd, t.stub, @intFromBool(t.primary), std.mem.asBytes(&t.termios) }); if (rec.refused.len > 0) try w.print("refused {s}\n", .{rec.refused}); @@ -206,11 +211,12 @@ pub const Record = struct { const rest = line[sp + 1 ..]; var it = std.mem.tokenizeScalar(u8, rest, ' '); // A word of a later build's record is passed over. - switch (std.meta.stringToEnum(enum { link, stub, old, window, pty, tty, refused, label, state, exe, dump }, word) orelse continue) { + switch (std.meta.stringToEnum(enum { link, stub, old, window, size, pty, tty, refused, label, state, exe, dump }, word) orelse continue) { .link => rec.link = try std.fmt.parseInt(c_int, rest, 10), .stub => rec.stub = try std.fmt.parseInt(c_int, rest, 10), .old => rec.old = try std.fmt.parseInt(c_int, rest, 10), .window => rec.window = std.mem.eql(u8, rest, "1"), + .size => rec.size = rest, .pty => { if (rec.nptys == rec.ptys.len) return error.BadRecord; const pane = try std.fmt.parseInt(u8, it.next() orelse return error.BadRecord, 10); @@ -474,7 +480,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op } test "an upgrade's record reads back as it was written, and refuses one cut short" { - var rec: Record = .{ .link = 5, .stub = 7, .old = 9, .window = true, .exe = "/a b/pardes", .dump = "/home/u/.local/share/pardes/pardes.xitdb", .label = "upgrade-1", .state = .kept }; + var rec: Record = .{ .link = 5, .stub = 7, .old = 9, .window = true, .size = "1402x1488", .exe = "/a b/pardes", .dump = "/home/u/.local/share/pardes/pardes.xitdb", .label = "upgrade-1", .state = .kept }; rec.addPty(3, 1234, 11); rec.addPty(0, 99, 12); var tio: posix.termios = std.mem.zeroes(posix.termios); @@ -487,6 +493,7 @@ test "an upgrade's record reads back as it was written, and refuses one cut shor try std.testing.expectEqual(@as(c_int, 5), back.link); try std.testing.expectEqual(@as(c_int, 9), back.old); try std.testing.expect(back.window); + try std.testing.expectEqualStrings("1402x1488", back.size.?); try std.testing.expectEqual(@as(usize, 2), back.nptys); try std.testing.expectEqual(Pty{ .pane = 3, .pid = 1234, .fd = 11 }, back.ptys[0]); try std.testing.expectEqual(@as(usize, 1), back.nttys); @@ -496,11 +503,11 @@ test "an upgrade's record reads back as it was written, and refuses one cut shor try std.testing.expectEqualStrings("/home/u/.local/share/pardes/pardes.xitdb", back.dump); try std.testing.expectEqualStrings("upgrade-1", back.label); try std.testing.expectEqual(daemon.State.kept, back.state.?); - // An older build's: its dump a file, no label, no state. + // An older build's: its dump a file, no label, no state, no size. const older = try Record.decode("link 5\nexe /a\ndump /run/u/pardes-upgrade-1.dump\n"); try std.testing.expectEqualStrings("/run/u/pardes-upgrade-1.dump", older.dump); try std.testing.expectEqualStrings("", older.label); - try std.testing.expect(older.state == null); + try std.testing.expect(older.state == null and older.size == null); try std.testing.expectError(error.BadRecord, Record.decode("link 5\n")); try std.testing.expectError(error.BadRecord, Record.decode("tty 0 1 2 1 abc\ndump x\n")); } diff --git a/test/daemon.py b/test/daemon.py index f456837b..b9296ea2 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -3995,10 +3995,17 @@ def upgrade_clients(old, new): shutil.rmtree(root, ignore_errors=True) +def frame_size(ppm): + """A window's capture's width and height in pixels (its P6 header).""" + return tuple(int(n) for n in ppm.read_bytes()[:32].split()[1:3]) + + def gui_upgrades(old, new): """Upgrade in a window session (test mode: hidden windows, captured): - its window, a client window, an unsaved edit and a shell's job, onto - another build.""" + its window, resized since its start, a client window, an unsaved edit + and a shell's job, onto another build; its new window the size the old + one had when its record names it (upgrade.zig `Record.size`), the + default when an older build's names none.""" scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' root = Path(tempfile.mkdtemp(prefix='rtgu-', dir=scratch)) env = base_env() @@ -4042,12 +4049,19 @@ def gui_upgrades(old, new): started.append(second.pid) frames = [caps / 'latest.ppm', root / 'second' / 'latest.ppm'] wait_for('both windows drawn', lambda: all(f.exists() for f in frames), timeout=20) + # The window resized by hand since its start (the test feed's + # in-band resize, CSI 48;rows;cols t, as a user's drag). + start = frame_size(frames[0]) + os.write(feed_w, b'\x1b[48;30;100t') + wait_for('the window resized', lambda: frame_size(frames[0]) != start) + sized = frame_size(frames[0]) install(new, binary) time.sleep(.05) mark = time.time() client.write(f'/pane/{shell}/exec', b'Upgrade\n') client.socket.close() wait_for('the session on the new build', lambda: exe_of(proc.pid) == (str(binary), True), timeout=30) + exec_at = time.time() client = reconnect(sock) assert proc.poll() is None wait_for('the daemon on the new build', lambda: exe_of(daemon) == (str(binary), True)) @@ -4070,6 +4084,17 @@ def gui_upgrades(old, new): second.p.wait(timeout=30) said = second.err.read_bytes() assert b'upgrade this client too' in said or b'run the same pardes at both ends' in said, said[-400:] + # The new build's window (a frame captured since the exec) the size + # the old one had at the Upgrade, not the one it started at, when + # the old build's record (the new process's command line) names it; + # an older build's names none: the default. + wait_for('a frame of the new build\'s window', lambda: frames[0].stat().st_mtime > exec_at) + record = next((a for a in cmdline(proc.pid) if a.startswith(b'--upgraded=')), b'') + size = re.search(rb'\nsize (\S+)\n', record) + back = frame_size(frames[0]) + assert back == (sized if size else start), ('the window back the size it had' if size else 'the default', back, sized, start, record) + print(f'upgrade: the window resized from {start[0]}x{start[1]} to {sized[0]}x{sized[1]} pixels came back ' + + (f'that size (its record: size {size[1].decode()})' if size else 'at the default (the old build\'s record names no size)')) said = Replica(root / 'pardes-replica.sock').hello('win', semantics(new)) assert said == ('welcome', proc.pid, 'win'), said os.kill(sleeper, signal.SIGTERM) |
