summaryrefslogtreecommitdiff
path: root/src/screen_state.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 11:38:06 -0300
committerGabriel Schneider <[email protected]>2026-11-06 12:03:00 -0300
commitf05c69380c8f23ab7dadb1c9d6240af687c88bed (patch)
tree8bb77af9ba2fadf64ac789bbe94c39df346a9db8 /src/screen_state.zig
parent239e8186111c215bf3bca842216205056e4b00e1 (diff)
downloadpardes-f05c69380c8f23ab7dadb1c9d6240af687c88bed.tar.gz
pardes-f05c69380c8f23ab7dadb1c9d6240af687c88bed.zip
kinds #18, ABI 2.2: pa_api says the core's ABI, pa_mouse grows a wheel's amount (a window passes a touchpad's fraction of a turn over a kind's pane, a terminal whole notches), pa_view says glyphs (no graphics), pa_paint's tail padding holds the pointer the kind asks for (the window shows a hand for PA_POINTER_LINK over its pane, a Shadow's frame carries it), and tick is told PA_FRAMED when a frame was drawn since its last; addon-test gains graphics on|off
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/screen_state.zig')
-rw-r--r--src/screen_state.zig19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/screen_state.zig b/src/screen_state.zig
index 1416ef42..1c86c216 100644
--- a/src/screen_state.zig
+++ b/src/screen_state.zig
@@ -1319,6 +1319,7 @@ pub const Shadow = struct {
rasters: std.ArrayList([]u8) = .empty,
prefix: Kind.Buf(96) = .{},
placed: bool = false,
+ pointer: u8 = 0,
pub fn deinit(sh: *Shadow, gpa: std.mem.Allocator) void {
gpa.free(sh.cells);
@@ -1344,7 +1345,9 @@ pub const Shadow = struct {
sh.cols = cols;
sh.rows = rows;
}
- sh.placed = try r.takeByte() != 0;
+ const flags = try r.takeByte();
+ sh.placed = flags & 1 != 0;
+ sh.pointer = flags >> 1;
sh.prefix.set(try r.take(try r.takeByte()));
for (0..rows) |y| {
sh.hashes[y] = try r.takeInt(u64, .little);
@@ -1406,12 +1409,14 @@ pub const ShadowSent = struct {
/// Frame `f` of a pane (its prefix and `placed` from its slot) for a peer
/// that was last sent `sent`: false, and nothing written, when it holds
/// this frame already.
-pub fn encodeShadow(gpa: std.mem.Allocator, sent: *ShadowSent, f: *const Kind.Frame, prefix: []const u8, placed: bool, w: *std.Io.Writer) !bool {
+pub fn encodeShadow(gpa: std.mem.Allocator, sent: *ShadowSent, f: *const Kind.Frame, prefix: []const u8, placed: bool, pointer: u8, w: *std.Io.Writer) !bool {
var hashes: std.ArrayList(Hash) = .empty;
errdefer hashes.deinit(gpa);
for (0..f.rows) |y| try hashes.append(gpa, std.hash.Wyhash.hash(0, std.mem.sliceAsBytes(f.cells[y * f.cols ..][0..f.cols])));
const places = f.places[0..f.n];
- const prefix_hash = std.hash.Wyhash.hash(@intFromBool(placed), prefix);
+ // Whether it placed a picture, and the pointer it asks for, one byte.
+ const flags: u8 = @intFromBool(placed) | @as(u8, @min(pointer, 127)) << 1;
+ const prefix_hash = std.hash.Wyhash.hash(flags, prefix);
var same = sent.cols == f.cols and std.mem.eql(Hash, sent.hashes.items, hashes.items) and sent.prefix == prefix_hash and sent.keys.items.len == places.len;
if (same) for (places, sent.keys.items) |pl, k| {
if (pl.key != k) same = false;
@@ -1422,7 +1427,7 @@ pub fn encodeShadow(gpa: std.mem.Allocator, sent: *ShadowSent, f: *const Kind.Fr
}
try w.writeInt(u16, f.cols, .little);
try w.writeInt(u16, f.rows, .little);
- try w.writeByte(@intFromBool(placed));
+ try w.writeByte(flags);
try w.writeByte(@intCast(@min(prefix.len, 96)));
try w.writeAll(prefix[0..@min(prefix.len, 96)]);
for (hashes.items, 0..) |h, y| {
@@ -1473,17 +1478,17 @@ test "a pane of a kind crosses as its frame, a row or a raster the peer holds as
defer sh.deinit(gpa);
var out: std.Io.Writer.Allocating = .init(gpa);
defer out.deinit();
- try std.testing.expect(try encodeShadow(gpa, &sent, &f, "fake", true, &out.writer));
+ try std.testing.expect(try encodeShadow(gpa, &sent, &f, "fake", true, 0, &out.writer));
try sh.apply(gpa, out.written());
try std.testing.expectEqualStrings("a", sh.cells[0].text[0..1]);
try std.testing.expectEqualStrings("fake", sh.prefix.slice());
try std.testing.expectEqual(@as(u8, 3), sh.rasters.items[0][2]);
// The same frame again: nothing to send.
out.clearRetainingCapacity();
- try std.testing.expect(!try encodeShadow(gpa, &sent, &f, "fake", true, &out.writer));
+ try std.testing.expect(!try encodeShadow(gpa, &sent, &f, "fake", true, 0, &out.writer));
// A cell of the second row moves: the first row and the raster go as hashes.
cells[4].flags = Kind.c.PA_PAINTED;
- try std.testing.expect(try encodeShadow(gpa, &sent, &f, "fake", true, &out.writer));
+ try std.testing.expect(try encodeShadow(gpa, &sent, &f, "fake", true, 0, &out.writer));
try std.testing.expect(out.written().len < 20 + 2 * 9 + 3 * 20 + 60);
try sh.apply(gpa, out.written());
try std.testing.expectEqual(@as(u8, Kind.c.PA_PAINTED), sh.cells[4].flags);