1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
//! 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,
/// How the host's `addon` effect went: `text` the kind's name, or
/// why not (Kind.landed). Borrowed for the step.
addon: struct { op: @import("Kind.zig").AddonOp, pane: u8, ok: bool, text: []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"} };
};
|