diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 0d796bff..f3eac171 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -70,6 +70,7 @@ changelog entry. - Added `Window::surface_position`, which is the position of the surface inside the window. - Added `Window::safe_area`, which describes the area of the surface that is unobstructed. - On X11, Wayland, Windows and macOS, improved scancode conversions for more obscure key codes. +- On Wayland, add `WindowExtWayland::xdg_toplevel`. - Add ability to make non-activating window on macOS using `NSPanel` with `NSWindowStyleMask::NonactivatingPanel`. - On Windows, add `IconExtWindows::from_resource_name`. - Implement `MonitorHandleProvider` for `MonitorHandle` to access common monitor API. diff --git a/src/platform/wayland.rs b/src/platform/wayland.rs index 86f6731b..b26e5cd2 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -13,7 +13,12 @@ //! * `wayland-csd-adwaita` (default). //! * `wayland-csd-adwaita-crossfont`. //! * `wayland-csd-adwaita-notitle`. + +use std::ffi::c_void; +use std::ptr::NonNull; + use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder}; +use crate::platform_impl::wayland::Window; pub use crate::window::Theme; use crate::window::{Window as CoreWindow, WindowAttributes}; @@ -72,9 +77,17 @@ impl EventLoopBuilderExtWayland for EventLoopBuilder { /// Additional methods on [`Window`] that are specific to Wayland. /// /// [`Window`]: crate::window::Window -pub trait WindowExtWayland {} +pub trait WindowExtWayland { + /// Returns `xdg_toplevel` of the window or [`None`] if the window is X11 window. + fn xdg_toplevel(&self) -> Option>; +} -impl WindowExtWayland for dyn CoreWindow + '_ {} +impl WindowExtWayland for dyn CoreWindow + '_ { + #[inline] + fn xdg_toplevel(&self) -> Option> { + self.cast_ref::()?.xdg_toplevel() + } +} /// Additional methods on [`WindowAttributes`] that are specific to Wayland. pub trait WindowAttributesExtWayland { diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index f76195d1..66e3d25a 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -1,5 +1,7 @@ //! The Wayland window. +use std::ffi::c_void; +use std::ptr::NonNull; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; @@ -214,6 +216,10 @@ impl Window { window_events_sink, }) } + + pub(crate) fn xdg_toplevel(&self) -> Option> { + NonNull::new(self.window.xdg_toplevel().id().as_ptr().cast()) + } } impl Window {