diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 06:24:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 11:19:44 -0300 |
| commit | c1917b949b9580de8bf0977874a210f0266812da (patch) | |
| tree | 447dd2235ea00634f662cd3becf4bceb8a895f41 /src/mouse.zig | |
| parent | 76c55b5bce0f181b0b15b16596c900397dfef544 (diff) | |
| download | pardes-c1917b949b9580de8bf0977874a210f0266812da.tar.gz pardes-c1917b949b9580de8bf0977874a210f0266812da.zip | |
kinds #14, the core's PDF code gone: pdf.zig and pdf_view.zig leave and every pdf_enabled branch with them; look, Jump, Recent, dumps (one from before the addon opens as its pane), the watch, mouse, keys, the rail and the tag go through Kind for any kind's pane; test/pdf.zig's behaviours are T1 cases over 9P (addons_pdf.zig) and pane cases (a Shadow over a replica, a file changed under it), the harnesses load pdf.so by path
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/mouse.zig')
| -rw-r--r-- | src/mouse.zig | 102 |
1 files changed, 25 insertions, 77 deletions
diff --git a/src/mouse.zig b/src/mouse.zig index 7eab8322..6e8c1719 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -14,8 +14,6 @@ const edit = @import("edit.zig"); const body_layer = @import("body_layer.zig"); const builtins = @import("builtins.zig"); const config = @import("config.zig"); -const pdf_enabled = panes.Pdf.enabled; -const pdf = panes.Pdf.pdf; const platform = pardes.platform; const Pane = panes.Pane; const MAX_PANES = pardes.MAX_PANES; @@ -52,9 +50,6 @@ pub const Drag = union(enum) { /// Where the sweep began in the text, once it has scrolled: its /// press row may be off the screen. anchor: ?modal.Cursor = null, - /// This gesture began over a usable native PDF raster. The payload is - /// zero-bit when PDF support is absent. - pdf: panes.Pdf.PointerDrag = .{}, /// Where its body was in the frontend's frame at its last hit there: /// a sweep that leaves it is clamped back onto it (`bodyHitForPane`). body: ?Layer.Place = null, @@ -385,7 +380,9 @@ fn tracksMouse(pane: *const Pane) bool { /// program's, reported without the Shift that chose it. True when the /// event was the program's. /// The pointer over the body of a pane whose kind takes the mouse: the -/// kind's, a press focusing the pane first. +/// kind's, a press focusing the pane first, its drag and release the +/// kind's wherever they go (clamped to its body); a pointer leaving the +/// body is told as a motion at 0xffff. fn kindMouse(p: *Pardes, m: Mouse) bool { const v = p.view(); if (v.drag != .none or v.header_drag or v.header_sweep != null) return false; @@ -396,13 +393,30 @@ fn kindMouse(p: *Pardes, m: Mouse) bool { const r = v.rects[id]; const top = p.bodyTop(pane, r) + pane.notices.span(); const x0 = r.x + config.GUTTER; - if (m.col < x0 or m.col >= r.x + r.w or m.row < top or m.row >= r.y + r.h) continue; + const inside = m.col >= x0 and m.col < r.x + r.w and m.row >= top and m.row < r.y + r.h; + const grabbed = v.kind_grab != null and v.kind_grab.? == id and (m.kind == .drag or m.kind == .release); + if (!inside and !grabbed) continue; + if (v.kind_hover != null and v.kind_hover.? != id) kindLeave(p); + v.kind_hover = @intCast(id); if (m.kind == .press) v.active = id; - return pardes.Kind.mouse(p, id, m, m.col - x0, m.row - top); + if (m.kind == .press and m.button != .wheel_up and m.button != .wheel_down and m.button != .wheel_left and m.button != .wheel_right) v.kind_grab = @intCast(id); + if (m.kind == .release) v.kind_grab = null; + const col = std.math.clamp(m.col, x0, r.x + r.w -| 1) - x0; + const row = std.math.clamp(m.row, top, r.y + r.h -| 1) - top; + return pardes.Kind.mouse(p, id, m, col, row); } + kindLeave(p); return false; } +/// The pointer has left the kind's pane it was over: told so, once. +pub fn kindLeave(p: *Pardes) void { + const v = p.view(); + const id = v.kind_hover orelse return; + v.kind_hover = null; + _ = pardes.Kind.mouse(p, id, .{ .button = .none, .kind = .motion, .col = 0, .row = 0 }, 0xffff, 0xffff); +} + fn programMouse(p: *Pardes, m: Mouse) bool { const v = p.view(); const button: ?panes.terminal.MouseButton = switch (m.button) { @@ -699,9 +713,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { _ = config.wheelTick(&v.wheel_guard, true); const id = hovered orelse return; const pane = p.panes[id].?; - if (pane.hasPdf()) - panes.Pdf.verticalWheel(p, pane, if (m.button == .wheel_up) -1 else 1) - else if (!programWheel(p, id, m, mcol, mrow)) + if (!programWheel(p, id, m, mcol, mrow)) pane.scrollBy(if (m.button == .wheel_up) -config.wheel_rows else config.wheel_rows); }, .wheel_left, .wheel_right => { @@ -711,10 +723,6 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { const pane = p.panes[id].?; if (programWheel(p, id, m, mcol, mrow)) { // the program's - } else if (pane.hasPdf()) { - panes.Pdf.horizontalWheel(p, pane, if (m.button == .wheel_right) 1 else -1); - // ponytail: no right clamp — overscroll shows blank and the - // next cursor move or left wheel pulls it back } else if (pane.file != null and !p.settings.wrap) { // wrapped there is nothing off to the right to reach const line = panes.File.sourceLine(pane, pane.body.cur_row); @@ -740,8 +748,6 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { if (v.drag == .select and v.drag.select.button == config.look_button) { if (p.panes[v.drag.select.id]) |t| { t.sel[@backingInt(config.look_button)].state = .none; - if (comptime pdf_enabled) - panes.Pdf.pointerCancel(t, v.drag.select.pdf); } v.drag = .none; return; @@ -827,14 +833,6 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { .button = config.select_button, .ctrl = m.ctrl, .body = bodyPlace(m.body_hit, pane), - .pdf = panes.Pdf.pointerStart( - p, - pane, - config.select_button, - mcol, - mrow, - pointed.on_tag, - ), } }; } }, @@ -858,8 +856,6 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { if (v.drag == .select) { if (p.panes[v.drag.select.id]) |t| { t.sel[@backingInt(v.drag.select.button)].state = .none; - if (comptime pdf_enabled) - panes.Pdf.pointerCancel(t, v.drag.select.pdf); } v.drag = .none; return; @@ -885,16 +881,6 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { .id = id, .button = m.button, .body = bodyPlace(m.body_hit, pane), - // A native body gesture stays native even when its - // point later misses a letterbox or selection. - .pdf = panes.Pdf.pointerStart( - p, - pane, - m.button, - mcol, - mrow, - pointed.on_tag, - ), }, }; } @@ -979,7 +965,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo // from the pointer. const body_y = p.bodyTop(pane, r); const body_h = r.h -| pane.tag_rows; - s.edge = if (s.button != config.select_button or pane.sel[b].r0 < tag_rows or pane.file == null or pane.hasPdf() or body_h == 0) + s.edge = if (s.button != config.select_button or pane.sel[b].r0 < tag_rows or pane.file == null or body_h == 0) 0 else if (mrow < body_y) -1 @@ -997,8 +983,6 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo else @as(i32, @min(@max(mrow, body_y), body_y + body_h - 1)) - @as(i32, body_y) + tag_rows; if (pane.sel[b].r1 < tag_rows) pane.sel[b].c1 += @as(i32, pane.tag_scroll); - if (comptime pdf_enabled) - panes.Pdf.pointerUpdate(&s.pdf, p, pane, mcol, mrow); } }, .none => {}, @@ -1140,7 +1124,7 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void { if (rows.len == 0) return; const forward = gesture.r1 > gesture.r0 or (gesture.r1 == gesture.r0 and gesture.c1 >= gesture.c0); const endpoint = rows[if (forward) rows.len - 1 else 0]; - const body = body_layer.bodyText(p, p.scratch.allocator(), pane) catch return; + const body = body_layer.bodyText(p.scratch.allocator(), pane) catch return; const line = modal.lineSlice(body, @intCast(@max(0, endpoint.row - panes.terminal.gridOffset(pane)))); const byte = if (forward) modal.prevGrapheme(line, @min(endpoint.hi, line.len)) else endpoint.lo; pane.body.cur_row = pane.surfRow(endpoint.row); @@ -1251,32 +1235,6 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { }, .select => |s| { const pane = p.panes[s.id] orelse return; - if (comptime pdf_enabled) { - if (s.pdf.native) { - var release = panes.Pdf.pointerRelease( - p, - pane, - s.pdf, - s.button, - s.chorded, - ); - defer release.deinit(p.pdf_gpa); - if (release.probe) |*probe| if (probe.link != null) { - look.followPdfLink(p, s.id, probe); - return; - }; - // A native PDF page has no byte offsets of its own to - // report, so a scripted pane cannot intercept this one. - if (release.action) |action| dispatchPointerBuiltin( - p, - s.id, - if (action == .look) config.look_cmd else config.exec_cmd, - release.text, - null, - ); - return; - } - } if (s.chorded) { // a cut/paste chord consumed this drag; the release is inert pane.sel[@backingInt(s.button)].state = .none; @@ -1402,16 +1360,6 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { fn chordCutPaste(p: *Pardes, cut: bool) void { const s = &p.view().drag.select; const pane = p.panes[s.id] orelse return; - if (comptime pdf_enabled) if (pane.pdf) |pv| { - if (!s.chorded) { - s.chorded = true; - pane.sel[sel_slot].state = .none; - } - // A PDF is immutable: its Cut-side chord is Snarf (copy), while - // Paste has no document mutation to perform. - if (cut and pv.selection_text.len > 0) edit.setYank(p, pv.selection_text); - return; - }; if (@min(pane.sel[sel_slot].r0, pane.sel[sel_slot].r1) < pane.tag_rows) { // A sweep over the tag cuts from and pastes into the tag's own text; // the part of it over the prefix is not the tag's to cut, so the |
