diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 19:20:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 22:03:21 -0300 |
| commit | d0bb5e63a95bcf2195743e222f468d4c508d11c0 (patch) | |
| tree | 9b0981e5ac92d1f0fd96c27987217f4618c80989 /src/Event.zig | |
| parent | 86c4f35af8505941c7472a81d8d62dca9b6e2fa9 (diff) | |
| download | pardes-d0bb5e63a95bcf2195743e222f468d4c508d11c0.tar.gz pardes-d0bb5e63a95bcf2195743e222f468d4c508d11c0.zip | |
split pardes.zig by noun, Event: what comes in, the union update takes and the types of its parts (Mouse, Key and its specials, hit, sel_slot, CellPixels, Frontend), moves into src/Event.zig, the clean room's name; the root names each as before (pardes.Event, pardes.Key and the rest; Frontend only inside), so no caller changes; a pure move, no field of the session touched, a dump and the wire as they were; gates on tui: core-test 960/960, behaviour-test 238/238
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/Event.zig')
| -rw-r--r-- | src/Event.zig | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/src/Event.zig b/src/Event.zig new file mode 100644 index 00000000..cc359974 --- /dev/null +++ b/src/Event.zig @@ -0,0 +1,149 @@ +//! 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 pdf_enabled = @import("panes.zig").Pdf.enabled; +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, +}; + +pub const Key = struct { + cp: u21, // codepoint or one of the specials below + text: []const u8 = "", + ctrl: bool = false, + alt: bool = false, + shift: bool = false, + + pub const enter: u21 = 0x0D; + pub const escape: u21 = 0x1B; + pub const tab: u21 = 0x09; + pub const backspace: u21 = 0x7F; + // private-use plane for non-text keys, matching no real codepoint + pub const up: u21 = 0xF0001; + pub const down: u21 = 0xF0002; + pub const left: u21 = 0xF0003; + pub const right: u21 = 0xF0004; + pub const home: u21 = 0xF0005; + pub const end: u21 = 0xF0006; + pub const page_up: u21 = 0xF0007; + pub const page_down: u21 = 0xF0008; + pub const delete: u21 = 0xF0009; + pub const insert: u21 = 0xF000A; + pub const print_screen: u21 = 0xF000B; + pub const scroll_lock: u21 = 0xF000C; + pub const pause: u21 = 0xF000D; + pub const menu: u21 = 0xF000E; + /// F1 to F25, in order: Fn is `f1 + n - 1`. + pub const f1: u21 = 0xF0011; + pub const f25: u21 = f1 + 24; +}; + +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); + +/// Pixel dimensions are meaningful only to the native PDF placement path. +/// Keep resize events layout-only when that path is not part of the build. +pub const CellPixels = if (pdf_enabled) struct { + w: u16 = 8, + h: u16 = 16, +} else struct {}; + +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, + /// Native shells may preserve sub-cell wheel distance in physical pixels. + /// TTY button events still enter through the ordinary mouse path. + /// `glide`: a wheel's notch, which the strip glides; a touchpad's + /// fraction is followed as it comes. + pdf_scroll: struct { pane: u8, delta_pixels: f32, glide: bool = true }, + /// 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, + 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, native_image_patches: bool = false }; |
