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