diff --git a/src/platform/wayland.rs b/src/platform/wayland.rs index 84af00388bd..1fd9535f9fc 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -13,6 +13,12 @@ //! * `wayland-csd-adwaita` (default). //! * `wayland-csd-adwaita-crossfont`. //! * `wayland-csd-adwaita-notitle`. + +use std::ffi::c_void; +use std::ptr::null_mut; + +use sctk::reexports::client::Proxy; + use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder}; use crate::monitor::MonitorHandle; pub use crate::window::Theme; @@ -73,9 +79,20 @@ 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 null if the window is X11 window. + fn xdg_toplevel(&self) -> *mut c_void; +} -impl WindowExtWayland for dyn CoreWindow + '_ {} +impl WindowExtWayland for dyn CoreWindow + '_ { + #[inline] + fn xdg_toplevel(&self) -> *mut c_void { + self.as_any() + .downcast_ref::() + .map(|w| w.xdg_toplevel().id().as_ptr().cast()) + .unwrap_or(null_mut()) + } +} /// 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 761ea7ffa5b..e3f2a254398 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -8,6 +8,7 @@ use sctk::reexports::client::protocol::wl_display::WlDisplay; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{Proxy, QueueHandle}; use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_v1::XdgActivationV1; +use sctk::reexports::protocols::xdg::shell::client::xdg_toplevel::XdgToplevel; use sctk::shell::xdg::window::{Window as SctkWindow, WindowDecorations}; use sctk::shell::WaylandSurface; use tracing::warn; @@ -239,6 +240,11 @@ impl Window { pub fn surface(&self) -> &WlSurface { self.window.wl_surface() } + + #[inline] + pub fn xdg_toplevel(&self) -> &XdgToplevel { + self.window.xdg_toplevel() + } } impl Drop for Window {