summaryrefslogtreecommitdiff
path: root/src/mouse.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 11:50:43 -0300
committerGabriel Schneider <[email protected]>2026-11-05 15:17:05 -0300
commitecdb0996147f319a4427273bf276e1fc5bf89156 (patch)
tree0b1be457ce4b8ce99db4acd713ff2620cde2d015 /src/mouse.zig
parent2bd4066a932ec8fc401e4b85e9f8441b17df3cfb (diff)
downloadpardes-ecdb0996147f319a4427273bf276e1fc5bf89156.tar.gz
pardes-ecdb0996147f319a4427273bf276e1fc5bf89156.zip
effects out, the panel transitions: the eleven Panel words in both tracks go, with the core's Presentation (tracks, the frozen previous grid, cell diffs, the acknowledged-geometry pending guard, and the pointer's mapping through a moving pane, so a pointer's cell is the cell it is over), draw.zig's core-composed character effects, animation.zig's transition half, the Surface's tracks and previous grid, the tty's compositor (src/tui/panel_compositor.zig: the glide's rows move into tui.zig) and the window's track groups, frozen old layers, last-frame image snapshot, transition instance fields and shader paths (ui.vert, ui.frag's crossfade, image.vert and image.frag, the transition-<n>.ppm capture); acknowledgePanelPresentation becomes `presented`, which a frontend calls after drawing a frame (a drag's moving end and a look-hover follow what is under the pointer now), and its tape site with it; the pointer tape site goes; GUI golden 18-mid-transition goes, ttyhelp's golden loses the `SPC a` rows (its wait is on `SPC Y` now), the window monkey loses PanelSlide, and the settings behaviour test's floor of on/off words is ten
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/mouse.zig')
-rw-r--r--src/mouse.zig265
1 files changed, 7 insertions, 258 deletions
diff --git a/src/mouse.zig b/src/mouse.zig
index e38d5d5f..6cb602f7 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -7,14 +7,11 @@ const exec = @import("exec.zig");
const look = @import("look.zig");
const std = @import("std");
const layout = @import("layout.zig");
-const Presentation = @import("Presentation.zig");
-const animation = @import("animation.zig");
const modal = @import("modal.zig");
const ctlfs = @import("ninep/tree.zig");
const panes = @import("panes.zig");
const edit = @import("edit.zig");
const body_layer = @import("body_layer.zig");
-const PanelCellDiff = @import("surface.zig").PanelCellDiff;
const builtins = @import("builtins.zig");
const config = @import("config.zig");
const pdf_enabled = panes.Pdf.enabled;
@@ -393,7 +390,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
else => return false,
};
const bit: u3 = if (button) |b| @as(u3, 1) << @intCast(@backingInt(b)) else 0;
- const at = p.pointerCell(@min(m.col, p.screen_w -| 1), @min(m.row, p.screen_h -| 1));
+ const at: struct { col: u16, row: u16 } = .{ .col = @min(m.col, p.screen_w -| 1), .row = @min(m.row, p.screen_h -| 1) };
var mods: panes.terminal.MouseMods = .{ .shift = m.shift, .alt = m.alt, .ctrl = m.ctrl };
var buf: [64]u8 = undefined;
if (p.mouse_grab) |*grab| {
@@ -409,8 +406,8 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
// Off the grid the cell runs on past its edge, and the encoder
// clamps it there.
const r = p.rects[grab.id];
- const col: i32 = if (at) |a| @as(i32, a.col) - @as(i32, r.x + config.GUTTER) else 0;
- const row: i32 = if (at) |a| @as(i32, a.row) - @as(i32, p.bodyTop(pane, r)) else 0;
+ const col: i32 = @as(i32, at.col) - @as(i32, r.x + config.GUTTER);
+ const row: i32 = @as(i32, at.row) - @as(i32, p.bodyTop(pane, r));
const action: panes.terminal.MouseAction = switch (m.kind) {
.press => .press,
.release => .release,
@@ -427,7 +424,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
const shifted_to_program = m.button == .middle or m.button == .right;
if (m.shift != shifted_to_program) return false;
if (shifted_to_program) mods.shift = false;
- const mapped = at orelse return false;
+ const mapped = at;
const id = paneAt(p, mapped.col, mapped.row) orelse return false;
const pane = p.panes[id].?;
if (!tracksMouse(pane)) return false;
@@ -550,17 +547,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
return;
}
p.raw_hover_intent = false;
- const mapped = p.pointerCell(raw_col, raw_row) orelse {
- look.cancelLookHover(p);
- if (m.kind == .release) {
- if (p.header_sweep) |sweep| if (sweep.button == m.button) {
- p.header_sweep = null;
- return headerSweepRun(p, sweep);
- };
- dragRelease(p, m.button);
- }
- return;
- };
+ const mapped: struct { col: u16, row: u16 } = .{ .col = raw_col, .row = raw_row };
const mcol = mapped.col;
const mrow = mapped.row;
p.hover_col = mcol;
@@ -1527,18 +1514,16 @@ test "plain left click clears explicit modal selection" {
try std.testing.expectEqual(.none, pane.sel[@backingInt(config.select_button)].state);
}
-test "selection drag and queued release do not enter panel pending state" {
+test "a selection drag and its release leave the selection done" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 10, .tty_only = true });
defer p.deinit();
const pane = try p.setTestFile("alpha beta\n");
- p.acknowledgePanelPresentation(&.{});
const rect = p.rects[0];
const x = rect.x + config.GUTTER + config.PREFIX_W + 1;
const y = rect.y + BOX_H;
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = x, .row = y } });
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .drag, .col = x + 2, .row = y } });
- try std.testing.expect(!p.presentation.pending);
p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = x + 2, .row = y } });
try std.testing.expect(p.drag == .none);
try std.testing.expectEqual(.done, pane.sel[sel_slot].state);
@@ -1686,242 +1671,6 @@ test "a RIGHT-column corner's two axes clamp independently" {
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = 999 } });
}
-test "pointer coordinates follow presented panel geometry" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20, .tty_only = true });
- defer p.deinit();
- const pane = p.panes[0].?;
-
- const moving: animation.Track = .{
- .serial = pane.serial,
- .pane = 0,
- .phase = .moving,
- .effect = .slide,
- .from = .{ .x = 20, .y = 5, .w = 40, .h = 10 },
- .to = .{ .x = 0, .y = 1, .w = 80, .h = 18 },
- };
- p.acknowledgePanelPresentation(&.{moving});
- // One shared physical-to-logical map feeds all pointer gestures. The
- // selected sample is 26.25% across and 35% down the presented rectangle.
- try std.testing.expectEqual(Presentation.CellPosition{ .col = 21, .row = 7 }, p.presentation.pointer(p.screen_w, p.screen_h, 30, 8).?);
- // Canonical cells covered only by the not-yet-arrived target are inert.
- try std.testing.expect(p.presentation.pointer(p.screen_w, p.screen_h, 2, 2) == null);
- // Unrelated screen space remains in the ordinary grid coordinate system.
- try std.testing.expectEqual(Presentation.CellPosition{ .col = 100, .row = 10 }, p.presentation.pointer(p.screen_w, p.screen_h, 100, 10).?);
-
- p.acknowledgePanelPresentation(&.{animation.Track{
- .serial = pane.serial,
- .pane = 0,
- .phase = .opening,
- .effect = .zoom,
- .from = .{ .x = 40, .y = 10, .w = 0, .h = 0 },
- .to = .{ .x = 0, .y = 1, .w = 80, .h = 18 },
- }});
- try std.testing.expect(p.presentation.pointer(p.screen_w, p.screen_h, 40, 10) == null);
-
- // Tracks paint in pane-slot order inside a phase. The later slot is the
- // top quad and therefore owns an overlap, even though both are moving.
- const overlap = [_]animation.Track{ .{
- .serial = pane.serial,
- .pane = 0,
- .phase = .moving,
- .effect = .slide,
- .from = .{ .x = 20, .y = 2, .w = 20, .h = 4 },
- .to = .{ .x = 0, .y = 2, .w = 20, .h = 4 },
- }, .{
- .serial = pane.serial + 1,
- .pane = 1,
- .phase = .moving,
- .effect = .slide,
- .from = .{ .x = 20, .y = 2, .w = 20, .h = 4 },
- .to = .{ .x = 60, .y = 2, .w = 20, .h = 4 },
- } };
- p.presentation.shown_tracks = @splat(null);
- p.presentation.shown_tracks[0] = overlap[0];
- p.presentation.shown_tracks[1] = overlap[1];
- try std.testing.expectEqual(Presentation.CellPosition{ .col = 65, .row = 3 }, p.presentation.pointer(p.screen_w, p.screen_h, 25, 3).?);
-}
-
-test "queued pointer input is inert until a changed layout is presented" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 16, .tty_only = true });
- defer p.deinit();
- // Establish that a real host has presented the boot layout.
- p.acknowledgePanelPresentation(&.{});
- p.settings.panel_transition = .slide;
-
- _ = try p.newShell(1, "");
- try std.testing.expect(layout.splitColumn(p, 0, 1, false));
- p.sync();
- try std.testing.expect(p.presentation.pending);
- try std.testing.expect(p.presentation.pointer(p.screen_w, p.screen_h, 10, 4) == null);
-
- var tracks: [MAX_PANES]animation.Track = undefined;
- var len: usize = 0;
- for (p.presentation.tracks) |maybe| if (maybe) |track| {
- tracks[len] = track;
- len += 1;
- };
- p.acknowledgePanelPresentation(tracks[0..len]);
- try std.testing.expect(!p.presentation.pending);
- // Whether this particular opening sample exposes the chosen cell is the
- // transition's concern; it is no longer rejected merely as speculative.
- try std.testing.expect(p.presentation.pointer(p.screen_w, p.screen_h, 99, 4) != null);
-}
-
-test "pointer rejects panel content cells which have not materialized" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 12, .tty_only = true });
- defer p.deinit();
- const pane = p.panes[0].?;
- const target: animation.Box = .{ .x = 4, .y = 2, .w = 32, .h = 4 };
- p.presentation.diffs = try p.gpa.alloc(PanelCellDiff, @as(usize, p.screen_w) * p.screen_h);
- @memset(p.presentation.diffs, .unchanged);
- for (2..6) |row| {
- for (4..36) |col| {
- // Distances on both sides of frame five prove that finished ASCII
- // bytes are clickable while bytes still walking are not.
- p.presentation.diffs[row * p.screen_w + col] = .{ .ascii = .{
- .from = ' ',
- .to = @intCast(' ' + (col - 4) % 12 + 1),
- } };
- }
- }
- p.presentation.diff_state = .ready;
-
- for ([_]animation.Transition{ .dissolve, .ascii }) |effect| {
- const frame: u16 = if (effect == .dissolve) 3 else 5;
- const track: animation.Track = .{
- .serial = pane.serial,
- .pane = 0,
- .phase = .opening,
- .effect = effect,
- .frame = frame,
- .from = target,
- .to = target,
- };
- p.acknowledgePanelPresentation(&.{track});
-
- var saw_visible = false;
- var saw_hidden = false;
- for (0..4) |relative_row| for (0..32) |relative_col| {
- const rcol: u16 = @intCast(relative_col);
- const rrow: u16 = @intCast(relative_row);
- const col: u16 = @intCast(4 + relative_col);
- const row: u16 = @intCast(2 + relative_row);
- const visible = switch (effect) {
- .dissolve => animation.dissolveRevealed(
- pane.serial,
- rcol,
- rrow,
- track.amount(),
- ),
- .ascii => switch (p.presentation.cellDiff(p.screen_w, p.screen_h, col, row)) {
- .ascii => |diff| diff.complete(track.frame),
- .unchanged, .visual => true,
- },
- else => unreachable,
- };
- const mapped = p.presentation.pointer(p.screen_w, p.screen_h, col, row);
- try std.testing.expectEqual(visible, mapped != null);
- if (mapped) |point|
- try std.testing.expectEqual(Presentation.CellPosition{ .col = col, .row = row }, point);
- saw_visible = saw_visible or visible;
- saw_hidden = saw_hidden or !visible;
- };
- try std.testing.expect(saw_visible);
- try std.testing.expect(saw_hidden);
- }
-}
-
-test "unchanged content cells remain clickable through data effects" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 40, .rows = 10, .tty_only = true });
- defer p.deinit();
- const pane = p.panes[0].?;
- p.presentation.diffs = try p.gpa.alloc(PanelCellDiff, @as(usize, p.screen_w) * p.screen_h);
- @memset(p.presentation.diffs, .unchanged);
- p.presentation.diff_state = .ready;
- const box: animation.Box = .{ .x = 2, .y = 2, .w = 20, .h = 4 };
-
- for ([_]animation.Transition{ .dissolve, .ascii }) |effect| {
- p.acknowledgePanelPresentation(&.{.{
- .serial = pane.serial,
- .pane = 0,
- .phase = .opening,
- .effect = effect,
- .from = box,
- .to = box,
- }});
- try std.testing.expectEqual(Presentation.CellPosition{ .col = 8, .row = 3 }, p.presentation.pointer(p.screen_w, p.screen_h, 8, 3).?);
- }
-}
-
-test "held drag follows acknowledged panels and balances an invisible release" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20, .tty_only = true });
- defer p.deinit();
- const pane = p.panes[0].?;
- const target = layout.panelBox(p.rects[0]);
- var track: animation.Track = .{
- .serial = pane.serial,
- .pane = 0,
- .phase = .moving,
- .effect = .slide,
- .from = .{ .x = 50, .y = 5, .w = 20, .h = 8 },
- .to = target,
- };
- const raw_col: u16 = 55;
- const raw_row: u16 = 7;
- p.acknowledgePanelPresentation(&.{track});
- p.update(.{ .mouse = .{
- .button = config.select_button,
- .kind = .press,
- .col = raw_col,
- .row = raw_row,
- } });
- try std.testing.expect(p.drag == .select);
- const first_col = pane.sel[sel_slot].c1;
- const first_row = pane.sel[sel_slot].r1;
-
- // Advancing producer state alone cannot move input. Only the sample the
- // host says it actually drew may remap the stationary held endpoint.
- track.frame = track.effect.frames() - 1;
- p.presentation.tracks[0] = track;
- try std.testing.expectEqual(first_col, pane.sel[sel_slot].c1);
- try std.testing.expectEqual(first_row, pane.sel[sel_slot].r1);
- p.acknowledgePanelPresentation(&.{track});
- try std.testing.expect(first_col != pane.sel[sel_slot].c1 or
- first_row != pane.sel[sel_slot].r1);
-
- const last_col = pane.sel[sel_slot].c1;
- const last_row = pane.sel[sel_slot].r1;
- track.phase = .opening;
- track.effect = .zoom;
- track.frame = 0;
- track.from = .{
- .x = target.x + target.w * 0.5,
- .y = target.y + target.h * 0.5,
- };
- p.acknowledgePanelPresentation(&.{track});
- try std.testing.expect(p.presentation.pointer(p.screen_w, p.screen_h, raw_col, raw_row) == null);
- try std.testing.expectEqual(last_col, pane.sel[sel_slot].c1);
- try std.testing.expectEqual(last_row, pane.sel[sel_slot].r1);
-
- // An unrelated release cannot consume the left drag. Its own release is
- // nevertheless balanced at the retained endpoint while the cell is dark.
- p.update(.{ .mouse = .{
- .button = config.exec_button,
- .kind = .release,
- .col = raw_col,
- .row = raw_row,
- } });
- try std.testing.expect(p.drag == .select);
- p.update(.{ .mouse = .{
- .button = config.select_button,
- .kind = .release,
- .col = raw_col,
- .row = raw_row,
- } });
- try std.testing.expect(p.drag == .none);
- try std.testing.expectEqual(.done, pane.sel[sel_slot].state);
-}
-
test "mouse thumb buttons navigate once and clear selection gestures" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
defer p.deinit();
@@ -2060,7 +1809,7 @@ test "Alt-click is B2 and Super-click B3, kept from the press through the releas
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
const file = try p.setTestFile("Newcol here\n");
- p.acknowledgePanelPresentation(&.{});
+ p.presented();
const r = p.rects[0];
const col = r.x + config.GUTTER + panes.File.gutterWidth(file) + 1;
const row = p.bodyTop(file, r);