diff --git a/CHANGELOG.md b/CHANGELOG.md index 66ff5391..35467e4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed graphical glitches when resizing on Wayland. - On Windows, fix freezes when performing certain actions after a window resize has been triggered. Reintroduces some visual artifacts when resizing. - Updated window manager hints under X11 to v1.5 of [Extended Window Manager Hints](https://specifications.freedesktop.org/wm-spec/wm-spec-1.5.html#idm140200472629520). +- Added `WindowBuilderExt::with_gtk_theme_variant` to X11-specific `WindowBuilder` functions. # Version 0.17.2 (2018-08-19) diff --git a/src/os/unix.rs b/src/os/unix.rs index b06a3d72..e166da73 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -219,6 +219,8 @@ pub trait WindowBuilderExt { fn with_override_redirect(self, override_redirect: bool) -> WindowBuilder; /// Build window with `_NET_WM_WINDOW_TYPE` hint; defaults to `Normal`. Only relevant on X11. fn with_x11_window_type(self, x11_window_type: XWindowType) -> WindowBuilder; + /// 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) -> WindowBuilder; /// Build window with resize increment hint. Only implemented on X11. fn with_resize_increments(self, increments: LogicalSize) -> WindowBuilder; /// Build window with base size hint. Only implemented on X11. @@ -269,6 +271,12 @@ impl WindowBuilderExt for WindowBuilder { self.platform_specific.base_size = Some(base_size.into()); self } + + #[inline] + fn with_gtk_theme_variant(mut self, variant: String) -> WindowBuilder { + self.platform_specific.gtk_theme_variant = Some(variant); + self + } } /// Additional methods on `MonitorId` that are specific to Linux. diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 5dc8a491..beca2076 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -45,6 +45,7 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub class: Option<(String, String)>, pub override_redirect: bool, pub x11_window_type: x11::util::WindowType, + pub gtk_theme_variant: Option, } lazy_static!( diff --git a/src/platform/linux/x11/window.rs b/src/platform/linux/x11/window.rs index 66394676..67d60a9e 100644 --- a/src/platform/linux/x11/window.rs +++ b/src/platform/linux/x11/window.rs @@ -272,6 +272,10 @@ impl UnownedWindow { window.set_window_type(pl_attribs.x11_window_type).queue(); } + if let Some(variant) = pl_attribs.gtk_theme_variant { + window.set_gtk_theme_variant(variant).queue(); + } + // set size hints { let mut min_dimensions = window_attrs.min_dimensions; @@ -457,6 +461,19 @@ impl UnownedWindow { ) } + fn set_gtk_theme_variant(&self, variant: String) -> 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 = CString::new(variant).expect("`_GTK_THEME_VARIANT` contained null byte"); + self.xconn.change_property( + self.xwindow, + hint_atom, + utf8_atom, + util::PropMode::Replace, + variant.as_bytes(), + ) + } + #[inline] pub fn set_urgent(&self, is_urgent: bool) { let mut wm_hints = self.xconn.get_wm_hints(self.xwindow).expect("`XGetWMHints` failed");