Add X11-specific with_gtk_theme_variant option (#659)

This commit is contained in:
Tobias Umbach 2018-09-20 23:00:04 +02:00 committed by Francesca Plebani
parent 1edbca1775
commit bc03ffb317
4 changed files with 27 additions and 0 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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<String>,
}
lazy_static!(

View file

@ -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");