mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
fix: ensure terminal tabs are reconstructed in main window after toggling visibility
This commit is contained in:

committed by
Mitchell Hashimoto

parent
d3de3448cc
commit
4dd9fe5cfd
@ -706,12 +706,34 @@ class AppDelegate: NSObject,
|
|||||||
|
|
||||||
/// Toggles visibility of all Ghosty Terminal windows. When hidden, activates Ghostty as the frontmost application
|
/// Toggles visibility of all Ghosty Terminal windows. When hidden, activates Ghostty as the frontmost application
|
||||||
@IBAction func toggleVisibility(_ sender: Any) {
|
@IBAction func toggleVisibility(_ sender: Any) {
|
||||||
// We only care about terminal windows.
|
if let mainWindow = terminalManager.mainWindow {
|
||||||
for window in NSApp.windows.filter({ $0.windowController is BaseTerminalController }) {
|
guard let parent = mainWindow.controller.window else {
|
||||||
if isVisible {
|
Self.logger.debug("could not get parent window")
|
||||||
window.orderOut(nil)
|
return
|
||||||
} else {
|
}
|
||||||
window.makeKeyAndOrderFront(nil)
|
|
||||||
|
guard let controller = parent.windowController as? TerminalController,
|
||||||
|
let primaryWindow = controller.window else {
|
||||||
|
Self.logger.debug("Could not retrieve primary window")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all terminal windows controlled by BaseTerminalController
|
||||||
|
for terminalWindow in NSApp.windows.filter({ $0.windowController is BaseTerminalController }) {
|
||||||
|
if isVisible {
|
||||||
|
terminalWindow.orderOut(nil)
|
||||||
|
} else {
|
||||||
|
primaryWindow.makeKeyAndOrderFront(nil)
|
||||||
|
primaryWindow.addTabbedWindow(terminalWindow, ordered: .above)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If our parent tab group already has this window, macOS added it and
|
||||||
|
// we need to remove it so we can set the correct order in the next line.
|
||||||
|
// If we don't do this, macOS gets really confused and the tabbedWindows
|
||||||
|
// state becomes incorrect.
|
||||||
|
if let tg = parent.tabGroup, tg.windows.firstIndex(of: parent) != nil {
|
||||||
|
tg.removeWindow(parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class TerminalManager {
|
|||||||
|
|
||||||
/// Returns the main window of the managed window stack. If there is no window
|
/// Returns the main window of the managed window stack. If there is no window
|
||||||
/// then an arbitrary window will be chosen.
|
/// then an arbitrary window will be chosen.
|
||||||
private var mainWindow: Window? {
|
var mainWindow: Window? {
|
||||||
for window in windows {
|
for window in windows {
|
||||||
if (window.controller.window?.isMainWindow ?? false) {
|
if (window.controller.window?.isMainWindow ?? false) {
|
||||||
return window
|
return window
|
||||||
|
Reference in New Issue
Block a user