1use cocoa::{
2 appkit::{NSAppearanceNameVibrantDark, NSAppearanceNameVibrantLight},
3 base::id,
4 foundation::NSString,
5};
6use gpui::WindowAppearance;
7use objc::{msg_send, sel, sel_impl};
8use std::ffi::CStr;
9
10pub(crate) unsafe fn window_appearance_from_native(appearance: id) -> WindowAppearance {
11 let name: id = msg_send![appearance, name];
12 unsafe {
13 if name == NSAppearanceNameVibrantLight {
14 WindowAppearance::VibrantLight
15 } else if name == NSAppearanceNameVibrantDark {
16 WindowAppearance::VibrantDark
17 } else if name == NSAppearanceNameAqua {
18 WindowAppearance::Light
19 } else if name == NSAppearanceNameDarkAqua {
20 WindowAppearance::Dark
21 } else {
22 println!(
23 "unknown appearance: {:?}",
24 CStr::from_ptr(name.UTF8String())
25 );
26 WindowAppearance::Light
27 }
28 }
29}
30
31#[link(name = "AppKit", kind = "framework")]
32unsafe extern "C" {
33 pub static NSAppearanceNameAqua: id;
34 pub static NSAppearanceNameDarkAqua: id;
35}