From 3fea5355d67107684d41c06338a491d51b6cdcf0 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Sat, 12 Nov 2022 13:27:23 +0200 Subject: [PATCH] review changes --- src/platform/wayland.rs | 18 -------------- src/platform/x11.rs | 9 ------- src/platform_impl/linux/mod.rs | 4 ---- src/platform_impl/linux/wayland/window/mod.rs | 5 ---- .../linux/wayland/window/shim.rs | 19 +++++---------- src/platform_impl/linux/x11/window.rs | 24 ++++++++++++------- src/window.rs | 3 +++ 7 files changed, 25 insertions(+), 57 deletions(-) diff --git a/src/platform/wayland.rs b/src/platform/wayland.rs index ae01870ea..313b4d006 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -88,14 +88,6 @@ pub trait WindowExtWayland { /// /// The pointer will become invalid when the [`Window`] is destroyed. fn wayland_display(&self) -> Option<*mut raw::c_void>; - - /// Updates [`Theme`] of window decorations. - /// - /// You can also use `WINIT_WAYLAND_CSD_THEME` env variable to set the theme. - /// Possible values for env variable are: "dark" and light". - /// - /// When unspecified a theme is automatically selected. - fn wayland_set_csd_theme(&self, config: Theme); } impl WindowExtWayland for Window { @@ -116,16 +108,6 @@ impl WindowExtWayland for Window { _ => None, } } - - #[inline] - fn wayland_set_csd_theme(&self, theme: Theme) { - #[allow(clippy::single_match)] - match self.window { - LinuxWindow::Wayland(ref w) => w.set_csd_theme(theme), - #[cfg(feature = "x11")] - _ => (), - } - } } /// Additional methods on [`WindowBuilder`] that are specific to Wayland. diff --git a/src/platform/x11.rs b/src/platform/x11.rs index 37c524241..721d05638 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -190,9 +190,6 @@ pub trait WindowBuilderExtX11 { /// Build window with `_NET_WM_WINDOW_TYPE` hints; defaults to `Normal`. Only relevant on X11. fn with_x11_window_type(self, x11_window_type: Vec) -> Self; - /// Build window with `_GTK_THEME_VARIANT` hint set to the specified value. Currently only relevant on X11. - fn with_gtk_theme_variant(self, variant: String) -> Self; - /// Build window with base size hint. Only implemented on X11. /// /// ``` @@ -248,12 +245,6 @@ impl WindowBuilderExtX11 for WindowBuilder { self } - #[inline] - fn with_gtk_theme_variant(mut self, variant: String) -> Self { - self.platform_specific.gtk_theme_variant = Some(variant); - self - } - #[inline] fn with_base_size>(mut self, base_size: S) -> Self { self.platform_specific.base_size = Some(base_size.into()); diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index ce2fcf3b1..0e06959fb 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -100,8 +100,6 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub override_redirect: bool, #[cfg(feature = "x11")] pub x11_window_types: Vec, - #[cfg(feature = "x11")] - pub gtk_theme_variant: Option, } impl Default for PlatformSpecificWindowBuilderAttributes { @@ -120,8 +118,6 @@ impl Default for PlatformSpecificWindowBuilderAttributes { override_redirect: false, #[cfg(feature = "x11")] x11_window_types: vec![XWindowType::Normal], - #[cfg(feature = "x11")] - gtk_theme_variant: None, } } } diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index fb16099cd..a86055111 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -439,11 +439,6 @@ impl Window { self.decorated.load(Ordering::Relaxed) } - #[inline] - pub fn set_csd_theme(&self, theme: Theme) { - self.send_request(WindowRequest::CsdThemeVariant(theme)); - } - #[inline] pub fn set_minimized(&self, minimized: bool) { // You can't unminimize the window on Wayland. diff --git a/src/platform_impl/linux/wayland/window/shim.rs b/src/platform_impl/linux/wayland/window/shim.rs index a6acb90f6..f0cc87efb 100644 --- a/src/platform_impl/linux/wayland/window/shim.rs +++ b/src/platform_impl/linux/wayland/window/shim.rs @@ -59,9 +59,6 @@ pub enum WindowRequest { /// Request decorations change. Decorate(bool), - /// Request decorations change. - CsdThemeVariant(Theme), - /// Make the window resizeable. Resizeable(bool), @@ -467,15 +464,6 @@ pub fn handle_window_requests(winit_state: &mut WinitState) { let window_request = window_user_requests.get_mut(window_id).unwrap(); window_request.refresh_frame = true; } - #[cfg(feature = "sctk-adwaita")] - WindowRequest::CsdThemeVariant(theme) => { - window_handle.window.set_frame_config(theme.into()); - - let window_requst = window_user_requests.get_mut(window_id).unwrap(); - window_requst.refresh_frame = true; - } - #[cfg(not(feature = "sctk-adwaita"))] - WindowRequest::CsdThemeVariant(_) => {} WindowRequest::Resizeable(resizeable) => { window_handle.window.set_resizable(resizeable); @@ -542,7 +530,12 @@ pub fn handle_window_requests(winit_state: &mut WinitState) { } WindowRequest::Theme(_theme) => { #[cfg(feature = "sctk-adwaita")] - window_handle.window.set_frame_config(_theme.into()); + { + window_handle.window.set_frame_config(_theme.into()); + + let window_requst = window_user_requests.get_mut(window_id).unwrap(); + window_requst.refresh_frame = true; + } } }; } diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 6dc83a30e..51048f42c 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -299,6 +299,10 @@ impl UnownedWindow { .set_decorations_inner(window_attrs.decorations) .queue(); + if let Some(theme) = window_attrs.preferred_theme { + window.set_theme_inner(theme).queue(); + } + { // Enable drag and drop (TODO: extend API to make this toggleable) unsafe { @@ -357,10 +361,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 @@ -564,9 +564,13 @@ impl UnownedWindow { ) } - fn set_gtk_theme_variant(&self, variant: String) -> util::Flusher<'_> { + pub fn set_theme_inner(&self, theme: 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 { + Theme::Dark => "dark", + Theme::Light => "light", + }; let variant = CString::new(variant).expect("`_GTK_THEME_VARIANT` contained null byte"); self.xconn.change_property( self.xwindow, @@ -577,6 +581,13 @@ impl UnownedWindow { ) } + #[inline] + pub fn set_theme(&self, theme: Theme) { + self.set_theme_inner(theme) + .flush() + .expect("Failed to change window theme") + } + fn set_netwm( &self, operation: util::StateOperation, @@ -1547,9 +1558,6 @@ impl UnownedWindow { RawDisplayHandle::Xlib(display_handle) } - #[inline] - pub fn set_theme(&self, _theme: Theme) {} - #[inline] pub fn theme(&self) -> Option { None diff --git a/src/window.rs b/src/window.rs index ce0ffb8ca..ebfbb2316 100644 --- a/src/window.rs +++ b/src/window.rs @@ -947,6 +947,9 @@ impl Window { /// /// ## Platform-specific /// + /// - **Wayland:** You can also use `WINIT_WAYLAND_CSD_THEME` env variable to set the theme. + /// Possible values for env variable are: "dark" and light". When unspecified, a theme is automatically selected. + /// /// - **iOS / Android / Web / x11:** Unsupported. #[inline] pub fn set_theme(&self, theme: Theme) {