feat: xdg surface handle
This commit is contained in:
parent
f98ccf8efc
commit
b961e4877d
2 changed files with 45 additions and 1 deletions
|
|
@ -14,10 +14,13 @@
|
|||
//! * `wayland-csd-adwaita-crossfont`.
|
||||
//! * `wayland-csd-adwaita-notitle`.
|
||||
//! * `wayland-csd-adwaita-notitlebar`.
|
||||
use std::any::Any;
|
||||
use std::ffi::c_void;
|
||||
use std::marker::PhantomData;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
use dpi::{LogicalSize, PhysicalSize};
|
||||
use rwh_06::HandleError;
|
||||
use sctk::reexports::client::Proxy;
|
||||
use sctk::reexports::client::protocol::wl_surface::WlSurface;
|
||||
use sctk::shm::slot::{Buffer, CreateBufferError, SlotPool};
|
||||
|
|
@ -72,12 +75,35 @@ pub trait EventLoopBuilderExtWayland {
|
|||
fn with_any_thread(&mut self, any_thread: bool) -> &mut Self;
|
||||
}
|
||||
|
||||
pub struct XdgSurfaceHandle<'a> {
|
||||
raw: NonNull<c_void>,
|
||||
_marker: PhantomData<&'a ()>,
|
||||
}
|
||||
|
||||
impl<'a> XdgSurfaceHandle<'a> {
|
||||
/// Create a `XdgSurfaceHandle` from a [`NonNull<c_void>`]
|
||||
pub unsafe fn borrow_raw(raw: NonNull<c_void>) -> Self {
|
||||
Self { raw, _marker: PhantomData }
|
||||
}
|
||||
|
||||
/// Get the underlying raw xdg_surface handle.
|
||||
pub fn as_raw(&self) -> NonNull<c_void> {
|
||||
self.raw
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasXdgSurfaceHandle {
|
||||
fn xdg_surface_handle(&self) -> Result<XdgSurfaceHandle<'_>, HandleError>;
|
||||
}
|
||||
|
||||
/// Additional methods on [`Window`] that are specific to Wayland.
|
||||
///
|
||||
/// [`Window`]: crate::window::Window
|
||||
pub trait WindowExtWayland {
|
||||
/// Returns `xdg_toplevel` of the window or [`None`] if the window is X11 window.
|
||||
fn xdg_toplevel(&self) -> Option<NonNull<c_void>>;
|
||||
|
||||
fn xdg_surface_handle<'a>(&'a self) -> Option<&dyn HasXdgSurfaceHandle>;
|
||||
}
|
||||
|
||||
impl WindowExtWayland for dyn CoreWindow + '_ {
|
||||
|
|
@ -85,6 +111,12 @@ impl WindowExtWayland for dyn CoreWindow + '_ {
|
|||
fn xdg_toplevel(&self) -> Option<NonNull<c_void>> {
|
||||
self.cast_ref::<Window>()?.xdg_toplevel()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
fn xdg_surface_handle(&self) -> Option<&dyn HasXdgSurfaceHandle> {
|
||||
Some(self.cast_ref::<Window>()? as &dyn HasXdgSurfaceHandle)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue