Add ActiveEventLoop::system_theme()
This also fixes macOS returning `None` in `Window::theme()` if no theme override is set, instead it now returns the system theme. MacOS and Wayland were the only ones working correctly according to the documentation, which was an oversight. The documentation was "fixed" now. Fixes #3837.
This commit is contained in:
parent
54ff9c3bb5
commit
15b79b18e1
12 changed files with 82 additions and 20 deletions
|
|
@ -1623,14 +1623,18 @@ impl WindowDelegate {
|
|||
}
|
||||
|
||||
pub fn theme(&self) -> Option<Theme> {
|
||||
// Note: We could choose between returning the value of `effectiveAppearance` or
|
||||
// `appearance`, depending on what the user is asking about:
|
||||
// - "how should I render on this particular frame".
|
||||
// - "what is the configuration for this window".
|
||||
//
|
||||
// We choose the latter for consistency with the `set_theme` call, though it might also be
|
||||
// useful to expose the former.
|
||||
Some(appearance_to_theme(unsafe { &*self.window().appearance()? }))
|
||||
unsafe { self.window().appearance() }
|
||||
.map(|appearance| appearance_to_theme(&appearance))
|
||||
.or_else(|| {
|
||||
let mtm = MainThreadMarker::from(self);
|
||||
let app = NSApplication::sharedApplication(mtm);
|
||||
|
||||
if app.respondsToSelector(sel!(effectiveAppearance)) {
|
||||
Some(super::window_delegate::appearance_to_theme(&app.effectiveAppearance()))
|
||||
} else {
|
||||
Some(Theme::Light)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_theme(&self, theme: Option<Theme>) {
|
||||
|
|
@ -1813,7 +1817,7 @@ fn dark_appearance_name() -> &'static NSString {
|
|||
ns_string!("NSAppearanceNameDarkAqua")
|
||||
}
|
||||
|
||||
fn appearance_to_theme(appearance: &NSAppearance) -> Theme {
|
||||
pub fn appearance_to_theme(appearance: &NSAppearance) -> Theme {
|
||||
let best_match = appearance.bestMatchFromAppearancesWithNames(&NSArray::from_id_slice(&[
|
||||
unsafe { NSAppearanceNameAqua.copy() },
|
||||
dark_appearance_name().copy(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue