diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index c42c259352..fb063c3e90 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`. ### Changed diff --git a/src/platform/wayland.rs b/src/platform/wayland.rs index 84af00388b..26b31c242a 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -13,10 +13,14 @@ //! * `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::monitor::MonitorHandle; pub use crate::window::Theme; -use crate::window::{Window as CoreWindow, WindowAttributes}; +use crate::window::WindowAttributes; /// Additional methods on [`ActiveEventLoop`] that are specific to Wayland. pub trait ActiveEventLoopExtWayland { @@ -73,9 +77,10 @@ impl EventLoopBuilderExtWayland for EventLoopBuilder { /// Additional methods on [`Window`] that are specific to Wayland. /// /// [`Window`]: crate::window::Window -pub trait WindowExtWayland {} - -impl WindowExtWayland for dyn CoreWindow + '_ {} +pub trait WindowExtWayland { + /// Returns `xdg_toplevel` of the window or [`None`] if the window is X11 window. + fn xdg_toplevel(&self) -> Option>; +} /// 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 761ea7ffa5..947b089893 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}; @@ -22,6 +24,7 @@ use crate::error::{NotSupportedError, RequestError}; use crate::event::{Ime, WindowEvent}; use crate::event_loop::AsyncRequestSerial; use crate::monitor::MonitorHandle as CoreMonitorHandle; +use crate::platform::wayland::WindowExtWayland; use crate::platform_impl::{Fullscreen, MonitorHandle as PlatformMonitorHandle}; use crate::window::{ Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme, @@ -659,6 +662,16 @@ impl CoreWindow for Window { } } +impl WindowExtWayland for dyn CoreWindow + '_ { + #[inline] + fn xdg_toplevel(&self) -> Option> { + let w = self.as_any().downcast_ref::()?; + let id = w.window.xdg_toplevel().id(); + + NonNull::new(id.as_ptr().cast()) + } +} + /// The request from the window to the event loop. #[derive(Debug)] pub struct WindowRequests {