diff options
| -rw-r--r-- | src/Event.zig | 149 | ||||
| -rw-r--r-- | src/pardes.zig | 147 |
2 files changed, 156 insertions, 140 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 }; diff --git a/src/pardes.zig b/src/pardes.zig index 75833e5f..1e9f1669 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -49,6 +49,13 @@ pub const Region = @import("surface.zig").Region; pub const Chrome = @import("surface.zig").Chrome; pub const RailTick = @import("surface.zig").RailTick; pub const MAX_REGIONS = @import("surface.zig").MAX_REGIONS; +/// What comes in (Event.zig). +pub const Mouse = @import("Event.zig").Mouse; +pub const Key = @import("Event.zig").Key; +pub const hit = @import("Event.zig").hit; +pub const sel_slot = @import("Event.zig").sel_slot; +pub const CellPixels = @import("Event.zig").CellPixels; +pub const Event = @import("Event.zig").Event; pub const builtins = @import("builtins.zig"); /// Every builtin as JSON, for the docs (tools/gen_builtins_json.zig). pub const builtins_json = @import("builtins_json.zig"); @@ -2643,149 +2650,9 @@ test "s in a header selects in the header's own text" { try std.testing.expectEqual(@as(u16, 0), pane.body.nsel); } -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 {}; - /// Said at a focus-in when the Host's `newer_build` answers yes (upgrade.zig). pub const newer_build_words = "a newer pardes is installed: Upgrade (SPC s U) moves this session onto it"; -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 }; - pub const PendingWrite = struct { bytes: []u8, off: usize = 0 }; /// `command` is Kill's: SIGTERM to the terminal's foreground job, and never |
