From cad461fff7d76cdb8afd82a2f4f6bb070ae614bb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 Nov 2023 09:14:57 -0700 Subject: [PATCH] macos: modify tabbing mode when entering/exiting fullscreen Related to #799 With tabbing mode disabled, fullscreen (native) windows when creating a new tab creates a window in the tab bar, but ALSO puts the window into a new "screen" on macOS. When you click the tab bar, macOS animates between screens. Its jarring! This commit makes it so that in fullscreen we go back to automatic tabbing even for new windows, which produces new windows within a tab. This is normal default behavior for macOS tabbed programs. When you are not in fullscreen or exit fullscreen, then the tabbing mode returns to disabled so Ghostty can manage it. --- .../Terminal/TerminalController.swift | 25 +++++++++++++++++++ .../Features/Terminal/TerminalManager.swift | 6 ----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 0c1417cd0..66fe9c965 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -96,6 +96,10 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele // If window decorations are disabled, remove our title if (!ghostty.windowDecorations) { window.styleMask.remove(.titled) } + // If we aren't in full screen, then we want to disable tabbing (see comment + // in the delegate function) + if (!window.styleMask.contains(.fullScreen)) { disableTabbing() } + // Terminals typically operate in sRGB color space and macOS defaults // to "native" which is typically P3. There is a lot more resources // covered in thie GitHub issue: https://github.com/mitchellh/ghostty/pull/376 @@ -174,6 +178,27 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele func windowDidBecomeKey(_ notification: Notification) { self.relabelTabs() } + + func windowWillExitFullScreen(_ notification: Notification) { + // See comment in this function + disableTabbing() + } + + func windowWillEnterFullScreen(_ notification: Notification) { + // We re-enable the automatic tabbing mode when we enter full screen otherwise + // every new tab also enters a new screen. + guard let window = self.window else { return } + window.tabbingMode = .automatic + } + + private func disableTabbing() { + // For new windows, explicitly disallow tabbing with other windows. + // This overrides the value of userTabbingPreference. Rationale: + // Ghostty provides separate "New Tab" and "New Window" actions so + // there's no reason to make "New Window" open in a tab. + guard let window = self.window else { return } + window.tabbingMode = .disallowed; + } //MARK: - First Responder diff --git a/macos/Sources/Features/Terminal/TerminalManager.swift b/macos/Sources/Features/Terminal/TerminalManager.swift index d078bc24f..147ae85b1 100644 --- a/macos/Sources/Features/Terminal/TerminalManager.swift +++ b/macos/Sources/Features/Terminal/TerminalManager.swift @@ -95,12 +95,6 @@ class TerminalManager { // Initialize our controller to load the window let c = TerminalController(ghostty, withBaseConfig: base) - // For new windows, explicitly disallow tabbing with other windows. - // This overrides the value of userTabbingPreference. Rationale: - // Ghostty provides separate "New Tab" and "New Window" actions so - // there's no reason to make "New Window" open in a tab. - c.window!.tabbingMode = .disallowed; - // Create a listener for when the window is closed so we can remove it. let pubClose = NotificationCenter.default.publisher( for: NSWindow.willCloseNotification,