mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-28 07:33:14 -04:00
Add Window::set_theme (#2553)
* Add `Window::set_theme`
* typo
* fix linux build
* fix wayland
* review changes
* update docs
* update changelog
* pin `image` dep
* suppport falling back to system default
* fix linux
* default to dark on macOS and x11
* fix `setAppearance` definition
* add macOS notes
* update docs
* Update CHANGELOG.md
Co-authored-by: Markus Siglreithmaier <m.siglreith@gmail.com>
* update doc
* Revert "pin `image` dep"
This reverts commit 7517f7c506.
* Update theme example with Window::set_theme
* Fix Window::theme getter on macOS
Co-authored-by: Markus Siglreithmaier <m.siglreith@gmail.com>
Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
@@ -301,6 +301,10 @@ impl UnownedWindow {
|
||||
.set_decorations_inner(window_attrs.decorations)
|
||||
.queue();
|
||||
|
||||
if let Some(theme) = window_attrs.preferred_theme {
|
||||
window.set_theme_inner(Some(theme)).queue();
|
||||
}
|
||||
|
||||
{
|
||||
// Enable drag and drop (TODO: extend API to make this toggleable)
|
||||
unsafe {
|
||||
@@ -359,10 +363,6 @@ impl UnownedWindow {
|
||||
|
||||
window.set_window_types(pl_attribs.x11_window_types).queue();
|
||||
|
||||
if let Some(variant) = pl_attribs.gtk_theme_variant {
|
||||
window.set_gtk_theme_variant(variant).queue();
|
||||
}
|
||||
|
||||
// set size hints
|
||||
{
|
||||
let mut min_inner_size = window_attrs
|
||||
@@ -565,9 +565,14 @@ impl UnownedWindow {
|
||||
)
|
||||
}
|
||||
|
||||
fn set_gtk_theme_variant(&self, variant: String) -> util::Flusher<'_> {
|
||||
pub fn set_theme_inner(&self, theme: Option<Theme>) -> util::Flusher<'_> {
|
||||
let hint_atom = unsafe { self.xconn.get_atom_unchecked(b"_GTK_THEME_VARIANT\0") };
|
||||
let utf8_atom = unsafe { self.xconn.get_atom_unchecked(b"UTF8_STRING\0") };
|
||||
let variant = match theme {
|
||||
Some(Theme::Dark) => "dark",
|
||||
Some(Theme::Light) => "light",
|
||||
None => "dark",
|
||||
};
|
||||
let variant = CString::new(variant).expect("`_GTK_THEME_VARIANT` contained null byte");
|
||||
self.xconn.change_property(
|
||||
self.xwindow,
|
||||
@@ -578,6 +583,13 @@ impl UnownedWindow {
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_theme(&self, theme: Option<Theme>) {
|
||||
self.set_theme_inner(theme)
|
||||
.flush()
|
||||
.expect("Failed to change window theme")
|
||||
}
|
||||
|
||||
fn set_netwm(
|
||||
&self,
|
||||
operation: util::StateOperation,
|
||||
|
||||
Reference in New Issue
Block a user