diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 11:38:06 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 12:03:00 -0300 |
| commit | f05c69380c8f23ab7dadb1c9d6240af687c88bed (patch) | |
| tree | 8bb77af9ba2fadf64ac789bbe94c39df346a9db8 /src | |
| parent | 239e8186111c215bf3bca842216205056e4b00e1 (diff) | |
| download | pardes-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')
| -rw-r--r-- | src/Addon.zig | 1 | ||||
| -rw-r--r-- | src/Event.zig | 3 | ||||
| -rw-r--r-- | src/Kind.zig | 24 | ||||
| -rw-r--r-- | src/addon_test.zig | 5 | ||||
| -rw-r--r-- | src/draw.zig | 5 | ||||
| -rw-r--r-- | src/gui/gui.zig | 14 | ||||
| -rw-r--r-- | src/kinds/pardes_addon.h | 31 | ||||
| -rw-r--r-- | src/replica.zig | 2 | ||||
| -rw-r--r-- | src/screen_state.zig | 19 | ||||
| -rw-r--r-- | src/wire.zig | 4 |
10 files changed, 83 insertions, 25 deletions
diff --git a/src/Addon.zig b/src/Addon.zig index 9f94f1de..c6dca34b 100644 --- a/src/Addon.zig +++ b/src/Addon.zig @@ -339,6 +339,7 @@ pub fn loadedOf(ops: *const Kind.Ops, path: []const u8, hash: [32]u8, words: *[6 .search = h.abi & 0xffff >= 1 and ops.search != null, .esc = h.abi & 0xffff >= 1 and ops.key != null, .address = ops.address != null, + .v22 = h.abi & 0xffff >= 2, }, }; } diff --git a/src/Event.zig b/src/Event.zig index 63dcb5f2..aa93f412 100644 --- a/src/Event.zig +++ b/src/Event.zig @@ -44,6 +44,9 @@ pub const Mouse = struct { /// pane or column out of the window (Handover.zig). col and row are /// still the last cell inside. outside: bool = false, + /// A wheel's turn in notches, a touchpad's fraction of one; 0 is one + /// (a terminal's, every wheel's but a window's over a kind's pane). + amount: f32 = 0, }; pub const Key = struct { diff --git a/src/Kind.zig b/src/Kind.zig index c1640b57..2add017a 100644 --- a/src/Kind.zig +++ b/src/Kind.zig @@ -38,8 +38,8 @@ pub const abi: u32 = c.PA_ABI; comptime { if (@sizeOf(usize) == 8) for (.{ .{ c.pa_cell, 20 }, .{ c.pa_window, 24 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 }, - .{ c.pa_placement, 80 }, .{ c.pa_paint, 128 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 10 }, - .{ c.pa_api, 96 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 }, + .{ c.pa_placement, 80 }, .{ c.pa_paint, 128 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 16 }, + .{ c.pa_api, 104 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 }, .{ c.pa_ops, 200 }, .{ c.pa_view, 32 }, }) |r| if (@sizeOf(r[0]) != r[1]) @compileError(std.fmt.comptimePrint("{s} is {d} bytes, the header says {d}", .{ @typeName(r[0]), @sizeOf(r[0]), r[1] })); } @@ -60,7 +60,9 @@ pub const Caps = packed struct(u16) { /// Esc comes to its `key` first (2.1). esc: bool = false, address: bool = false, - pad: u7 = 0, + /// 2.2's: a wheel's amount, the pointer in paint, PA_FRAMED. + v22: bool = false, + pad: u6 = 0, }; pub const Entry = struct { @@ -171,6 +173,10 @@ pub const Slot = struct { told: Buf(400) = .{}, thumb_at: f32 = 0, thumb_span: f32 = 0, + /// The pointer its last frame asked for over it (PA_POINTER_*, 2.2), + /// and whether a frame was painted since its last tick. + pointer: u8 = 0, + painted: bool = false, /// What its view was (`api.view`) when `tick` was last told: a change /// ticks it again (2.1). view: u64 = 0, @@ -433,6 +439,8 @@ pub fn paint(p: *const Pardes, slot: *Slot, id: usize, arena: std.mem.Allocator, slot.placed = placed; slot.thumb_at = std.math.clamp(out.at, 0, 1); slot.thumb_span = std.math.clamp(out.span, 0, 1); + slot.pointer = if (caps(p, slot).v22) @intCast(@min(out.pointer, 255)) else 0; + slot.painted = true; return cells; } @@ -581,6 +589,7 @@ pub fn mouse(p: *Pardes, id: usize, m: pardes.Mouse, col: u16, row: u16) bool { .pad = 0, .col = col, .row = row, + .amount = m.amount, }; var cl: Call = .{ .p = p, .id = id, .slot = slot }; const prev = cl.begin("mouse"); @@ -610,7 +619,11 @@ pub fn step(p: *Pardes) void { if (slot.next_tick == 0 or (slot.next_tick > 1 and now < slot.next_tick)) continue; var cl: Call = .{ .p = p, .id = id, .slot = slot }; const prev = cl.begin("tick"); - if (slot.ops) |o| cl.ret = @bitCast(o.tick.?(slot.st, now, if (focused) c.PA_FOCUSED else 0)); + // A frame drawn since its last tick (2.2): a fling's frames are + // counted by them. + const flags = (if (focused) c.PA_FOCUSED else 0) | (if (slot.painted and caps(p, slot).v22) c.PA_FRAMED else 0); + slot.painted = false; + if (slot.ops) |o| cl.ret = @bitCast(o.tick.?(slot.st, now, flags)); slot.next_tick = @bitCast(cl.end(prev).ret); p.needs_frame = true; }; @@ -642,6 +655,7 @@ pub fn viewOf(p: *const Pardes, id: usize) c.pa_view { .dpi = policy.dpi, .max_px = policy.max_dimension, .fill = @intFromBool(policy.match_viewport), + .glyphs = @intFromBool(!v.frontend.native_images), .pad = @splat(0), }; } @@ -850,6 +864,8 @@ pub fn calling(buf: []u8) ?[]const u8 { pub const api: c.pa_api = .{ .size = @sizeOf(c.pa_api), + .abi = c.PA_ABI, + .pad = 0, .alloc = struct { fn f(n: usize) callconv(.c) ?*anyopaque { const cl = current orelse return null; diff --git a/src/addon_test.zig b/src/addon_test.zig index 427f0289..7b151ee6 100644 --- a/src/addon_test.zig +++ b/src/addon_test.zig @@ -17,6 +17,8 @@ //! seed 7 what every pane's seed is made from (before open) //! click 3 1 a left click at the body's column 3, row 1 //! focus, blur the window takes the keyboard, or loses it +//! graphics on|off a frontend that shows pictures, or one without +//! them (glyph art, the start's) //! dump the pane's record (its length) loaded into a //! fresh pane, which the script goes on with //! body, ctl the pane's body, or its ctl file's read @@ -108,6 +110,9 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons p.update(.{ .mouse = .{ .button = .left, .kind = mk, .col = body.x + col, .row = body.y + row } }); } else if (is(verb, "focus") or is(verb, "blur")) { p.update(.{ .focus = is(verb, "focus") }); + } else if (is(verb, "graphics")) { + // A frontend that shows pictures (`graphics on`), or glyph art. + p.update(.{ .frontend = .{ .windowed = false, .native_images = std.mem.eql(u8, arg, "on") } }); } else if (is(verb, "dump")) { id = try reloaded(p, gpa, at, out); } else if (is(verb, "body") or is(verb, "ctl")) { diff --git a/src/draw.zig b/src/draw.zig index 8538c6a6..b17e2458 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -183,6 +183,11 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { // afford it the arrow instead. if (p.look_hover_preview != null) s.pointer_shape = .target; if (v.drag == .move or v.drag == .column_move) s.pointer_shape = .box; + // Over a kind's pane, the pointer its last frame asked for (a PDF's + // hand over a link; 2.2). + if (v.kind_hover) |id| if (p.panes[id]) |pane| if (pane.addon) |k| { + if ((if (k.shadow) |sh| sh.pointer else k.pointer) == pardes.Kind.c.PA_POINTER_LINK) s.pointer_shape = .link; + }; for (&s.body_layers) |*layer| layer.rows = 0; for (&s.tag_layers) |*layer| layer.rows = 0; s.placements.clearRetainingCapacity(); diff --git a/src/gui/gui.zig b/src/gui/gui.zig index e7cd539a..8271699e 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -2900,11 +2900,15 @@ fn wheelAt(g: *Gui, in: *Input, w: WheelTurn, mc: MouseCell) void { }; if (hit) |id| { const pane = core.panes[id].?; - if (pane.addon != null or (!w.mods.shift and pane.isTerminal() and pardes.panes.terminal.ownsWheel(pane))) { - // The program's (codex, htop, less), or a kind's (a - // PDF's strip): every whole turn goes to it, no glide, - // for nothing of ours moves. Shift keeps a terminal's - // wheel pardes's. + if (pane.addon != null) { + // A kind's (a PDF's strip): the turn as it came, a + // touchpad's fraction of a notch too (pa_mouse.amount). + resetScroll(g); + in.post(.{ .mouse = .{ .button = if (w.y < 0) .wheel_down else .wheel_up, .kind = .press, .col = mc.col, .row = mc.row, .tag_hit = mc.tag_hit, .body_hit = mc.body_hit, .ctrl = w.mods.ctrl, .shift = w.mods.shift, .alt = w.mods.alt, .amount = @abs(w.y) } }); + } else if (!w.mods.shift and pane.isTerminal() and pardes.panes.terminal.ownsWheel(pane)) { + // The program's (codex, htop, less): every whole turn goes + // to it, no glide, for nothing of ours moves. Shift keeps + // a terminal's wheel pardes's. resetScroll(g); g.program_wheel = accumulateWheelDelta(g.program_wheel, w.y); while (g.program_wheel >= 1) : (g.program_wheel -= 1) diff --git a/src/kinds/pardes_addon.h b/src/kinds/pardes_addon.h index e7334063..072f2447 100644 --- a/src/kinds/pardes_addon.h +++ b/src/kinds/pardes_addon.h @@ -32,7 +32,7 @@ /* Major in the high half: an addon of another major is refused. */ #define PA_ABI_MAJOR 2u -#define PA_ABI_MINOR 1u +#define PA_ABI_MINOR 2u #define PA_ABI ((PA_ABI_MAJOR << 16) | PA_ABI_MINOR) #define PA_OK 0 @@ -106,13 +106,20 @@ typedef struct pa_placement { * frame, body and prefix together, never over no cells. 2.1: `at` and * `span`, where the window is in the pane's whole (the share above it and * the share it shows, 0 to 1), are the rail's thumb; 0 and 0, none. A kind - * writes them only to a core whose api->size says 2.1. */ + * writes them only to a core whose api->size says 2.1. 2.2: `pointer`, the + * pointer a frontend shows over the pane (PA_POINTER_*), which a terminal + * ignores. In paint, not in mouse's answer: what is under a resting pointer + * is known after the motion (a PDF's link, found on a tick), and the field + * takes the record's tail padding, so its size stays. */ +#define PA_POINTER_DEFAULT 0u +#define PA_POINTER_LINK 1u typedef struct pa_paint { pa_placement *placements; uint32_t cap, n; char prefix[96]; uint32_t prefix_len; float at, span; + uint32_t pointer; } pa_paint; /* ---- input ---- */ @@ -147,10 +154,13 @@ typedef struct pa_key { #define PA_MOTION 2 #define PA_DRAG 3 /* A pointer event in the window's cells; a motion at col and row 0xffff - * when the pointer leaves the window. */ + * when the pointer leaves the window. 2.2: `amount`, a wheel's turn in + * notches, a touchpad's fraction of one (a terminal's are whole; 0 from an + * older core: one; an older kind is told each turn as a notch). */ typedef struct pa_mouse { uint8_t button, action, ctrl, shift, alt, pad; uint16_t col, row; + float amount; } pa_mouse; /* ---- what pardes does for an addon ---- */ @@ -163,7 +173,9 @@ typedef struct pa_view { uint16_t cols, rows, cell_w, cell_h; uint32_t fg, bg, sel, link; uint16_t dpi, max_px; - uint8_t fill, pad[3]; + /* 2.2: `glyphs`, 1 when the frontend shows placements as glyph art (a + * terminal without graphics; 0 from an older core). */ + uint8_t fill, glyphs, pad[2]; } pa_view; /* Valid during any call pardes makes for a pane, and about that pane. */ @@ -196,6 +208,9 @@ typedef struct pa_api { /* The text the pane has selected now, which a yank, a chord's Snarf and * a keyboard Look take; n 0, none. */ void (*select)(const char *text, uint32_t n); + /* 2.2 (api->size >= 104): the core's PA_ABI, so a kind reads the 2.2 + * fields it is given (pa_mouse.amount) only from a core that sets them. */ + uint32_t abi, pad; } pa_api; /* What a job allocates from, on its worker (pa_api is not there): as often @@ -226,8 +241,10 @@ typedef struct pa_word { } pa_word; #define PA_WORD(nm, ld, a, op, dc) { .name = (nm), .leader = (ld), .arg = (a), .opens = (op), .doc = (dc) } -/* tick's flags: the pane has the keyboard in some view. */ +/* tick's flags: the pane has the keyboard in some view; 2.2: a frame of it + * was drawn since the last tick. */ #define PA_FOCUSED 0x1u +#define PA_FRAMED 0x2u typedef struct pa_head { uint32_t size, abi; @@ -309,8 +326,8 @@ _Static_assert(sizeof(pa_window) == 24, "pa_window"); _Static_assert(sizeof(pa_rect) == 16 && sizeof(pa_cells) == 8, "pa_rect"); _Static_assert(sizeof(pa_placement) == 80, "pa_placement"); _Static_assert(sizeof(pa_paint) == 128 && sizeof(pa_view) == 32, "pa_paint"); -_Static_assert(sizeof(pa_key) == 8 && sizeof(pa_mouse) == 10, "pa_key"); -_Static_assert(sizeof(pa_api) == 96 && sizeof(pa_out) == 16, "pa_api"); +_Static_assert(sizeof(pa_key) == 8 && sizeof(pa_mouse) == 16, "pa_key"); +_Static_assert(sizeof(pa_api) == 104 && sizeof(pa_out) == 16, "pa_api"); _Static_assert(sizeof(pa_word) == 32 && sizeof(pa_head) == 56, "pa_head"); _Static_assert(sizeof(pa_ops) == 200, "pa_ops"); #endif diff --git a/src/replica.zig b/src/replica.zig index 25507ec5..e5dbe310 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -446,7 +446,7 @@ pub const Screens = struct { try writeScreenHead(&x.s.out, x.s.gpa, @intCast(id), pane.serial, kind_shadow); var w: std.Io.Writer.Allocating = .fromArrayList(x.s.gpa, &x.s.out); defer x.s.out = w.toArrayList(); - if (!try screen_state.encodeShadow(x.s.gpa, &pp.shadow, &frame, k.prefix.slice(), k.placed, &w.writer)) continue; + if (!try screen_state.encodeShadow(x.s.gpa, &pp.shadow, &frame, k.prefix.slice(), k.placed, k.pointer, &w.writer)) continue; try x.out.append(x.s.gpa, try x.s.gpa.dupe(u8, w.written())); }; } 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); diff --git a/src/wire.zig b/src/wire.zig index d083ea82..e39e25b4 100644 --- a/src/wire.zig +++ b/src/wire.zig @@ -518,6 +518,7 @@ pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 { try w.writeByte(@intFromBool(m.ctrl)); try w.writeByte(@intFromBool(m.shift)); try w.writeByte(@intFromBool(m.alt)); + try w.writeInt(u32, @bitCast(m.amount), .little); try putBodyHit(&w, m.body_hit); try putTagHit(&w, m.tag_hit); }, @@ -597,6 +598,7 @@ pub fn decodeClient(tag: u8, payload: []const u8) Error!ClientMsg { .ctrl = try getBool(&r), .shift = try getBool(&r), .alt = try getBool(&r), + .amount = @bitCast(try r.takeInt(u32, .little)), .body_hit = try getBodyHit(&r), .tag_hit = try getTagHit(&r), } } }, @@ -633,7 +635,7 @@ pub fn clientBound(msg: ClientMsg) usize { .screen_ack, .want => |bytes| bytes.len, .event => |ev| switch (ev) { // Its hits' places (14 bytes each) past the slack. - .mouse => 28, + .mouse => 32, .resize, .pointer_leave, .focus, .frontend => 0, .key => |k| k.text.len, .paste => |b| b.len, |
