mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: initialize some pressure click boilerplate
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import QuickLookUI
|
||||
import SwiftUI
|
||||
import UserNotifications
|
||||
import GhosttyKit
|
||||
@ -72,6 +73,7 @@ extension Ghostty {
|
||||
private var markedText: NSMutableAttributedString
|
||||
private var mouseEntered: Bool = false
|
||||
private(set) var focused: Bool = true
|
||||
private var prevPressureStage: Int = 0
|
||||
private var cursor: NSCursor = .iBeam
|
||||
private var cursorVisible: CursorVisibility = .visible
|
||||
private var appearanceObserver: NSKeyValueObservation? = nil
|
||||
@ -441,6 +443,10 @@ extension Ghostty {
|
||||
}
|
||||
|
||||
override func mouseUp(with event: NSEvent) {
|
||||
// Always reset our pressure when the mouse goes up
|
||||
prevPressureStage = 0
|
||||
|
||||
// If we have an active surface, report the event
|
||||
guard let surface = self.surface else { return }
|
||||
let mods = Ghostty.ghosttyMods(event.modifierFlags)
|
||||
ghostty_surface_mouse_button(surface, GHOSTTY_MOUSE_RELEASE, GHOSTTY_MOUSE_LEFT, mods)
|
||||
@ -571,6 +577,19 @@ extension Ghostty {
|
||||
ghostty_surface_mouse_scroll(surface, x, y, mods)
|
||||
}
|
||||
|
||||
override func pressureChange(with event: NSEvent) {
|
||||
// Pressure stage 2 is force click. We only want to execute this on the
|
||||
// initial transition to stage 2, and not for any repeated events.
|
||||
guard self.prevPressureStage < 2 else { return }
|
||||
prevPressureStage = event.stage
|
||||
guard event.stage == 2 else { return }
|
||||
|
||||
// If the user has force click enabled then we do a quick look. There
|
||||
// is no public API for this as far as I can tell.
|
||||
guard UserDefaults.standard.bool(forKey: "com.apple.trackpad.forceClick") else { return }
|
||||
quickLook(with: event)
|
||||
}
|
||||
|
||||
override func cursorUpdate(with event: NSEvent) {
|
||||
switch (cursorVisible) {
|
||||
case .visible, .hidden:
|
||||
@ -885,6 +904,31 @@ extension Ghostty {
|
||||
Ghostty.moveFocus(to: self)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: QuickLook
|
||||
|
||||
private var quickLookURL: NSURL?
|
||||
|
||||
override func quickLook(with event: NSEvent) {
|
||||
/* TODO
|
||||
guard let panel = QLPreviewPanel.shared() else { return }
|
||||
panel.delegate = self
|
||||
panel.dataSource = self
|
||||
panel.makeKeyAndOrderFront(self)
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: QuickLook Delegates
|
||||
|
||||
extension Ghostty.SurfaceView: QLPreviewPanelDelegate, QLPreviewPanelDataSource {
|
||||
func numberOfPreviewItems(in panel: QLPreviewPanel!) -> Int {
|
||||
return quickLookURL != nil ? 1 : 0
|
||||
}
|
||||
|
||||
func previewPanel(_ panel: QLPreviewPanel!, previewItemAt index: Int) -> (any QLPreviewItem)! {
|
||||
return quickLookURL ?? nil
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user