Skip to content

Commit 0cf8781

Browse files
committed
wayland: Add WindowExtWayland::xdg_toplevel
1 parent 69382fd commit 0cf8781

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Diff for: src/platform/wayland.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
//! * `wayland-csd-adwaita` (default).
1414
//! * `wayland-csd-adwaita-crossfont`.
1515
//! * `wayland-csd-adwaita-notitle`.
16+
17+
use std::ffi::c_void;
18+
use std::ptr::null_mut;
19+
20+
use sctk::reexports::client::Proxy;
21+
1622
use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder};
1723
use crate::monitor::MonitorHandle;
1824
pub use crate::window::Theme;
@@ -73,9 +79,20 @@ impl EventLoopBuilderExtWayland for EventLoopBuilder {
7379
/// Additional methods on [`Window`] that are specific to Wayland.
7480
///
7581
/// [`Window`]: crate::window::Window
76-
pub trait WindowExtWayland {}
82+
pub trait WindowExtWayland {
83+
/// Returns `xdg_toplevel` of the window or null if the window is X11 window.
84+
fn xdg_toplevel(&self) -> *mut c_void;
85+
}
7786

78-
impl WindowExtWayland for dyn CoreWindow + '_ {}
87+
impl WindowExtWayland for dyn CoreWindow + '_ {
88+
#[inline]
89+
fn xdg_toplevel(&self) -> *mut c_void {
90+
self.as_any()
91+
.downcast_ref::<crate::platform_impl::wayland::Window>()
92+
.map(|w| w.xdg_toplevel().id().as_ptr().cast())
93+
.unwrap_or(null_mut())
94+
}
95+
}
7996

8097
/// Additional methods on [`WindowAttributes`] that are specific to Wayland.
8198
pub trait WindowAttributesExtWayland {

Diff for: src/platform_impl/linux/wayland/window/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use sctk::reexports::client::protocol::wl_display::WlDisplay;
88
use sctk::reexports::client::protocol::wl_surface::WlSurface;
99
use sctk::reexports::client::{Proxy, QueueHandle};
1010
use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_v1::XdgActivationV1;
11+
use sctk::reexports::protocols::xdg::shell::client::xdg_toplevel::XdgToplevel;
1112
use sctk::shell::xdg::window::{Window as SctkWindow, WindowDecorations};
1213
use sctk::shell::WaylandSurface;
1314
use tracing::warn;
@@ -239,6 +240,11 @@ impl Window {
239240
pub fn surface(&self) -> &WlSurface {
240241
self.window.wl_surface()
241242
}
243+
244+
#[inline]
245+
pub fn xdg_toplevel(&self) -> &XdgToplevel {
246+
self.window.xdg_toplevel()
247+
}
242248
}
243249

244250
impl Drop for Window {

0 commit comments

Comments
 (0)