mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 08:16:13 +03:00
Merge pull request #423 from mitchellh/split-focus
macos: fade unfocused splits
This commit is contained in:
@ -183,6 +183,11 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
return clone
|
return clone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// True if there are no neighbors
|
||||||
|
func isEmpty() -> Bool {
|
||||||
|
return self.previous == nil && self.next == nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +346,7 @@ extension Ghostty {
|
|||||||
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, isSplit: !neighbors.isEmpty())
|
||||||
.onReceive(pub) { onNewSplit(notification: $0) }
|
.onReceive(pub) { onNewSplit(notification: $0) }
|
||||||
.onReceive(pubClose) { onClose(notification: $0) }
|
.onReceive(pubClose) { onClose(notification: $0) }
|
||||||
.onReceive(pubFocus) { onMoveFocus(notification: $0) }
|
.onReceive(pubFocus) { onMoveFocus(notification: $0) }
|
||||||
|
@ -38,6 +38,10 @@ extension Ghostty {
|
|||||||
// remains the same, the surface that is being rendered remains the same.
|
// remains the same, the surface that is being rendered remains the same.
|
||||||
@ObservedObject var surfaceView: SurfaceView
|
@ObservedObject var surfaceView: SurfaceView
|
||||||
|
|
||||||
|
// True if this surface is part of a split view. This is important to know so
|
||||||
|
// we know whether to dim the surface out of focus.
|
||||||
|
var isSplit: Bool = false
|
||||||
|
|
||||||
// Maintain whether our view has focus or not
|
// Maintain whether our view has focus or not
|
||||||
@FocusState private var surfaceFocus: Bool
|
@FocusState private var surfaceFocus: Bool
|
||||||
|
|
||||||
@ -49,6 +53,7 @@ extension Ghostty {
|
|||||||
private var hasFocus: Bool { surfaceFocus && windowFocus }
|
private var hasFocus: Bool { surfaceFocus && windowFocus }
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
// We use a GeometryReader to get the frame bounds so that our metal surface
|
// We use a GeometryReader to get the frame bounds so that our metal surface
|
||||||
// is up to date. See TerminalSurfaceView for why we don't use the NSView
|
// is up to date. See TerminalSurfaceView for why we don't use the NSView
|
||||||
// resize callback.
|
// resize callback.
|
||||||
@ -116,6 +121,17 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.ghosttySurfaceView(surfaceView)
|
.ghosttySurfaceView(surfaceView)
|
||||||
|
|
||||||
|
// If we're part of a split view and don't have focus, we put a semi-transparent
|
||||||
|
// rectangle above our view to make it look unfocused. We use "surfaceFocus"
|
||||||
|
// because we want to keep our focused surface dark even if we don't have window
|
||||||
|
// focus.
|
||||||
|
if (isSplit && !surfaceFocus) {
|
||||||
|
Rectangle()
|
||||||
|
.fill(.white)
|
||||||
|
.opacity(0.15)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user