Skip to content

Commit

Permalink
feat: allow explicitly setting the window appearance on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
henryhchchc committed Dec 29, 2024
1 parent 6f375e2 commit c6cc982
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
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

0 comments on commit c6cc982

Please sign in to comment.