macos: split traversal uses direction to determine proper focus target

Fixes #415
This commit is contained in:
Mitchell Hashimoto
2023-09-10 08:59:05 -07:00
parent 946826c384
commit 303c5ca189

View File

@ -8,13 +8,13 @@ extension Ghostty {
struct TerminalSplit: View { struct TerminalSplit: View {
let onClose: (() -> Void)? let onClose: (() -> Void)?
let baseConfig: ghostty_surface_config_s? let baseConfig: ghostty_surface_config_s?
@Environment(\.ghosttyApp) private var app @Environment(\.ghosttyApp) private var app
/// Non-nil if one of the surfaces in the split tree is currently "zoomed." A zoomed surface /// Non-nil if one of the surfaces in the split tree is currently "zoomed." A zoomed surface
/// becomes "full screen" on the split tree. /// becomes "full screen" on the split tree.
@State private var zoomedSurface: SurfaceView? = nil @State private var zoomedSurface: SurfaceView? = nil
var body: some View { var body: some View {
if let app = app { if let app = app {
ZStack { ZStack {
@ -24,7 +24,7 @@ extension Ghostty {
onClose: onClose, onClose: onClose,
baseConfig: baseConfig baseConfig: baseConfig
) )
// If we have a zoomed surface, we overlay that on top of our split // If we have a zoomed surface, we overlay that on top of our split
// root. Our split root will become clear when there is a zoomed // root. Our split root will become clear when there is a zoomed
// surface. We need to keep the split root around so that we don't // surface. We need to keep the split root around so that we don't
@ -37,7 +37,7 @@ extension Ghostty {
} }
} }
} }
/// This enum represents the possible states that a node in the split tree can be in. It is either: /// This enum represents the possible states that a node in the split tree can be in. It is either:
/// ///
/// - noSplit - This is an unsplit, single pane. This contains only a "leaf" which has a single /// - noSplit - This is an unsplit, single pane. This contains only a "leaf" which has a single
@ -50,85 +50,98 @@ extension Ghostty {
case noSplit(Leaf) case noSplit(Leaf)
case horizontal(Container) case horizontal(Container)
case vertical(Container) case vertical(Container)
/// Returns the view that would prefer receiving focus in this tree. This is always the /// Returns the view that would prefer receiving focus in this tree. This is always the
/// top-left-most view. This is used when creating a split or closing a split to find the /// top-left-most view. This is used when creating a split or closing a split to find the
/// next view to send focus to. /// next view to send focus to.
func preferredFocus() -> SurfaceView { func preferredFocus(_ direction: SplitFocusDirection = .top) -> SurfaceView {
let container: Container
switch (self) { switch (self) {
case .noSplit(let leaf): case .noSplit(let leaf):
// noSplit is easy because there is only one thing to focus
return leaf.surface return leaf.surface
case .horizontal(let container): case .horizontal(let c):
return container.topLeft.preferredFocus() container = c
case .vertical(let container): case .vertical(let c):
return container.topLeft.preferredFocus() container = c
} }
let node: SplitNode
switch (direction) {
case .previous, .bottom, .left:
node = container.bottomRight
case .next, .top, .right:
node = container.topLeft
}
return node.preferredFocus(direction)
} }
/// Close the surface associated with this node. This will likely deinitialize the /// Close the surface associated with this node. This will likely deinitialize the
/// surface. At this point, the surface view in this node tree can never be used again. /// surface. At this point, the surface view in this node tree can never be used again.
func close() { func close() {
switch (self) { switch (self) {
case .noSplit(let leaf): case .noSplit(let leaf):
leaf.surface.close() leaf.surface.close()
case .horizontal(let container): case .horizontal(let container):
container.topLeft.close() container.topLeft.close()
container.bottomRight.close() container.bottomRight.close()
case .vertical(let container): case .vertical(let container):
container.topLeft.close() container.topLeft.close()
container.bottomRight.close() container.bottomRight.close()
} }
} }
/// Returns true if the split tree contains the given view. /// Returns true if the split tree contains the given view.
func contains(view: SurfaceView) -> Bool { func contains(view: SurfaceView) -> Bool {
switch (self) { switch (self) {
case .noSplit(let leaf): case .noSplit(let leaf):
return leaf.surface == view return leaf.surface == view
case .horizontal(let container): case .horizontal(let container):
return container.topLeft.contains(view: view) || return container.topLeft.contains(view: view) ||
container.bottomRight.contains(view: view) container.bottomRight.contains(view: view)
case .vertical(let container): case .vertical(let container):
return container.topLeft.contains(view: view) || return container.topLeft.contains(view: view) ||
container.bottomRight.contains(view: view) container.bottomRight.contains(view: view)
} }
} }
class Leaf: ObservableObject { class Leaf: ObservableObject {
let app: ghostty_app_t let app: ghostty_app_t
@Published var surface: SurfaceView @Published var surface: SurfaceView
/// Initialize a new leaf which creates a new terminal surface. /// Initialize a new leaf which creates a new terminal surface.
init(_ app: ghostty_app_t, _ baseConfig: ghostty_surface_config_s?) { init(_ app: ghostty_app_t, _ baseConfig: ghostty_surface_config_s?) {
self.app = app self.app = app
self.surface = SurfaceView(app, baseConfig) self.surface = SurfaceView(app, baseConfig)
} }
} }
class Container: ObservableObject { class Container: ObservableObject {
let app: ghostty_app_t let app: ghostty_app_t
@Published var topLeft: SplitNode @Published var topLeft: SplitNode
@Published var bottomRight: SplitNode @Published var bottomRight: SplitNode
/// A container is always initialized from some prior leaf because a split has to originate /// A container is always initialized from some prior leaf because a split has to originate
/// from a non-split value. When initializing, we inherit the leaf's surface and then /// from a non-split value. When initializing, we inherit the leaf's surface and then
/// initialize a new surface for the new pane. /// initialize a new surface for the new pane.
init(from: Leaf, baseConfig: ghostty_surface_config_s? = nil) { init(from: Leaf, baseConfig: ghostty_surface_config_s? = nil) {
self.app = from.app self.app = from.app
// Initially, both topLeft and bottomRight are in the "nosplit" // Initially, both topLeft and bottomRight are in the "nosplit"
// state since this is a new split. // state since this is a new split.
self.topLeft = .noSplit(from) self.topLeft = .noSplit(from)
self.bottomRight = .noSplit(.init(app, baseConfig)) self.bottomRight = .noSplit(.init(app, baseConfig))
} }
} }
/// This keeps track of the "neighbors" of a split: the immediately above/below/left/right /// This keeps track of the "neighbors" of a split: the immediately above/below/left/right
/// nodes. This is purposely weak so we don't have to worry about memory management /// nodes. This is purposely weak so we don't have to worry about memory management
/// with this (although, it should always be correct). /// with this (although, it should always be correct).
@ -137,16 +150,16 @@ extension Ghostty {
var right: SplitNode? var right: SplitNode?
var top: SplitNode? var top: SplitNode?
var bottom: SplitNode? var bottom: SplitNode?
/// These are the previous/next nodes. It will certainly be one of the above as well /// These are the previous/next nodes. It will certainly be one of the above as well
/// but we keep track of these separately because depending on the split direction /// but we keep track of these separately because depending on the split direction
/// of the containing node, previous may be left OR top (same for next). /// of the containing node, previous may be left OR top (same for next).
var previous: SplitNode? var previous: SplitNode?
var next: SplitNode? var next: SplitNode?
/// No neighbors, used by the root node. /// No neighbors, used by the root node.
static let empty: Self = .init() static let empty: Self = .init()
/// Get the node for a given direction. /// Get the node for a given direction.
func get(direction: SplitFocusDirection) -> SplitNode? { func get(direction: SplitFocusDirection) -> SplitNode? {
let map: [SplitFocusDirection : KeyPath<Self, SplitNode?>] = [ let map: [SplitFocusDirection : KeyPath<Self, SplitNode?>] = [
@ -157,11 +170,11 @@ extension Ghostty {
.left: \.left, .left: \.left,
.right: \.right, .right: \.right,
] ]
guard let path = map[direction] else { return nil } guard let path = map[direction] else { return nil }
return self[keyPath: path] return self[keyPath: path]
} }
/// Update multiple keys and return a new copy. /// Update multiple keys and return a new copy.
func update(_ attrs: [WritableKeyPath<Self, SplitNode?>: SplitNode?]) -> Self { func update(_ attrs: [WritableKeyPath<Self, SplitNode?>: SplitNode?]) -> Self {
var clone = self var clone = self
@ -172,7 +185,7 @@ extension Ghostty {
} }
} }
} }
/// The root of a split tree. This sets up the initial SplitNode state and renders. There is only ever /// The root of a split tree. This sets up the initial SplitNode state and renders. There is only ever
/// one of these in a split tree. /// one of these in a split tree.
private struct TerminalSplitRoot: View { private struct TerminalSplitRoot: View {
@ -180,14 +193,14 @@ extension Ghostty {
@State private var requestClose: Bool = false @State private var requestClose: Bool = false
let onClose: (() -> Void)? let onClose: (() -> Void)?
let baseConfig: ghostty_surface_config_s? let baseConfig: ghostty_surface_config_s?
/// Keeps track of whether we're in a zoomed split state or not. If one of the splits we own /// Keeps track of whether we're in a zoomed split state or not. If one of the splits we own
/// is in the zoomed state, we clear our body since we expect a zoomed split to overlay /// is in the zoomed state, we clear our body since we expect a zoomed split to overlay
/// this one. /// this one.
@Binding var zoomedSurface: SurfaceView? @Binding var zoomedSurface: SurfaceView?
@FocusedValue(\.ghosttySurfaceTitle) private var surfaceTitle: String? @FocusedValue(\.ghosttySurfaceTitle) private var surfaceTitle: String?
init(app: ghostty_app_t, init(app: ghostty_app_t,
zoomedSurface: Binding<SurfaceView?>, zoomedSurface: Binding<SurfaceView?>,
onClose: (() ->Void)? = nil, onClose: (() ->Void)? = nil,
@ -197,11 +210,11 @@ extension Ghostty {
self._zoomedSurface = zoomedSurface self._zoomedSurface = zoomedSurface
_node = State(wrappedValue: SplitNode.noSplit(.init(app, baseConfig))) _node = State(wrappedValue: SplitNode.noSplit(.init(app, baseConfig)))
} }
var body: some View { var body: some View {
let center = NotificationCenter.default let center = NotificationCenter.default
let pubZoom = center.publisher(for: Notification.didToggleSplitZoom) let pubZoom = center.publisher(for: Notification.didToggleSplitZoom)
// If we're zoomed, we don't render anything, we are transparent. This // If we're zoomed, we don't render anything, we are transparent. This
// ensures that the View stays around so we don't lose our state, but // ensures that the View stays around so we don't lose our state, but
// also that the zoomed view on top can see through if background transparency // also that the zoomed view on top can see through if background transparency
@ -218,15 +231,15 @@ extension Ghostty {
) )
.onChange(of: requestClose) { value in .onChange(of: requestClose) { value in
guard value else { return } guard value else { return }
// Free any resources associated with this root, we're closing. // Free any resources associated with this root, we're closing.
node.close() node.close()
// Call our callback // Call our callback
guard let onClose = self.onClose else { return } guard let onClose = self.onClose else { return }
onClose() onClose()
} }
case .horizontal(let container): case .horizontal(let container):
TerminalSplitContainer( TerminalSplitContainer(
direction: .horizontal, direction: .horizontal,
@ -235,7 +248,7 @@ extension Ghostty {
container: container container: container
) )
.onReceive(pubZoom) { onZoom(notification: $0) } .onReceive(pubZoom) { onZoom(notification: $0) }
case .vertical(let container): case .vertical(let container):
TerminalSplitContainer( TerminalSplitContainer(
direction: .vertical, direction: .vertical,
@ -252,7 +265,7 @@ extension Ghostty {
let pubSplit = center.publisher(for: Notification.ghosttyNewSplit, object: zoomedSurface!) let pubSplit = center.publisher(for: Notification.ghosttyNewSplit, object: zoomedSurface!)
let pubClose = center.publisher(for: Notification.ghosttyCloseSurface, object: zoomedSurface!) let pubClose = center.publisher(for: Notification.ghosttyCloseSurface, object: zoomedSurface!)
let pubFocus = center.publisher(for: Notification.ghosttyFocusSplit, object: zoomedSurface!) let pubFocus = center.publisher(for: Notification.ghosttyFocusSplit, object: zoomedSurface!)
ZStack {} ZStack {}
.onReceive(pubZoom) { onZoomReset(notification: $0) } .onReceive(pubZoom) { onZoomReset(notification: $0) }
.onReceive(pubSplit) { onZoomReset(notification: $0) } .onReceive(pubSplit) { onZoomReset(notification: $0) }
@ -260,32 +273,32 @@ extension Ghostty {
.onReceive(pubFocus) { onZoomReset(notification: $0) } .onReceive(pubFocus) { onZoomReset(notification: $0) }
} }
} }
func onZoom(notification: SwiftUI.Notification) { func onZoom(notification: SwiftUI.Notification) {
// Our node must be split to receive zooms. You can't zoom an unsplit terminal. // Our node must be split to receive zooms. You can't zoom an unsplit terminal.
if case .noSplit = node { if case .noSplit = node {
preconditionFailure("TerminalSplitRoom must not be zoom-able if no splits exist") preconditionFailure("TerminalSplitRoom must not be zoom-able if no splits exist")
} }
// Make sure the notification has a surface and that this window owns the surface. // Make sure the notification has a surface and that this window owns the surface.
guard let surfaceView = notification.object as? SurfaceView else { return } guard let surfaceView = notification.object as? SurfaceView else { return }
guard node.contains(view: surfaceView) else { return } guard node.contains(view: surfaceView) else { return }
// We are in the zoomed state. // We are in the zoomed state.
zoomedSurface = surfaceView zoomedSurface = surfaceView
// See onZoomReset, same logic. // See onZoomReset, same logic.
DispatchQueue.main.async { Ghostty.moveFocus(to: surfaceView) } DispatchQueue.main.async { Ghostty.moveFocus(to: surfaceView) }
} }
func onZoomReset(notification: SwiftUI.Notification) { func onZoomReset(notification: SwiftUI.Notification) {
// Make sure the notification has a surface and that this window owns the surface. // Make sure the notification has a surface and that this window owns the surface.
guard let surfaceView = notification.object as? SurfaceView else { return } guard let surfaceView = notification.object as? SurfaceView else { return }
guard zoomedSurface == surfaceView else { return } guard zoomedSurface == surfaceView else { return }
// We are now unzoomed // We are now unzoomed
zoomedSurface = nil zoomedSurface = nil
// We need to stay focused on this view, but the view is going to change // We need to stay focused on this view, but the view is going to change
// superviews. We need to do this async so it happens on the next event loop // superviews. We need to do this async so it happens on the next event loop
// tick. // tick.
@ -304,30 +317,30 @@ extension Ghostty {
} }
} }
} }
/// A noSplit leaf node of a split tree. /// A noSplit leaf node of a split tree.
private struct TerminalSplitLeaf: View { private struct TerminalSplitLeaf: View {
/// The leaf to draw the surface for. /// The leaf to draw the surface for.
let leaf: SplitNode.Leaf let leaf: SplitNode.Leaf
/// The neighbors, used for navigation. /// The neighbors, used for navigation.
let neighbors: SplitNode.Neighbors let neighbors: SplitNode.Neighbors
/// The SplitNode that the leaf belongs to. /// The SplitNode that the leaf belongs to.
@Binding var node: SplitNode @Binding var node: SplitNode
/// This will be set to true when the split requests that is become closed. /// This will be set to true when the split requests that is become closed.
@Binding var requestClose: Bool @Binding var requestClose: Bool
/// This controls whether we're actively confirming if we want to close or not. /// This controls whether we're actively confirming if we want to close or not.
@State private var confirmClose: Bool = false @State private var confirmClose: Bool = false
var body: some View { var body: some View {
let center = NotificationCenter.default let center = NotificationCenter.default
let pub = center.publisher(for: Notification.ghosttyNewSplit, object: leaf.surface) let pub = center.publisher(for: Notification.ghosttyNewSplit, object: leaf.surface)
let pubClose = center.publisher(for: Notification.ghosttyCloseSurface, object: leaf.surface) let pubClose = center.publisher(for: Notification.ghosttyCloseSurface, object: leaf.surface)
let pubFocus = center.publisher(for: Notification.ghosttyFocusSplit, object: leaf.surface) let pubFocus = center.publisher(for: Notification.ghosttyFocusSplit, object: leaf.surface)
SurfaceWrapper(surfaceView: leaf.surface) SurfaceWrapper(surfaceView: leaf.surface)
.onReceive(pub) { onNewSplit(notification: $0) } .onReceive(pub) { onNewSplit(notification: $0) }
.onReceive(pubClose) { onClose(notification: $0) } .onReceive(pubClose) { onClose(notification: $0) }
@ -345,7 +358,7 @@ extension Ghostty {
"the process will be killed.") "the process will be killed.")
} }
} }
private func onClose(notification: SwiftUI.Notification) { private func onClose(notification: SwiftUI.Notification) {
var processAlive = false var processAlive = false
if let valueAny = notification.userInfo?["process_alive"] { if let valueAny = notification.userInfo?["process_alive"] {
@ -353,7 +366,7 @@ extension Ghostty {
processAlive = value processAlive = value
} }
} }
// If the child process is not alive, then we exit immediately // If the child process is not alive, then we exit immediately
guard processAlive else { guard processAlive else {
requestClose = true requestClose = true
@ -363,7 +376,7 @@ extension Ghostty {
// Child process is alive, so we want to show a confirmation. // Child process is alive, so we want to show a confirmation.
confirmClose = true confirmClose = true
} }
private func onNewSplit(notification: SwiftUI.Notification) { private func onNewSplit(notification: SwiftUI.Notification) {
let configAny = notification.userInfo?[Ghostty.Notification.NewSurfaceConfigKey] let configAny = notification.userInfo?[Ghostty.Notification.NewSurfaceConfigKey]
let config = configAny as? ghostty_surface_config_s let config = configAny as? ghostty_surface_config_s
@ -375,17 +388,17 @@ extension Ghostty {
switch (direction) { switch (direction) {
case GHOSTTY_SPLIT_RIGHT: case GHOSTTY_SPLIT_RIGHT:
splitDirection = .horizontal splitDirection = .horizontal
case GHOSTTY_SPLIT_DOWN: case GHOSTTY_SPLIT_DOWN:
splitDirection = .vertical splitDirection = .vertical
default: default:
return return
} }
// Setup our new container since we are now split // Setup our new container since we are now split
let container = SplitNode.Container(from: leaf, baseConfig: config) let container = SplitNode.Container(from: leaf, baseConfig: config)
// Depending on the direction, change the parent node. This will trigger // Depending on the direction, change the parent node. This will trigger
// the parent to relayout our views. // the parent to relayout our views.
switch (splitDirection) { switch (splitDirection) {
@ -394,35 +407,38 @@ extension Ghostty {
case .vertical: case .vertical:
node = .vertical(container) node = .vertical(container)
} }
// See moveFocus comment, we have to run this whenever split changes. // See moveFocus comment, we have to run this whenever split changes.
Ghostty.moveFocus(to: container.bottomRight.preferredFocus(), from: node.preferredFocus()) Ghostty.moveFocus(to: container.bottomRight.preferredFocus(), from: node.preferredFocus())
} }
/// This handles the event to move the split focus (i.e. previous/next) from a keyboard event. /// This handles the event to move the split focus (i.e. previous/next) from a keyboard event.
private func onMoveFocus(notification: SwiftUI.Notification) { private func onMoveFocus(notification: SwiftUI.Notification) {
// Determine our desired direction // Determine our desired direction
guard let directionAny = notification.userInfo?[Notification.SplitDirectionKey] else { return } guard let directionAny = notification.userInfo?[Notification.SplitDirectionKey] else { return }
guard let direction = directionAny as? SplitFocusDirection else { return } guard let direction = directionAny as? SplitFocusDirection else { return }
guard let next = neighbors.get(direction: direction) else { return } guard let next = neighbors.get(direction: direction) else { return }
Ghostty.moveFocus(to: next.preferredFocus(), from: node.preferredFocus()) Ghostty.moveFocus(
to: next.preferredFocus(direction),
from: node.preferredFocus()
)
} }
} }
/// This represents a split view that is in the horizontal or vertical split state. /// This represents a split view that is in the horizontal or vertical split state.
private struct TerminalSplitContainer: View { private struct TerminalSplitContainer: View {
let direction: SplitViewDirection let direction: SplitViewDirection
let neighbors: SplitNode.Neighbors let neighbors: SplitNode.Neighbors
@Binding var node: SplitNode @Binding var node: SplitNode
@StateObject var container: SplitNode.Container @StateObject var container: SplitNode.Container
@State private var closeTopLeft: Bool = false @State private var closeTopLeft: Bool = false
@State private var closeBottomRight: Bool = false @State private var closeBottomRight: Bool = false
var body: some View { var body: some View {
SplitView(direction, left: { SplitView(direction, left: {
let neighborKey: WritableKeyPath<SplitNode.Neighbors, SplitNode?> = direction == .horizontal ? \.right : \.bottom let neighborKey: WritableKeyPath<SplitNode.Neighbors, SplitNode?> = direction == .horizontal ? \.right : \.bottom
TerminalSplitNested( TerminalSplitNested(
node: $container.topLeft, node: $container.topLeft,
neighbors: neighbors.update([ neighbors: neighbors.update([
@ -433,17 +449,17 @@ extension Ghostty {
) )
.onChange(of: closeTopLeft) { value in .onChange(of: closeTopLeft) { value in
guard value else { return } guard value else { return }
// Close the top left and release all resources // Close the top left and release all resources
container.topLeft.close() container.topLeft.close()
// When closing the topLeft, our parent becomes the bottomRight. // When closing the topLeft, our parent becomes the bottomRight.
node = container.bottomRight node = container.bottomRight
Ghostty.moveFocus(to: node.preferredFocus(), from: container.topLeft.preferredFocus()) Ghostty.moveFocus(to: node.preferredFocus(), from: container.topLeft.preferredFocus())
} }
}, right: { }, right: {
let neighborKey: WritableKeyPath<SplitNode.Neighbors, SplitNode?> = direction == .horizontal ? \.left : \.top let neighborKey: WritableKeyPath<SplitNode.Neighbors, SplitNode?> = direction == .horizontal ? \.left : \.top
TerminalSplitNested( TerminalSplitNested(
node: $container.bottomRight, node: $container.bottomRight,
neighbors: neighbors.update([ neighbors: neighbors.update([
@ -454,10 +470,10 @@ extension Ghostty {
) )
.onChange(of: closeBottomRight) { value in .onChange(of: closeBottomRight) { value in
guard value else { return } guard value else { return }
// Close the node and release all resources // Close the node and release all resources
container.bottomRight.close() container.bottomRight.close()
// When closing the bottomRight, our parent becomes the topLeft. // When closing the bottomRight, our parent becomes the topLeft.
node = container.topLeft node = container.topLeft
Ghostty.moveFocus(to: node.preferredFocus(), from: container.bottomRight.preferredFocus()) Ghostty.moveFocus(to: node.preferredFocus(), from: container.bottomRight.preferredFocus())
@ -465,14 +481,14 @@ extension Ghostty {
}) })
} }
} }
/// This is like TerminalSplitRoot, but... not the root. This renders a SplitNode in any state but /// This is like TerminalSplitRoot, but... not the root. This renders a SplitNode in any state but
/// requires there be a binding to the parent node. /// requires there be a binding to the parent node.
private struct TerminalSplitNested: View { private struct TerminalSplitNested: View {
@Binding var node: SplitNode @Binding var node: SplitNode
let neighbors: SplitNode.Neighbors let neighbors: SplitNode.Neighbors
@Binding var requestClose: Bool @Binding var requestClose: Bool
var body: some View { var body: some View {
switch (node) { switch (node) {
case .noSplit(let leaf): case .noSplit(let leaf):
@ -482,7 +498,7 @@ extension Ghostty {
node: $node, node: $node,
requestClose: $requestClose requestClose: $requestClose
) )
case .horizontal(let container): case .horizontal(let container):
TerminalSplitContainer( TerminalSplitContainer(
direction: .horizontal, direction: .horizontal,
@ -490,7 +506,7 @@ extension Ghostty {
node: $node, node: $node,
container: container container: container
) )
case .vertical(let container): case .vertical(let container):
TerminalSplitContainer( TerminalSplitContainer(
direction: .vertical, direction: .vertical,
@ -501,7 +517,7 @@ extension Ghostty {
} }
} }
} }
/// When changing the split state, or going full screen (native or non), the terminal view /// When changing the split state, or going full screen (native or non), the terminal view
/// will lose focus. There has to be some nice SwiftUI-native way to fix this but I can't /// will lose focus. There has to be some nice SwiftUI-native way to fix this but I can't
/// figure it out so we're going to do this hacky thing to bring focus back to the terminal /// figure it out so we're going to do this hacky thing to bring focus back to the terminal
@ -514,7 +530,7 @@ extension Ghostty {
moveFocus(to: to, from: from) moveFocus(to: to, from: from)
return return
} }
// If we had a previously focused node and its not where we're sending // If we had a previously focused node and its not where we're sending
// focus, make sure that we explicitly tell it to lose focus. In theory // focus, make sure that we explicitly tell it to lose focus. In theory
// we should NOT have to do this but the focus callback isn't getting // we should NOT have to do this but the focus callback isn't getting
@ -524,10 +540,10 @@ extension Ghostty {
} }
window.makeFirstResponder(to) window.makeFirstResponder(to)
// On newer versions of macOS everything above works great so we're done. // On newer versions of macOS everything above works great so we're done.
if #available(macOS 13, *) { return } if #available(macOS 13, *) { return }
// On macOS 12, splits do not properly gain focus. I don't know why, but // On macOS 12, splits do not properly gain focus. I don't know why, but
// it seems like the `focused` SwiftUI method doesn't work. We use // it seems like the `focused` SwiftUI method doesn't work. We use
// NotificationCenter as a blunt force instrument to make it work. // NotificationCenter as a blunt force instrument to make it work.