Skip to content

Commit

Permalink
Restore hidden titlebar after fullscreen (#3572)
Browse files Browse the repository at this point in the history
This fixes #3535 .

There exists an issue in ghostty on mac where if you have hidden your
titlebar, then enter fullscreen, the titlebar will reappear after
exiting fullscreen.

The reason for this is that after exiting fullscreen macos reapplies
some styling on the new window created after exiting fullscreen. To
combat this we will reapply the styling to hide the titlebar after
exiting fullscreen.

Required config:
```
macos-titlebar-style = hidden
macos-non-native-fullscreen = true
```

Steps to reproduce:

- Open Ghostty
- Enter fullscreen (non-native)
- Exit fullscreen

On main you will see the titlebar reappearing after exiting fullscreen,
while that does not happen with this patch.
  • Loading branch information
mitchellh authored Jan 2, 2025
2 parents b68e9a1 + 88674a1 commit 600e417
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions macos/Sources/Features/Terminal/TerminalController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ class TerminalController: BaseTerminalController {
// When our fullscreen state changes, we resync our appearance because some
// properties change when fullscreen or not.
guard let focusedSurface else { return }
if (!(fullscreenStyle?.isFullscreen ?? false) &&
ghostty.config.macosTitlebarStyle == "hidden")
{
applyHiddenTitlebarStyle()
}

syncAppearance(focusedSurface.derivedConfig)
}

Expand Down Expand Up @@ -274,6 +280,43 @@ class TerminalController: BaseTerminalController {
shouldCascadeWindows = false
}

fileprivate func applyHiddenTitlebarStyle() {
guard let window else { return }

window.styleMask = [
// We need `titled` in the mask to get the normal window frame
.titled,

// Full size content view so we can extend
// content in to the hidden titlebar's area
.fullSizeContentView,

.resizable,
.closable,
.miniaturizable,
]

// Hide the title
window.titleVisibility = .hidden
window.titlebarAppearsTransparent = true

// Hide the traffic lights (window control buttons)
window.standardWindowButton(.closeButton)?.isHidden = true
window.standardWindowButton(.miniaturizeButton)?.isHidden = true
window.standardWindowButton(.zoomButton)?.isHidden = true

// Disallow tabbing if the titlebar is hidden, since that will (should) also hide the tab bar.
window.tabbingMode = .disallowed

// Nuke it from orbit -- hide the titlebar container entirely, just in case. There are
// some operations that appear to bring back the titlebar visibility so this ensures
// it is gone forever.
if let themeFrame = window.contentView?.superview,
let titleBarContainer = themeFrame.firstDescendant(withClassName: "NSTitlebarContainerView") {
titleBarContainer.isHidden = true
}
}

override func windowDidLoad() {
super.windowDidLoad()
guard let window = window as? TerminalWindow else { return }
Expand Down Expand Up @@ -365,38 +408,7 @@ class TerminalController: BaseTerminalController {

// If our titlebar style is "hidden" we adjust the style appropriately
if (config.macosTitlebarStyle == "hidden") {
window.styleMask = [
// We need `titled` in the mask to get the normal window frame
.titled,

// Full size content view so we can extend
// content in to the hidden titlebar's area
.fullSizeContentView,

.resizable,
.closable,
.miniaturizable,
]

// Hide the title
window.titleVisibility = .hidden
window.titlebarAppearsTransparent = true

// Hide the traffic lights (window control buttons)
window.standardWindowButton(.closeButton)?.isHidden = true
window.standardWindowButton(.miniaturizeButton)?.isHidden = true
window.standardWindowButton(.zoomButton)?.isHidden = true

// Disallow tabbing if the titlebar is hidden, since that will (should) also hide the tab bar.
window.tabbingMode = .disallowed

// Nuke it from orbit -- hide the titlebar container entirely, just in case. There are
// some operations that appear to bring back the titlebar visibility so this ensures
// it is gone forever.
if let themeFrame = window.contentView?.superview,
let titleBarContainer = themeFrame.firstDescendant(withClassName: "NSTitlebarContainerView") {
titleBarContainer.isHidden = true
}
applyHiddenTitlebarStyle()
}

// In various situations, macOS automatically tabs new windows. Ghostty handles
Expand Down

0 comments on commit 600e417

Please sign in to comment.