Mitchell Hashimoto 2025-11-14 07:28:20 -08:00 committed by GitHub
commit 05b42919d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 96 additions and 11 deletions

View File

@ -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) {

View File

@ -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 }

View File

@ -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.

View File

@ -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..<counter {
for _ in 0 ..< counter {
assert(unhide())
}
assert(self.counter == 0)
return counter
}
}
enum CursorStyle {
case `default`
case grabIdle
case grabActive
case horizontalText
case verticalText
case link
case resizeLeft
case resizeRight
case resizeUp
case resizeDown
case resizeUpDown
case resizeLeftRight
case contextMenu
case crosshair
case operationNotAllowed
}
extension CursorStyle {
var cursor: NSCursor {
switch self {
case .default:
return .arrow
case .grabIdle:
return .openHand
case .grabActive:
return .closedHand
case .horizontalText:
return .iBeam
case .verticalText:
return .iBeamCursorForVerticalLayout
case .link:
return .pointingHand
case .resizeLeft:
if #available(macOS 15.0, *) {
return .columnResize(directions: .left)
} else {
return .resizeLeft
}
case .resizeRight:
if #available(macOS 15.0, *) {
return .columnResize(directions: .right)
} else {
return .resizeRight
}
case .resizeUp:
if #available(macOS 15.0, *) {
return .rowResize(directions: .up)
} else {
return .resizeUp
}
case .resizeDown:
if #available(macOS 15.0, *) {
return .rowResize(directions: .down)
} else {
return .resizeDown
}
case .resizeUpDown:
if #available(macOS 15.0, *) {
return .rowResize
} else {
return .resizeUpDown
}
case .resizeLeftRight:
if #available(macOS 15.0, *) {
return .columnResize
} else {
return .resizeLeftRight
}
case .contextMenu:
return .contextualMenu
case .crosshair:
return .crosshair
case .operationNotAllowed:
return .operationNotAllowed
}
}
}