diff --git a/macos/Sources/Ghostty/SurfaceScrollView.swift b/macos/Sources/Ghostty/SurfaceScrollView.swift index 41a3df530..fcf25f479 100644 --- a/macos/Sources/Ghostty/SurfaceScrollView.swift +++ b/macos/Sources/Ghostty/SurfaceScrollView.swift @@ -133,6 +133,12 @@ class SurfaceScrollView: NSView { } } .store(in: &cancellables) + surfaceView.$pointerStyle + .receive(on: DispatchQueue.main) + .sink { [weak self] newStyle in + self?.scrollView.documentCursor = newStyle.cursor + } + .store(in: &cancellables) } required init?(coder: NSCoder) { diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index b42e34314..0358f765b 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -76,7 +76,6 @@ extension Ghostty { .focusedValue(\.ghosttySurfaceView, surfaceView) .focusedValue(\.ghosttySurfaceCellSize, surfaceView.cellSize) #if canImport(AppKit) - .backport.pointerStyle(surfaceView.pointerStyle) .onReceive(pubBecomeKey) { notification in guard let window = notification.object as? NSWindow else { return } guard let surfaceWindow = surfaceView.window else { return } diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index 3375e47ce..063b13300 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -73,7 +73,7 @@ extension Ghostty { @Published var surfaceSize: ghostty_surface_size_s? = nil // Whether the pointer should be visible or not - @Published private(set) var pointerStyle: BackportPointerStyle = .default + @Published private(set) var pointerStyle: CursorStyle = .horizontalText /// The configuration derived from the Ghostty config so we don't need to rely on references. @Published private(set) var derivedConfig: DerivedConfig @@ -477,16 +477,16 @@ extension Ghostty { pointerStyle = .resizeLeftRight case GHOSTTY_MOUSE_SHAPE_VERTICAL_TEXT: - pointerStyle = .default + pointerStyle = .verticalText - // These are not yet supported. We should support them by constructing a - // PointerStyle from an NSCursor. case GHOSTTY_MOUSE_SHAPE_CONTEXT_MENU: - fallthrough + pointerStyle = .contextMenu + case GHOSTTY_MOUSE_SHAPE_CROSSHAIR: - fallthrough + pointerStyle = .crosshair + case GHOSTTY_MOUSE_SHAPE_NOT_ALLOWED: - pointerStyle = .default + pointerStyle = .operationNotAllowed default: // We ignore unknown shapes. diff --git a/macos/Sources/Helpers/Cursor.swift b/macos/Sources/Helpers/Cursor.swift index fe4a148b5..f749386da 100644 --- a/macos/Sources/Helpers/Cursor.swift +++ b/macos/Sources/Helpers/Cursor.swift @@ -1,6 +1,7 @@ import Cocoa +import SwiftUI -/// This helps manage the stateful nature of NSCursor hiding and unhiding. +/// This helps manage the stateful nature of NSCursor hiding and unhiding. class Cursor { private static var counter: UInt = 0 @@ -19,7 +20,7 @@ class Cursor { // won't go negative. NSCursor.unhide() - if (counter > 0) { + if counter > 0 { counter -= 1 return true } @@ -29,10 +30,89 @@ class Cursor { static func unhideCompletely() -> UInt { let counter = self.counter - for _ in 0..