summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-21 21:30:19 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:15 -0300
commit02841e214442c7a602877883425757b0dab3f924 (patch)
tree8e27863c52d128a6fb69d2dbf69e8b5b1df57941 /src
parentb730ce12667fb75c99b97eafcfc73d7b1f8bdd13 (diff)
downloadpardes-02841e214442c7a602877883425757b0dab3f924.tar.gz
pardes-02841e214442c7a602877883425757b0dab3f924.zip
A click that takes focus glides the cursor once, straight to the click
Diffstat (limited to 'src')
-rw-r--r--src/CHANGELOG.md2
-rw-r--r--src/draw.zig47
-rw-r--r--src/pardes.zig3
3 files changed, 48 insertions, 4 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 1d6a1e71..362aaf5b 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -22,6 +22,8 @@
numbers no longer come along with the first line.
- The GUI's scrollbar thumb moves by the pixel and follows a smooth
scroll as it glides, instead of jumping a row of the track at a time.
+- A click in another pane glides the cursor once, straight to where it
+ was clicked, no longer first to that pane's old cursor.
- Built with Zig 0.17. A bare `zig build` still puts the binaries in
`~/.local/bin`, now as a copy beside the prefix, which `--prefix` no
diff --git a/src/draw.zig b/src/draw.zig
index 84575873..31157b1d 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -282,15 +282,20 @@ fn glideCursor(p: *Pardes, s: *Surface) void {
const seen = frame.unplace(old.place(at));
p.cursor_glide.shift(seen[0] - at[0], seen[1] - at[1]);
p.cursor_crossing = true;
+ p.cursor_held = p.drag == .select;
}
p.cursor_view = .{ .serial = pane.serial, .line = line, .origin = origin, .inside = inside };
}
- p.cursor_glide.aim(box, p.now_ns, motion, snap);
+ // A click that took focus places the cursor on its release; aimed at
+ // the pane's old cursor meanwhile, it would glide there first.
+ if (p.drag != .select) p.cursor_held = false;
+ if (!p.cursor_held) p.cursor_glide.aim(box, p.now_ns, motion, snap);
_ = p.cursor_glide.step(p.now_ns);
const moving = p.cursor_glide.moving();
- if (!moving) p.cursor_crossing = false;
- // Drawn as the quad while it glides and while its pane moves.
- s.chrome.cursor_glide = 2 | @as(u8, @intFromBool(moving or frame.moving()));
+ if (!moving and !p.cursor_held) p.cursor_crossing = false;
+ // Drawn as the quad while it glides, while its pane moves and while it
+ // waits for a click's release.
+ s.chrome.cursor_glide = 2 | @as(u8, @intFromBool(moving or frame.moving() or p.cursor_held));
// The shell blinks it, from how long ago the last key or click was.
if (p.settings.cursor_blink)
s.chrome.cursor_idle_ms = @intCast(@min(std.math.maxInt(u32) - 1, (p.now_ns -| p.input_ns) / std.time.ns_per_ms));
@@ -2355,6 +2360,40 @@ test "focus moved to another column glides from where the cursor was drawn" {
try std.testing.expect(!p.cursor_glide.moving() and !p.cursor_crossing);
}
+test "a click that takes focus glides the cursor once, to where it lands on release" {
+ if (!builtins.capabilities.lift) return error.SkipZigTest;
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 });
+ defer p.deinit();
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ p.settings.motion = .smooth;
+ try twoColumns(p, &arena);
+ p.active = 0;
+ p.advance(3 * std.time.ns_per_s);
+ _ = arena.reset(.retain_capacity);
+ const before = try p.render(arena.allocator());
+ const was: [2]f32 = .{ before.chrome.cursor_quad[0], before.chrome.cursor_quad[1] };
+ // Pressed in the other column: focus moves, the cursor waits.
+ p.active = 1;
+ p.drag = .{ .select = .{ .id = 1, .button = config.select_button } };
+ for (0..3) |_| {
+ p.advance(p.now_ns + 100 * std.time.ns_per_ms);
+ _ = arena.reset(.retain_capacity);
+ const held = try p.render(arena.allocator());
+ try std.testing.expectApproxEqAbs(was[0], held.chrome.cursor_quad[0], 0.01);
+ try std.testing.expectApproxEqAbs(was[1], held.chrome.cursor_quad[1], 0.01);
+ }
+ // Released: one glide, from there to the placed cursor.
+ p.drag = .none;
+ _ = arena.reset(.retain_capacity);
+ _ = try p.render(arena.allocator());
+ try std.testing.expect(p.cursor_glide.moving());
+ p.advance(p.now_ns + 5 * std.time.ns_per_s);
+ _ = arena.reset(.retain_capacity);
+ const landed = try p.render(arena.allocator());
+ try std.testing.expectApproxEqAbs(focusedCursorBox(p, landed).?.x, landed.chrome.cursor_quad[0], 0.01);
+}
+
test "focus moving to a pane with no cursor while the cursor glides lets the session go idle" {
if (!builtins.capabilities.lift) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 });
diff --git a/src/pardes.zig b/src/pardes.zig
index 2a94c0f0..72470490 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -4550,6 +4550,9 @@ pub const Pardes = struct {
cursor_view: struct { serial: u32 = 0, line: i64 = 0, origin: [2]f32 = .{ 0, 0 }, inside: bool = true } = .{},
/// The cursor glides from one pane to another: it may cross the grid.
cursor_crossing: bool = false,
+ /// A click took focus to another pane and its button is still down: the
+ /// cursor waits where it was drawn for the release that places it.
+ cursor_held: bool = false,
input_ns: u64 = 0,
animate_theme_changes: bool = false,
native_images: bool = false,