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

feat: allow explicitly setting the window appearance on macOS #6521

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::ssh::{SshBackend, SshDomain};
use crate::tls::{TlsDomainClient, TlsDomainServer};
use crate::units::Dimension;
use crate::unix::UnixDomain;
use crate::window::MacOSWindowAppearance;
use crate::wsl::WslDomain;
use crate::{
default_config_with_overrides_applied, default_one_point_oh, default_one_point_oh_f64,
Expand Down Expand Up @@ -544,6 +545,10 @@ pub struct Config {
#[dynamic(default)]
pub macos_window_background_blur: i64,

/// Explicitly sets the window appearance on macOS.
#[dynamic(default)]
pub macos_window_appearance: MacOSWindowAppearance,

/// Only works on Windows
#[dynamic(default)]
pub win32_system_backdrop: SystemBackdrop,
Expand Down
8 changes: 8 additions & 0 deletions config/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ pub enum WindowLevel {
Normal = 0,
AlwaysOnTop = 3,
}

#[derive(Debug, Default, Clone, ToDynamic, PartialEq, Eq, FromDynamic)]
pub enum MacOSWindowAppearance {
#[default]
System,
Light,
Dark,
}
14 changes: 14 additions & 0 deletions docs/config/lua/config/macos_window_appearance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
tags:
- appearance
---
# `macos_window_appearance = "System"`

{{since('nightly')}}

This option allows explicitly the appearance of the window on macOS.

The following values are supported:
- `"System"`: Follow the system appearance. This is the default.
- `"Light"`: Use the light appearance.
- `"Dark"`: Use the dark appearance.
11 changes: 9 additions & 2 deletions window/src/os/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
use anyhow::{anyhow, bail, ensure};
use async_trait::async_trait;
use cocoa::appkit::{
self, CGFloat, NSApplication, NSApplicationActivateIgnoringOtherApps,
self, CGFloat, NSAppearance, NSApplication, NSApplicationActivateIgnoringOtherApps,
NSApplicationPresentationOptions, NSBackingStoreBuffered, NSEvent, NSEventModifierFlags,
NSOpenGLContext, NSOpenGLPixelFormat, NSPasteboard, NSRunningApplication, NSScreen, NSView,
NSViewHeightSizable, NSViewWidthSizable, NSWindow, NSWindowStyleMask,
Expand All @@ -26,7 +26,7 @@ use cocoa::foundation::{
NSArray, NSAutoreleasePool, NSFastEnumeration, NSInteger, NSNotFound, NSPoint, NSRect, NSSize,
NSUInteger,
};
use config::window::WindowLevel;
use config::window::{MacOSWindowAppearance, WindowLevel};
use config::ConfigHandle;
use core_foundation::base::{CFTypeID, TCFType};
use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName};
Expand Down Expand Up @@ -603,6 +603,13 @@ impl Window {
window.setContentView_(*view);
window.setDelegate_(*view);

let appearance = match config.macos_window_appearance {
MacOSWindowAppearance::System => nil,
MacOSWindowAppearance::Light => NSAppearance(*nsstring("NSAppearanceNameAqua")),
MacOSWindowAppearance::Dark => NSAppearance(*nsstring("NSAppearanceNameDarkAqua")),
};
NSWindow::setAppearance(*window, appearance);

view.setWantsLayer(YES);
let () = msg_send![
*view,
Expand Down