summaryrefslogtreecommitdiff
path: root/core/Event.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-18 22:03:14 -0300
committerGabriel Schneider <[email protected]>2026-11-18 22:23:51 -0300
commit99f5b10eccd95aa0066ea6fe6bb75f367ab56a47 (patch)
tree813596ea84318a7bae4fd7416ba463de8e3b7107 /core/Event.zig
parent92d553123673376adf6126ab90d49a22c5b833d2 (diff)
downloadpardes-99f5b10eccd95aa0066ea6fe6bb75f367ab56a47.tar.gz
pardes-99f5b10eccd95aa0066ea6fe6bb75f367ab56a47.zip
core: src/ becomes core/, pardes.zig its root.zig (the reorganisation's tree, step 2d), and every mention of a src/ path follows: the build's paths, the core's imports of its root, the tests that read the repository's files by path (lspbench's, look.zig's spans over core/look.zig), the comments that cite files, the documents and the manual (the typst corpus reads core/tutor.txt and core/plumbing); left as they were: the /src tree's served names (src/pardes.zig and the rest are the 9P tree's, not the repository's), the CHANGELOG's history, fixtures that are only strings; fs-unit-test runs from the core's root (a module of the core rooted at fs.zig had the runtime's and the devices' `core` be fs.zig); nothing else changes: the ledger (pardes.test.* now root.test.*), frames byte-identical, replicas and process-test the base's
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Event.zig')
-rw-r--r--core/Event.zig134
1 files changed, 134 insertions, 0 deletions
diff --git a/core/Event.zig b/core/Event.zig
new file mode 100644
index 00000000..faea73cc
--- /dev/null
+++ b/core/Event.zig
@@ -0,0 +1,134 @@
+//! What comes in: the union `update` takes (a key, the mouse, a resize, a
+//! pty's bytes, a host's answer) and the types of its parts.
+const config = @import("config.zig");
+const selection_pipe = @import("selection_pipe.zig");
+const Stream = @import("Stream.zig");
+const Layer = @import("Layer.zig");
+const RowMetrics = Layer.Metrics;
+const TagHit = Layer.TagHit;
+
+pub const Mouse = struct {
+ /// The host has inverted a compact body layer. Physical col/row still
+ /// route pane chrome; these coordinates address the pane's logical text.
+ pub const BodyHit = struct {
+ serial: u32,
+ row: u16,
+ col: u16,
+ pixel_x: f32,
+ pixel_y: f32,
+ metrics: RowMetrics,
+ place: Layer.Place = .{},
+ };
+ // sel indexing relies on left/middle/right being 0/1/2
+ pub const Button = enum { left, middle, right, wheel_up, wheel_down, wheel_left, wheel_right, none, back, forward };
+ pub const Kind = enum { press, release, motion, drag };
+ button: Button,
+ kind: Kind,
+ col: u16,
+ row: u16,
+ ctrl: bool = false,
+ shift: bool = false,
+ /// Alt, which xterm's mouse reports call meta.
+ alt: bool = false,
+ /// Super: Cmd on a Mac, the Windows key elsewhere. A terminal's mouse
+ /// report has no such bit, so only a pixel shell sets it.
+ super: bool = false,
+ body_hit: ?BodyHit = null,
+ tag_hit: ?TagHit = null,
+ /// A pixel frontend's press on the rule it draws at the top of this row,
+ /// which is where two panes meet if they do: the one grab that resizes
+ /// them there. A row of text never is one; a terminal, with no rule,
+ /// resizes by the grip.
+ rule_above: bool = false,
+ /// A release past the window's edge: a grip let go there carries its
+ /// 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 = @import("plain").Key;
+
+pub fn hit(key: Key, binding: []const config.Chord) bool {
+ for (binding) |c| {
+ if (key.cp != c.cp or key.ctrl != c.ctrl or key.alt != c.alt) continue;
+ if (c.shift and !key.shift) continue;
+ return true;
+ }
+ return false;
+}
+
+pub const sel_slot = @backingInt(config.select_button);
+
+/// A cell's pixels, as the frontend draws it: what a kind's pictures and a
+/// terminal's kitty images are laid out at.
+pub const CellPixels = struct {
+ w: u16 = 8,
+ h: u16 = 16,
+};
+
+pub const Event = union(enum) {
+ key: Key,
+ mouse: Mouse,
+ resize: struct {
+ cols: u16,
+ rows: u16,
+ cell_pixels: CellPixels = .{},
+ row_metrics: ?RowMetrics = null,
+ },
+ output: struct { pane: u8, bytes: []const u8 },
+ /// The pane's pty reached end of file: its output is over. An
+ /// interactive terminal closes; a command pane waits for `exited`.
+ eof: struct { pane: u8, status: ?u8 = null },
+ /// A command pane's child exited, with this status (null: unknown). It
+ /// is the command's end, whatever still holds its pty (a job it left in
+ /// the background prints on until end of file).
+ exited: struct { pane: u8, status: ?u8 },
+ lsp_resp: struct { id: u32, rows: ?[]const u8 },
+ pipe_resp: struct {
+ id: u32,
+ success: bool,
+ outputs: []const []const u8,
+ failure: ?selection_pipe.Failure = null,
+ },
+ file_changed: struct { pane: u8, bytes: []const u8 },
+ /// A disk search's batch (Stream.zig), borrowed for the step.
+ search: Stream.Batch,
+ paste: []const u8,
+ command: []const u8,
+ /// The host pointer left the drawable area. Unlike an out-of-range motion,
+ /// this must not clamp onto and preview the final grid cell.
+ pointer_leave,
+ /// The window gained (true) or lost the host's keyboard focus.
+ focus: bool,
+ /// How the host's handover `seq` went (Handover.finish): taken by `to`,
+ /// or `failure` says why not. Borrowed for the step.
+ handed: struct { seq: u32, to: []const u8 = "", failure: ?[]const u8 = null },
+ /// The live view's frontend, which its replica client says first
+ /// (docs/next-daemon.md, "Phase 6: GUI replica notes"): a window, which
+ /// draws pictures itself and takes the GUI's own words, or a terminal.
+ frontend: Frontend,
+ /// What the host's `addon` effect read off a library, or why not
+ /// (Addon.landed). Borrowed for the step.
+ addon: struct { op: @import("Addon.zig").Op, pane: u8, kind: *const @import("Kind.zig").Loaded },
+ /// A kind's job answered (host_io.Job), at its kind's generation then.
+ /// Borrowed for the step.
+ job: struct { pane: u8, serial: u32, token: u32, gen: u32, bytes: []const u8 },
+ tick,
+};
+
+/// A view's frontend: what a client of a session elsewhere says it is.
+pub const Frontend = struct {
+ windowed: bool,
+ native_images: bool = false,
+ /// The shell can take a changed image a few rows at a time (a texture
+ /// row upload, a shared-memory hand-off), so a PDF selection is
+ /// repainted as it is dragged instead of once on release. Each
+ /// process's own: in no digest and no dump (Pardes.replica.local was
+ /// where it said so).
+ native_image_patches: bool = false,
+
+ pub const replica = .{ .local = .{"native_image_patches"} };
+};