summaryrefslogtreecommitdiff
path: root/src/macos.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/macos.zig')
-rw-r--r--src/macos.zig83
1 files changed, 79 insertions, 4 deletions
diff --git a/src/macos.zig b/src/macos.zig
index a63ac626..4f616945 100644
--- a/src/macos.zig
+++ b/src/macos.zig
@@ -451,6 +451,7 @@ const State = struct {
rotate_velocity: f32 = 0,
rotate_last_ns: i128 = 0,
rotate_coasting: bool = false,
+ pointer_rule_above: bool = false,
scene_ns: u64 = 0,
last_tick_ns: u64 = 0,
tick_bank_ns: u64 = 0,
@@ -1436,7 +1437,7 @@ export fn pardes_paste(text_ptr: ?[*]const u8, len: usize) void {
export fn pardes_mouse(button_arg: c_int, kind_arg: c_int, col: u16, row: u16, mods: u32) void {
pardes.turn.wake();
defer pardes.turn.rest();
- mouseWithHit(button_arg, kind_arg, col, row, mods, null, null);
+ mouseWithHit(button_arg, kind_arg, col, row, mods, null, null, false);
}
export fn pardes_mouse_pixel(button_arg: c_int, kind_arg: c_int, col: u16, row: u16, mods: u32, x: f32, y: f32, bw: f32, bh: f32, tw: f32, th: f32) void {
@@ -1456,10 +1457,14 @@ export fn pardes_mouse_pixel(button_arg: c_int, kind_arg: c_int, col: u16, row:
tag_hit = layer.tagHit(point.x * bw, point.y * bh, bw, bh, tw, th);
if (tag_hit != null) break;
}
- mouseWithHit(button_arg, kind_arg, col, row, mods, hit, tag_hit);
+ const rule_above = if (source) |point|
+ row > 0 and (point.y - @floor(point.y)) * @max(1, bh) < 3
+ else
+ false;
+ mouseWithHit(button_arg, kind_arg, col, row, mods, hit, tag_hit, rule_above);
}
-fn mouseWithHit(button_arg: c_int, kind_arg: c_int, col: u16, row: u16, mods: u32, hit: ?pardes.Mouse.BodyHit, tag_hit: ?pardes.TagHit) void {
+fn mouseWithHit(button_arg: c_int, kind_arg: c_int, col: u16, row: u16, mods: u32, hit: ?pardes.Mouse.BodyHit, tag_hit: ?pardes.TagHit, rule_above: bool) void {
const st = &(state orelse return);
const button: pardes.Mouse.Button = switch (button_arg) {
0 => .left,
@@ -1481,10 +1486,12 @@ fn mouseWithHit(button_arg: c_int, kind_arg: c_int, col: u16, row: u16, mods: u3
3 => .drag,
else => return,
};
+ st.pointer_rule_above = rule_above;
st.core.update(.{
.mouse = .{
.body_hit = hit,
.tag_hit = tag_hit,
+ .rule_above = rule_above,
.button = button,
.kind = kind,
.col = col,
@@ -1914,6 +1921,9 @@ export fn pardes_tag_layer_value(index: u32, field: u32) u32 {
const st = &(state orelse return 0);
if (index >= pardes.MAX_TAG_LAYERS) return 0;
const layer = &st.core.surface.tag_layers[index];
+ // The renderer retires a layer by clearing rows, retaining its storage
+ // and geometry for reuse. Do not expose that stale band to AppKit.
+ if (layer.rows == 0) return 0;
return switch (field) {
0 => layer.cols,
1 => @backingInt(layer.kind),
@@ -1998,7 +2008,34 @@ export fn pardes_pointer_shape() u32 {
pardes.turn.wake();
defer pardes.turn.rest();
const st = &(state orelse return 0);
- return @backingInt(st.core.surface.pointer_shape);
+ return nativePointerShape(st.core, st.pointer_rule_above);
+}
+
+fn nativePointerShape(core: *const pardes.Pardes, rule_above: bool) u32 {
+ switch (core.drag) {
+ .move, .column_move => return 3,
+ .border_v => return 5,
+ .border_h => return 6,
+ .select => return @backingInt(core.surface.pointer_shape),
+ .none => {},
+ }
+ if (core.pointer_inside) for (core.surface.regions[0..core.surface.nregions]) |region| {
+ if (region.kind != .grip and region.kind != .column_grip) continue;
+ const r = region.rect;
+ if (core.hover_col >= r.x and core.hover_col - r.x < r.w and
+ core.hover_row >= r.y and core.hover_row - r.y < r.h) return 4;
+ };
+ if (core.pointer_inside) {
+ for (0..core.ncol -| 1) |column| {
+ if (core.hover_col == core.col_x[column] + core.col_w[column] -| 1) return 5;
+ }
+ if (rule_above and core.hover_row > 0) for (0..core.ncol) |column| {
+ if (core.hover_col < core.col_x[column] or core.hover_col >= core.col_x[column] + core.col_w[column]) continue;
+ const seam = if (core.settings.tag_bottom) core.hover_row else core.hover_row - 1;
+ if (@import("mouse.zig").seamIdxAt(core, column, seam) != null) return 6;
+ };
+ }
+ return @backingInt(core.surface.pointer_shape);
}
export fn pardes_cursor_y() i32 {
@@ -2877,6 +2914,44 @@ test "mac tag layer ABI preserves logical capacity and physical grip" {
try std.testing.expectEqual(@as(u8, 'G'), canonical[9].text[0]);
try std.testing.expectEqual(@as(u8, 'G'), canonical[18].text[0]);
try std.testing.expectEqual(encodeCell(.{}).len, canonical[10].len);
+
+ // Dismissed notices and old tag positions retain their capacity. They
+ // must disappear from the host's layout as well as its cell buffer, or
+ // AppKit keeps painting their borders over otherwise empty pane bodies.
+ core.surface.tag_layers[0].rows = 0;
+ for (0..13) |field| try std.testing.expectEqual(@as(u32, 0), pardes_tag_layer_value(0, @intCast(field)));
+ try std.testing.expect(pardes_tag_layer_cells(0) == null);
+}
+
+test "mac drag pointer follows pane and column grips and releases" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer core.deinit();
+ _ = try core.setTestFile("text\n");
+ core.presentation.enabled = false;
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ _ = try core.render(arena.allocator());
+ for ([_]pardes.Region.Kind{ .grip, .column_grip }) |kind| {
+ const r = for (core.surface.regions[0..core.surface.nregions]) |region| {
+ if (region.kind == kind) break region.rect;
+ } else return error.NoGrip;
+ core.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = r.x, .row = r.y } });
+ try std.testing.expectEqual(@as(u32, 4), nativePointerShape(core, false));
+ core.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = r.x, .row = r.y } });
+ try std.testing.expectEqual(@as(u32, 3), nativePointerShape(core, false));
+ core.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = r.x, .row = r.y } });
+ try std.testing.expectEqual(@as(u32, 4), nativePointerShape(core, false));
+ }
+ core.pointer_inside = false;
+ core.surface.pointer_shape = .arrow;
+ try std.testing.expectEqual(@as(u32, 0), nativePointerShape(core, false));
+ core.surface.pointer_shape = .link;
+ try std.testing.expectEqual(@as(u32, 1), nativePointerShape(core, false));
+ core.drag = .{ .border_v = .{ .left_col = 0, .cur_x = 40 } };
+ try std.testing.expectEqual(@as(u32, 5), nativePointerShape(core, false));
+ core.drag = .{ .border_h = .{ .col = 0, .top_idx = 0, .cur_y = 12 } };
+ try std.testing.expectEqual(@as(u32, 6), nativePointerShape(core, false));
}
test "mac window blur builtin reaches the ABI without changing opacity" {