Rework theme API

This commit adds support for theming on macOS and
also unifies the system theme handling across platforms.
This commit is contained in:
keiya sasaki 2022-10-19 03:34:36 +09:00 committed by GitHub
parent 4f06cfcf5b
commit 92fdf5ba85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 256 additions and 60 deletions

View file

@ -31,8 +31,6 @@ pub use self::x11::XNotSupported;
use self::x11::{ffi::XVisualInfo, util::WindowType as XWindowType, XConnection, XError};
#[cfg(feature = "x11")]
use crate::platform::x11::XlibErrorHook;
#[cfg(feature = "wayland")]
use crate::window::Theme;
use crate::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
error::{ExternalError, NotSupportedError, OsError as RootOsError},
@ -41,7 +39,7 @@ use crate::{
ControlFlow, DeviceEventFilter, EventLoopClosed, EventLoopWindowTarget as RootELW,
},
icon::Icon,
window::{CursorGrabMode, CursorIcon, UserAttentionType, WindowAttributes},
window::{CursorGrabMode, CursorIcon, Theme, UserAttentionType, WindowAttributes},
};
pub(crate) use crate::icon::RgbaIcon as PlatformIcon;
@ -104,8 +102,6 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub x11_window_types: Vec<XWindowType>,
#[cfg(feature = "x11")]
pub gtk_theme_variant: Option<String>,
#[cfg(feature = "wayland")]
pub csd_theme: Option<Theme>,
}
impl Default for PlatformSpecificWindowBuilderAttributes {
@ -126,8 +122,6 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
x11_window_types: vec![XWindowType::Normal],
#[cfg(feature = "x11")]
gtk_theme_variant: None,
#[cfg(feature = "wayland")]
csd_theme: None,
}
}
}
@ -590,6 +584,11 @@ impl Window {
pub fn raw_display_handle(&self) -> RawDisplayHandle {
x11_or_wayland!(match self; Window(window) => window.raw_display_handle())
}
#[inline]
pub fn theme(&self) -> Option<Theme> {
x11_or_wayland!(match self; Window(window) => window.theme())
}
}
/// Hooks for X11 errors.

View file

@ -170,7 +170,7 @@ impl Window {
// Set CSD frame config from theme if specified,
// otherwise use upstream automatic selection.
#[cfg(feature = "sctk-adwaita")]
if let Some(theme) = platform_attributes.csd_theme.or_else(|| {
if let Some(theme) = attributes.preferred_theme.or_else(|| {
std::env::var(WAYLAND_CSD_THEME_ENV_VAR)
.ok()
.and_then(|s| s.as_str().try_into().ok())
@ -619,6 +619,11 @@ impl Window {
self.window_requests.lock().unwrap().push(request);
self.event_loop_awakener.ping();
}
#[inline]
pub fn theme(&self) -> Option<Theme> {
None
}
}
impl Drop for Window {

View file

@ -20,7 +20,7 @@ use crate::{
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError,
PlatformSpecificWindowBuilderAttributes, VideoMode as PlatformVideoMode,
},
window::{CursorGrabMode, CursorIcon, Icon, UserAttentionType, WindowAttributes},
window::{CursorGrabMode, CursorIcon, Icon, Theme, UserAttentionType, WindowAttributes},
};
use super::{
@ -1546,4 +1546,9 @@ impl UnownedWindow {
display_handle.screen = self.screen_id;
RawDisplayHandle::Xlib(display_handle)
}
#[inline]
pub fn theme(&self) -> Option<Theme> {
None
}
}