macos: more robust surface focus state detection

Fixes #1500

This overhauls how we do focus management for surfaces to make it more
robust. This DID somehow all work before but was always brittle and was
a sketchy play with SwiftUI/AppKit behavior across macOS versions.

The new approach uses our window controller and terminal delegate
system to disseminate focus information whenever any surface changes
focus. This ensures that only ONE surface ever has focus in libghostty
because the controller ensures it is widely distributed.
This commit is contained in:
Mitchell Hashimoto
2024-02-11 09:16:41 -08:00
parent aa27190baf
commit 118b51157a
4 changed files with 55 additions and 18 deletions

View File

@@ -11,7 +11,7 @@ extension Ghostty {
/// "container" which has a recursive top/left SplitNode and bottom/right SplitNode. These
/// values can further be split infinitely.
///
enum SplitNode: Equatable, Hashable, Codable {
enum SplitNode: Equatable, Hashable, Codable, Sequence {
case leaf(Leaf)
case split(Container)
@@ -136,6 +136,24 @@ extension Ghostty {
}
}
// MARK: - Sequence
func makeIterator() -> IndexingIterator<[Leaf]> {
return leaves().makeIterator()
}
/// Return all the leaves in this split node. This isn't very efficient but our split trees are never super
/// deep so its not an issue.
private func leaves() -> [Leaf] {
switch (self) {
case .leaf(let leaf):
return [leaf]
case .split(let container):
return container.topLeft.leaves() + container.bottomRight.leaves()
}
}
// MARK: - Equatable
static func == (lhs: SplitNode, rhs: SplitNode) -> Bool {