Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/shell/xdg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
qh,
WindowData(weak.clone()),
);
let xdg_surface = XdgShellSurface { surface, xdg_surface };
let xdg_surface = XdgShellSurface { surface: Some(surface), xdg_surface };
let xdg_toplevel = xdg_surface.xdg_surface().get_toplevel(qh, WindowData(weak.clone()));

// If server side decorations are available, create the toplevel decoration.
Expand Down Expand Up @@ -138,11 +138,11 @@
}
});

WindowInner {
WindowInner::new(
xdg_surface,
xdg_toplevel,
toplevel_decoration,
pending_configure: Mutex::new(WindowConfigure {
Mutex::new(WindowConfigure {
new_size: (None, None),
suggested_bounds: None,
// Initial configure will indicate whether there are server side decorations.
Expand All @@ -151,7 +151,7 @@
// XXX by default we assume that everything is supported.
capabilities: WindowManagerCapabilities::all(),
}),
}
)
});

// Explicitly drop the queue freeze to allow the queue to resume work.
Expand Down Expand Up @@ -211,7 +211,7 @@
self: Arc<Self>,
_: &wayland_client::backend::Backend,
_: wayland_client::backend::protocol::Message<wayland_client::backend::ObjectId, OwnedFd>,
) -> Option<Arc<(dyn wayland_client::backend::ObjectData + 'static)>> {

Check warning on line 214 in src/shell/xdg/mod.rs

View workflow job for this annotation

GitHub Actions / test (beta)

unnecessary parentheses around type

Check warning on line 214 in src/shell/xdg/mod.rs

View workflow job for this annotation

GitHub Actions / test (beta)

unnecessary parentheses around type

Check warning on line 214 in src/shell/xdg/mod.rs

View workflow job for this annotation

GitHub Actions / test (beta)

unnecessary parentheses around type

Check warning on line 214 in src/shell/xdg/mod.rs

View workflow job for this annotation

GitHub Actions / test (beta)

unnecessary parentheses around type

Check warning on line 214 in src/shell/xdg/mod.rs

View workflow job for this annotation

GitHub Actions / test (beta)

unnecessary parentheses around type

Check warning on line 214 in src/shell/xdg/mod.rs

View workflow job for this annotation

GitHub Actions / ci (beta)

unnecessary parentheses around type

Check warning on line 214 in src/shell/xdg/mod.rs

View workflow job for this annotation

GitHub Actions / ci (beta)

unnecessary parentheses around type
unreachable!("xdg_positioner has no events");
}
fn destroyed(&self, _: wayland_client::backend::ObjectId) {}
Expand All @@ -221,7 +221,9 @@
#[derive(Debug)]
pub struct XdgShellSurface {
xdg_surface: xdg_surface::XdgSurface,
surface: Surface,
// Will always be Some, only needed to extract surface in destroy before
// drop.
surface: Option<Surface>,
}

impl XdgShellSurface {
Expand Down Expand Up @@ -258,15 +260,19 @@
let surface = surface.into();
let xdg_surface = wm_base.bound_global()?.get_xdg_surface(surface.wl_surface(), qh, udata);

Ok(XdgShellSurface { xdg_surface, surface })
Ok(XdgShellSurface { xdg_surface, surface: Some(surface) })
}

pub fn xdg_surface(&self) -> &xdg_surface::XdgSurface {
&self.xdg_surface
}

pub fn wl_surface(&self) -> &wl_surface::WlSurface {
self.surface.wl_surface()
self.surface.as_ref().unwrap().wl_surface()
}

pub fn destroy(mut self) -> Surface {
self.surface.take().unwrap()
}
}

Expand Down
34 changes: 28 additions & 6 deletions src/shell/xdg/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@

#[derive(Debug)]
struct PopupInner {
surface: XdgShellSurface,
// Will always be Some, only needed to extract surface in destroy before
// drop.
surface: Option<XdgShellSurface>,
xdg_popup: xdg_popup::XdgPopup,
pending_position: (AtomicI32, AtomicI32),
pending_dimensions: (AtomicI32, AtomicI32),
pending_token: AtomicU32,
configure_state: AtomicU32,
}

impl PopupInner {
pub fn surface(&self) -> &XdgShellSurface {
&self.surface.as_ref().unwrap()

Check failure on line 48 in src/shell/xdg/popup.rs

View workflow job for this annotation

GitHub Actions / lint

this expression creates a reference which is immediately dereferenced by the compiler
}

pub fn destroy(mut self) -> XdgShellSurface {
self.surface.take().unwrap()
}
}

impl Popup {
/// Create a new popup.
///
Expand Down Expand Up @@ -96,7 +108,7 @@
qh,
PopupData { inner: weak.clone() },
);
let surface = XdgShellSurface { surface, xdg_surface };
let surface = XdgShellSurface { surface: Some(surface), xdg_surface };
let xdg_popup = surface.xdg_surface().get_popup(
parent,
position,
Expand All @@ -105,7 +117,7 @@
);

PopupInner {
surface,
surface: Some(surface),
xdg_popup,
pending_position: (AtomicI32::new(0), AtomicI32::new(0)),
pending_dimensions: (AtomicI32::new(-1), AtomicI32::new(-1)),
Expand All @@ -122,20 +134,30 @@
}

pub fn xdg_shell_surface(&self) -> &XdgShellSurface {
&self.inner.surface
&self.inner.surface()

Check failure on line 137 in src/shell/xdg/popup.rs

View workflow job for this annotation

GitHub Actions / lint

this expression creates a reference which is immediately dereferenced by the compiler
}

pub fn xdg_surface(&self) -> &xdg_surface::XdgSurface {
self.inner.surface.xdg_surface()
self.inner.surface().xdg_surface()
}

pub fn wl_surface(&self) -> &wl_surface::WlSurface {
self.inner.surface.wl_surface()
self.inner.surface().wl_surface()
}

pub fn reposition(&self, position: &xdg_positioner::XdgPositioner, token: u32) {
self.xdg_popup().reposition(position, token);
}

/// Destroy the popup and extract the underlying surface. Note that reusing
/// the surface for anything other than another xdg popup is a protocol
/// violation, and that the buffer attached to the surface must be cleared
/// before reuse as an xdg surface cannot have a buffer attached to it.
pub fn destroy(self) -> Surface {
// Should never panic because the only other Arc reference is a weak
// reference.
Arc::into_inner(self.inner).unwrap().destroy().destroy()

Check failure on line 159 in src/shell/xdg/popup.rs

View workflow job for this annotation

GitHub Actions / ci (1.65.0)

no function or associated item named `into_inner` found for struct `Arc<_>` in the current scope

Check failure on line 159 in src/shell/xdg/popup.rs

View workflow job for this annotation

GitHub Actions / lint

current MSRV (Minimum Supported Rust Version) is `1.65.0` but this item is stable since `1.70.0`
}
}

impl PopupData {
Expand Down
42 changes: 34 additions & 8 deletions src/shell/xdg/window/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@
WindowState,
};

#[derive(Debug)]
pub struct WindowInner {
// Will always be Some, only needed to extract xdg_surface in destroy before
// drop.
xdg_surface: Option<XdgShellSurface>,
pub xdg_toplevel: xdg_toplevel::XdgToplevel,
pub toplevel_decoration: Option<zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1>,
pub pending_configure: Mutex<WindowConfigure>,
}

impl WindowInner {
pub fn new(
xdg_surface: XdgShellSurface,
xdg_toplevel: xdg_toplevel::XdgToplevel,
toplevel_decoration: Option<zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1>,
pending_configure: Mutex<WindowConfigure>,
) -> Self {
Self {
xdg_surface: Some(xdg_surface),
xdg_toplevel,
toplevel_decoration,
pending_configure,
}
}

pub fn xdg_surface(&self) -> &XdgShellSurface {
&self.xdg_surface.as_ref().unwrap()

Check failure on line 56 in src/shell/xdg/window/inner.rs

View workflow job for this annotation

GitHub Actions / lint

this expression creates a reference which is immediately dereferenced by the compiler
}

pub fn destroy(mut self) -> XdgShellSurface {
self.xdg_surface.take().unwrap()
}
}

impl Drop for WindowInner {
fn drop(&mut self) {
// XDG decoration says we must destroy the decoration object before the toplevel
Expand All @@ -41,14 +75,6 @@
}
}

#[derive(Debug)]
pub struct WindowInner {
pub xdg_surface: XdgShellSurface,
pub xdg_toplevel: xdg_toplevel::XdgToplevel,
pub toplevel_decoration: Option<zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1>,
pub pending_configure: Mutex<WindowConfigure>,
}

impl ProvidesBoundGlobal<zxdg_decoration_manager_v1::ZxdgDecorationManagerV1, 1> for XdgShell {
fn bound_global(
&self,
Expand Down
15 changes: 13 additions & 2 deletions src/shell/xdg/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
xdg::shell::client::{xdg_surface, xdg_toplevel},
};

use crate::compositor::Surface;
use crate::shell::WaylandSurface;

use self::inner::WindowInner;
Expand Down Expand Up @@ -285,17 +286,27 @@
pub fn xdg_toplevel(&self) -> &xdg_toplevel::XdgToplevel {
&self.0.xdg_toplevel
}

/// Destroy the window and extract the underlying surface. Note that reusing
/// the surface for anything other than another xdg toplevel is a protocol
/// violation, and that the buffer attached to the surface must be cleared
/// before reuse as an xdg surface cannot have a buffer attached to it.
pub fn destroy(self) -> Surface {
// Should never panic because the only other Arc reference is a weak
// reference.
Arc::into_inner(self.0).unwrap().destroy().destroy()

Check failure on line 297 in src/shell/xdg/window/mod.rs

View workflow job for this annotation

GitHub Actions / ci (1.65.0)

no function or associated item named `into_inner` found for struct `Arc<_>` in the current scope

Check failure on line 297 in src/shell/xdg/window/mod.rs

View workflow job for this annotation

GitHub Actions / lint

current MSRV (Minimum Supported Rust Version) is `1.65.0` but this item is stable since `1.70.0`
}
}

impl WaylandSurface for Window {
fn wl_surface(&self) -> &wl_surface::WlSurface {
self.0.xdg_surface.wl_surface()
self.0.xdg_surface().wl_surface()
}
}

impl XdgSurface for Window {
fn xdg_surface(&self) -> &xdg_surface::XdgSurface {
self.0.xdg_surface.xdg_surface()
self.0.xdg_surface().xdg_surface()
}
}

Expand Down
Loading