Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve transparency on macOS #7965

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

madsmtm
Copy link

@madsmtm madsmtm commented May 10, 2024

Extension upon #7928, see that for discussion. I've improved a bit on the window background, by setting the alpha channel to follow the window opacity.

When window.opacity < 1, we do two things:

  • Set the title bar as transparent (new).
  • Disable window border shadows (existing behaviour).

Copy link
Member

@chrisduerr chrisduerr left a comment

Choose a reason for hiding this comment

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

Missing changelog entry.

Comment on lines +186 to +190
// Set initial background opacity and transparency
#[cfg(target_os = "macos")]
set_titlebar_transparent(&window, config.window_opacity() < 1.);
#[cfg(target_os = "macos")]
set_background_opacity(&window, config.window_opacity() as _);
Copy link
Member

Choose a reason for hiding this comment

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

You're not calling window.set_transparent here anymore, why is that?

Copy link
Author

Choose a reason for hiding this comment

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

Because it's called in WindowBuilder::with_transparent instead.

Copy link
Member

Choose a reason for hiding this comment

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

That was also called before though? Are you suggesting a winit update has removed the necessity for this on all platforms?

Comment on lines 350 to 359
pub fn set_transparent(&self, transparent: bool) {
self.window.set_transparent(transparent);
#[cfg(target_os = "macos")]
set_titlebar_transparent(&self.window, transparent);
}

pub fn set_background_opacity(&self, _opacity: f32) {
#[cfg(target_os = "macos")]
set_background_opacity(&self.window, _opacity as _)
}
Copy link
Member

Choose a reason for hiding this comment

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

Is there ever a scenario where you'd want to call set_background_opacity without setting transparency? Seems like the two functions can just be combined.

Comment on lines +518 to +520
// If transparent, fill background with NSColor.clearColor,
// otherwise fill with NSColor.windowBackgroundColor so that MacOS
// properly draws the window's border and opaque title bar.
Copy link
Member

Choose a reason for hiding this comment

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

This sounds like the window's background is filled, but surely that's not what is happening, right? Just the titlebar background?

@@ -496,3 +507,33 @@ fn use_srgb_color_space(window: &WinitWindow) {
let _: () = msg_send![raw_window, setColorSpace: NSColorSpace::sRGBColorSpace(nil)];
}
}

#[cfg(target_os = "macos")]
fn set_background_opacity(window: &WinitWindow, opacity: CGFloat) {
Copy link
Member

Choose a reason for hiding this comment

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

These macOS-specific functions should indicate their macOS-specificity. They're also lacking function documentation.

@@ -167,7 +168,7 @@ impl Window {
.with_title(&identity.title)
.with_theme(config.window.theme())
.with_visible(false)
.with_transparent(true)
.with_transparent(config.window_opacity() < 1.)
Copy link
Member

Choose a reason for hiding this comment

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

I believe we've had it this way in the past and that changed. Are you sure this is safe on all platforms? Because I'm not sure that this doesn't change Alacritty's behavior.

@@ -182,8 +183,11 @@ impl Window {
window.set_ime_allowed(true);
window.set_ime_purpose(ImePurpose::Terminal);

// Set initial transparency hint.
window.set_transparent(config.window_opacity() < 1.);
// Set initial background opacity and transparency
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Set initial background opacity and transparency
// Set initial background opacity and transparency.

@sfsam
Copy link

sfsam commented May 10, 2024

I'm seeing the same thing I observed in the discussion of #7928: No borders and a white title bar even though decorations_theme_variant = "Dark" is set. I think this is due to something that was changed in the move to winit 0.3.0. I'm on MacOS Sonoma 14.4.1. FWIW, my window config:

[window]
decorations_theme_variant = "Dark"
decorations = "full"
option_as_alt = "OnlyLeft"
resize_increments = true
dimensions = { columns = 100, lines = 24 }

@nixpulvis
Copy link
Contributor

nixpulvis commented May 14, 2024

Set the title bar as transparent (new)

Seems to me this may be undesired. I hate to think we need yet another macOS specific configuration for it though.

Screenshot 2024-05-14 at 9 47 41 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants