Skip to content

fix Ghostty background opacity toggle action handling#225

Open
vadimi wants to merge 2 commits intosupabitapp:mainfrom
vadimi:main
Open

fix Ghostty background opacity toggle action handling#225
vadimi wants to merge 2 commits intosupabitapp:mainfrom
vadimi:main

Conversation

@vadimi
Copy link
Copy Markdown

@vadimi vadimi commented Apr 8, 2026

Handle Ghostty toggle-background-opacity action in the surface bridge and add a per-window opaque override in GhosttySurfaceView. This lets users temporarily force an opaque terminal background when transparency is enabled, while preserving fullscreen behavior.

This should fix #180

Handle Ghostty toggle-background-opacity action in the surface bridge and add a per-window opaque override in GhosttySurfaceView. This lets users temporarily force an opaque terminal background when transparency is enabled, while preserving fullscreen behavior.
Copy link
Copy Markdown
Collaborator

@sbertix sbertix left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution 🙇‍♂️

Comment on lines +71 to +73
case GHOSTTY_ACTION_TOGGLE_BACKGROUND_OPACITY:
surfaceView?.toggleBackgroundOpacity()
return true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

isBackgroundOpaque is per-view, but applyWindowBackgroundAppearance() modifies window-level properties. With splits, another surface's call to applyWindowBackgroundAppearance() would revert the toggle silently cause its own isBackgroundOpaque is still false. Could we move this state to window-level instead? Wdyt?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ah yes, that totally makes sense. I've checked ghostty and it does it per tab, but I like per window much better. I've added isBackgroundOpaque on the NSWindow level. I haven't found any other custom state properties in the repo, so please let me know if you prefer another approach. Ghostty does it on the windowController level, but it's not used in this repo.

private var lastSurfaceFocus: Bool?
private var eventMonitor: Any?
private var notificationObservers: [NSObjectProtocol] = []
private var isBackgroundOpaque = false
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we considering resetting isBackgroundOpaque when ghosttyRuntimeConfigDidChange fires? Cause if the user toggles opaque then changes the config, the flag persists and they'd need to toggle twice 🤔

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've checked ghostty and it looks like it doesn't do it when I reload the config.

Comment on lines +421 to +422
guard runtime.backgroundOpacity() < 1 else { return }
guard let window, !window.styleMask.contains(.fullScreen) else { return }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

NIT, both guards are re-checked inside applyWindowBackgroundAppearance(). Could we add a short comment explaining they prevent toggling isBackgroundOpaque when it'd have no visible effect? Otherwise it reads like duplication at first glance.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

- define isBackgroundOpaque on NSWindow level
- add comments inside toggleBackgroundOpacity function
- change GHOSTTY_ACTION_TOGGLE_BACKGROUND_OPACITY return statement to
  use similar style as other actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Toggle Background Opacity is not working

2 participants