diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/macos.zig | 83 | ||||
| -rw-r--r-- | src/macos/Sources/PardesView.swift | 25 | ||||
| -rw-r--r-- | src/macos/pardes.h | 5 | ||||
| -rw-r--r-- | src/pardes.zig | 4 |
4 files changed, 103 insertions, 14 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" { diff --git a/src/macos/Sources/PardesView.swift b/src/macos/Sources/PardesView.swift index 4ea4475a..b51f6719 100644 --- a/src/macos/Sources/PardesView.swift +++ b/src/macos/Sources/PardesView.swift @@ -2652,22 +2652,26 @@ final class PardesView: NSView { // .inVisibleRect keeps the area correct across resizes on its own, which // is why the rect argument can be anything. addTrackingArea(NSTrackingArea(rect: .zero, - options: [.mouseMoved, .mouseEnteredAndExited, .inVisibleRect, .activeInKeyWindow], + options: [.mouseMoved, .mouseEnteredAndExited, .cursorUpdate, .inVisibleRect, .activeInKeyWindow], owner: self, userInfo: nil)) } - private enum Pointer: Equatable { case text, link, target } + private enum Pointer: Equatable { case text, link, target, grab, dragging, resizeHorizontal, resizeVertical } private var pointer: Pointer = .text /// The core's pointer_shape, in this shell's cursor vocabulary: a link /// is a PDF hyperlink (the hand), a target is a word the core's own /// Look-hover plumbing validated as a real Look or Exec operand, and - /// anything else is text — the I-beam. + /// grips and dividers carry the native drag/resize affordances. private func pointerShape() -> Pointer { switch pardes_pointer_shape() { case 1: return .link case 2: return .target + case 3: return .dragging + case 4: return .grab + case 5: return .resizeHorizontal + case 6: return .resizeVertical default: return .text } } @@ -2677,14 +2681,21 @@ final class PardesView: NSView { case .link: return .pointingHand case .target: return .arrow case .text: return .iBeam + case .grab: return .openHand + case .dragging: return .closedHand + case .resizeHorizontal: return .resizeLeftRight + case .resizeVertical: return .resizeUpDown } } + override func cursorUpdate(with event: NSEvent) { + pointer = pointerShape() + cursorFor(pointer).set() + } + override func resetCursorRects() { - // Every cell in this view is text, including the tags. An arrow over - // plain text is the wrong affordance — but a word the core has - // validated as a Look or Exec target earns it: middle- and - // right-clicking there acts, and the cursor says so before it does. + // AppKit may reset cursor rectangles between frames. Keep the current + // text, target, grip or drag affordance instead of resetting to I-beam. addCursorRect(bounds, cursor: cursorFor(pointer)) } diff --git a/src/macos/pardes.h b/src/macos/pardes.h index 33db3bb5..f9aa0ec4 100644 --- a/src/macos/pardes.h +++ b/src/macos/pardes.h @@ -519,8 +519,9 @@ bool pardes_active_dirty(void); int32_t pardes_cursor_x(void); int32_t pardes_cursor_y(void); bool pardes_cursor_bar(void); -// Mouse pointer affordance: 0 = default text pointer, 1 = link hand, -// 2 = a validated Look/Exec target under the pointer (the acme arrow). +// Mouse pointer affordance: 0 text, 1 link, 2 Look/Exec target, +// 3 carrying a pane/column, +// 4 over a draggable grip, 5 horizontal resize, 6 vertical resize. uint32_t pardes_pointer_shape(void); // The Look or Exec the core performed since this was last asked, and clears diff --git a/src/pardes.zig b/src/pardes.zig index e14e9273..bd813e0e 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -291,7 +291,9 @@ pub const MAX_JUMPS = 64; pub const TOPBAR_H: u16 = 1; pub const COLBAR_H: u16 = 1; pub const BOX_H: u16 = 1; -pub const TAG_GAP: u16 = 0; +// AppKit's square mode/grip box needs breathing room before the tag text. +// Keep this in the core layout so selection and hit testing share the inset. +pub const TAG_GAP: u16 = if (platform == .macos) 1 else 0; pub const TAG_TEXT_INSET: u16 = config.GUTTER + TAG_GAP; pub fn taglineBandOffset(row: u16, canvas_h: f32, cell_h: u32, tagline_h: u32) u32 { |
