Skip to content

macos: opacity-toggle setting persists between tabs in a window and to a newly created window - #11583

Merged
bo2themax merged 2 commits into
ghostty-org:mainfrom
davidsanchez222:persist-opacity-toggle
May 16, 2026
Merged

bo2themax merged 2 commits into
ghostty-org:mainfrom
davidsanchez222:persist-opacity-toggle

Conversation

@davidsanchez222

@davidsanchez222 davidsanchez222 commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

Conversion of #11041 into a PR. My vouch request doubles as an Issue so I don't think I need to make a new issue in Issue Triage.

The opacity toggle setting is now reflected amongst all tabs. So now when you press the keybinding for toggle_background_opacity, all existing tabs and all new tabs created will have the same toggle setting.

There is also logic in BaseTerminalController.swift that makes a new window inherit the current window's toggle state. There is no logic that changes the toggle state between all windows as I think the toggle logic should be per-window. This is a subjective design choice so let me know if you disagree.

A suggestion for the future, if the user wants more fine-tuned control over the scope, maybe a configuration option like

toggle_background_opacity_scope

and have the options be

global, window, tab

could be useful but I think that might be too complex for a small issue like this.

edit: I just stumbled upon this post #4817. If this were to be implemented (themes at a tab or window level) then the design of this pr would have to rethought.

AI usage disclosure:
I used OpenAI Codex (GPT-5.3-Codex) for AI-assisted code editing and text drafting and for code review.
Extent: initial implementation and wording assistance.
I manually reviewed and edited the code and I understand how the changes work in TerminalController.swift and BaseTerminalController.swift

@davidsanchez222
davidsanchez222 requested a review from a team as a code owner March 17, 2026 00:22
@ghostty-bot ghostty-bot Bot added the os/macos label Mar 25, 2026
@davidsanchez222 davidsanchez222 changed the title macos: opacity-toggle setting persists between tabs in a window and to a newly a created window macos: opacity-toggle setting persists between tabs in a window and to a newly created window Mar 25, 2026
@@ -313,14 +307,17 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
tree: SplitTree<Ghostty.SurfaceView>,
position: NSPoint? = nil,
confirmUndo: Bool = true,
inheritBackgroundOpacityFrom parentController: TerminalController? = nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing TerminalController around, just use isBackgroundOpaque would be better

guard let window, !window.styleMask.contains(.fullScreen) else { return }

let newValue = !isBackgroundOpaque
let controllers: [TerminalController]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a shared all that you can get all opened windows, so you can toggle them all.

And I think you can just call super here and move some of the stuff to Base so that quick terminal can also benefit from this

@davidsanchez222 davidsanchez222 Apr 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a shared all that you can get all opened windows, so you can toggle them all.

I was hesitant at first to make the toggle apply to all (windows and tabs) because I didn't know if the current behavior was a design choice. However, I do agree with you that making it global is better since its rare that a user would want a different opacity setting between different tabs and/or windows. I added this to the new commit.

And I think you can just call super here

I ended up not calling super in TerminalController because I removed the
override func toggleBackgroundOpacity entirely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, when I was testing if my newest changes worked for quick terminal, I ran into an issue of not being able to open to quick terminal for just my debug build. I don't know why toggle_quick_terminal isn't in the command palette. I made a discussion post that might be worth checking out: #12130

let newValue = !isBackgroundOpaque
let controllers = NSApplication.shared.windows.compactMap {
$0.windowController as? BaseTerminalController
}

@davidsanchez222 davidsanchez222 Apr 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use TerminalController.all like you said but I found that it excluded the quick terminal. Instead, I added this logic. It computes newValue, gathers all open terminal controllers, and applies. This change did include the quick terminal

bo2themax
bo2themax previously approved these changes Apr 5, 2026

@bo2themax bo2themax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much cleaner to me, thanks, now we wait, please don't pin anyone🫪

@bo2themax
bo2themax dismissed their stale review April 5, 2026 18:36

Need to test

@bo2themax
bo2themax self-requested a review April 5, 2026 18:57
@bo2themax

Copy link
Copy Markdown
Member

Tried, LGTM, please rebase to the latest, and I'll reapprove it 🙏

@davidsanchez222
davidsanchez222 force-pushed the persist-opacity-toggle branch from 333a1b2 to 0e49204 Compare April 5, 2026 21:05
@davidsanchez222

Copy link
Copy Markdown
Contributor Author

Tried, LGTM, please rebase to the latest, and I'll reapprove it 🙏

Done. Thanks!

@davidsanchez222

Copy link
Copy Markdown
Contributor Author

Is there anything else I need to do? I use ghostty every day on one monitor and the current behavior is driving me crazy when it is above other windows while translucent.

@bo2themax

bo2themax commented Apr 9, 2026 •

Copy link
Copy Markdown
Member

Is there anything else I need to do? I use ghostty every day on one monitor and the current behavior is driving me crazy when it is above other windows while translucent.

No, be patient, you can always build in release mode and use local build

@davidsanchez222

Copy link
Copy Markdown
Contributor Author

Hi is there any reason this hasn't been merged? The review has been approved for over a month and its a small change.

@bo2themax
bo2themax merged commit b6c6f76 into ghostty-org:main May 16, 2026
86 checks passed
@github-actions github-actions Bot added this to the 1.3.2 milestone May 16, 2026
@bo2themax bo2themax modified the milestones: 1.3.2, 1.4.0 May 16, 2026
shiweis added a commit to shiweis/ghostty-windows that referenced this pull request May 17, 2026
When the user toggles `background_opacity` to fully opaque on an
existing window, child windows created via `new_window` now start
opaque too instead of reverting to the configured `background-opacity`
value. Mirrors the macOS behavior from upstream e5c31e8 (ghostty-org#11583).

The new_window action handler inspects the parent surface's HWND
WS_EX_LAYERED bit: if it's clear while config opacity < 1.0, the
parent was toggled to opaque, so the new Window is initialized with
`force_opaque = true` which skips the WS_EX_LAYERED setup in
Window.init.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants