Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Sources/Fluid/Services/TypingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final class TypingService {
private static let pasteboardSessionSemaphore = DispatchSemaphore(value: 1)
private static let pasteboardRestoreQueue = DispatchQueue(label: "TypingService.PasteboardRestore", qos: .utility)
private static var focusSnapshot: FocusSnapshot?
private static let ghosttyBundleIdentifier = "com.mitchellh.ghostty"

private var textInsertionMode: SettingsStore.TextInsertionMode {
SettingsStore.shared.textInsertionMode
Expand Down Expand Up @@ -224,6 +225,36 @@ final class TypingService {
return Self.isCurrentlyFocusedElement(element, expectedPID: pid)
}

private func isGhosttyApplication(pid: pid_t) -> Bool {
guard pid > 0,
let app = NSRunningApplication(processIdentifier: pid)
else {
return false
}

return app.bundleIdentifier == Self.ghosttyBundleIdentifier
}

private func ghosttyTargetPID(preferredTargetPID: pid_t?) -> pid_t? {
if let preferredTargetPID, preferredTargetPID > 0 {
return self.isGhosttyApplication(pid: preferredTargetPID) ? preferredTargetPID : nil
}

if let focusedPID = self.getSystemFocusedElementAndPID()?.pid,
self.isGhosttyApplication(pid: focusedPID)
{
return focusedPID
}

if let frontmostPID = NSWorkspace.shared.frontmostApplication?.processIdentifier,
self.isGhosttyApplication(pid: frontmostPID)
{
return frontmostPID
}

return nil
}

/// Best-effort: activates the app with the given PID, unless it's Fluid itself.
@discardableResult
static func activateApp(pid: pid_t) -> Bool {
Expand Down Expand Up @@ -341,6 +372,17 @@ final class TypingService {
self.log("[TypingService] insertTextInstantly called with \(text.count) characters")
self.log("[TypingService] Attempting to type text: \"\(text.prefix(50))\(text.count > 50 ? "..." : "")\"")

if self.textInsertionMode == .standard,
let ghosttyTargetPID = self.ghosttyTargetPID(preferredTargetPID: preferredTargetPID)
{
self.log("[TypingService] Ghostty target detected in standard mode (PID \(ghosttyTargetPID)); forcing Reliable Paste path")
if self.tryReliablePasteInsertion(text, preferredTargetPID: ghosttyTargetPID) {
self.log("[TypingService] SUCCESS: Ghostty Reliable Paste path completed")
return
}
self.log("[TypingService] Ghostty Reliable Paste path fell through to direct-typing fallbacks")
}

if self.textInsertionMode == .reliablePaste {
self.log("[TypingService] Reliable Paste mode enabled")
if self.tryReliablePasteInsertion(text, preferredTargetPID: preferredTargetPID) {
Expand Down
Loading