Skip to content

Commit

Permalink
wayland: Add WindowExtWayland::xdg_toplevel
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Jan 11, 2025
1 parent 69382fd commit 0cf8781
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/platform/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<crate::platform_impl::wayland::Window>()
.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 {
Expand Down
6 changes: 6 additions & 0 deletions src/platform_impl/linux/wayland/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0cf8781

Please sign in to comment.