mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
review changes
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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<XWindowType>) -> 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<S: Into<Size>>(mut self, base_size: S) -> Self {
|
||||
self.platform_specific.base_size = Some(base_size.into());
|
||||
|
||||
@@ -100,8 +100,6 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
pub override_redirect: bool,
|
||||
#[cfg(feature = "x11")]
|
||||
pub x11_window_types: Vec<XWindowType>,
|
||||
#[cfg(feature = "x11")]
|
||||
pub gtk_theme_variant: Option<String>,
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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<Theme> {
|
||||
None
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user