wayland.shell.legacy: remove shell surface data
It is now redundant with the wl_surface user_data mechanism.
This commit is contained in:
parent
c604a48dce
commit
19432460cd
|
@ -36,17 +36,10 @@
|
|||
//! use smithay::wayland::compositor::CompositorToken;
|
||||
//! use smithay::wayland::shell::legacy::{wl_shell_init, ShellSurfaceRole, ShellRequest};
|
||||
//! # use wayland_server::protocol::{wl_seat, wl_output};
|
||||
//! # #[derive(Default)] struct MySurfaceData;
|
||||
//!
|
||||
//! // define the metadata you want associated with the shell surfaces
|
||||
//! #[derive(Default)]
|
||||
//! pub struct MyShellSurfaceData {
|
||||
//! /* ... */
|
||||
//! }
|
||||
//!
|
||||
//! // define the roles type. You need to integrate the XdgSurface role:
|
||||
//! define_roles!(MyRoles =>
|
||||
//! [ShellSurface, ShellSurfaceRole<MyShellSurfaceData>]
|
||||
//! [ShellSurface, ShellSurfaceRole]
|
||||
//! );
|
||||
//!
|
||||
//! # fn main() {
|
||||
|
@ -62,7 +55,7 @@
|
|||
//! // token from the compositor implementation
|
||||
//! compositor_token,
|
||||
//! // your implementation
|
||||
//! |event: ShellRequest<_, MyShellSurfaceData>| { /* ... */ },
|
||||
//! |event: ShellRequest<_>| { /* ... */ },
|
||||
//! None // put a logger if you want
|
||||
//! );
|
||||
//!
|
||||
|
@ -86,28 +79,24 @@ use wayland_server::{
|
|||
mod wl_handlers;
|
||||
|
||||
/// Metadata associated with the `wl_surface` role
|
||||
pub struct ShellSurfaceRole<D: 'static> {
|
||||
pub struct ShellSurfaceRole {
|
||||
/// Title of the surface
|
||||
pub title: String,
|
||||
/// Class of the surface
|
||||
pub class: String,
|
||||
pending_ping: u32,
|
||||
/// Some user data you may want to associate with the surface
|
||||
pub user_data: D,
|
||||
}
|
||||
|
||||
/// A handle to a shell surface
|
||||
pub struct ShellSurface<R, D> {
|
||||
pub struct ShellSurface<R> {
|
||||
wl_surface: wl_surface::WlSurface,
|
||||
shell_surface: wl_shell_surface::WlShellSurface,
|
||||
token: CompositorToken<R>,
|
||||
_d: ::std::marker::PhantomData<D>,
|
||||
}
|
||||
|
||||
impl<R, D> ShellSurface<R, D>
|
||||
impl<R> ShellSurface<R>
|
||||
where
|
||||
R: Role<ShellSurfaceRole<D>> + 'static,
|
||||
D: 'static,
|
||||
R: Role<ShellSurfaceRole> + 'static,
|
||||
{
|
||||
/// Is the shell surface referred by this handle still alive?
|
||||
pub fn alive(&self) -> bool {
|
||||
|
@ -168,16 +157,6 @@ where
|
|||
pub fn send_popup_done(&self) {
|
||||
self.shell_surface.popup_done()
|
||||
}
|
||||
|
||||
/// Access the user data you associated to this surface
|
||||
pub fn with_user_data<F, T>(&self, f: F) -> Result<T, ()>
|
||||
where
|
||||
F: FnOnce(&mut D) -> T,
|
||||
{
|
||||
self.token
|
||||
.with_role_data(&self.wl_surface, |data| f(&mut data.user_data))
|
||||
.map_err(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
/// Possible kinds of shell surface of the `wl_shell` protocol
|
||||
|
@ -234,13 +213,13 @@ pub enum ShellSurfaceKind {
|
|||
}
|
||||
|
||||
/// A request triggered by a `wl_shell_surface`
|
||||
pub enum ShellRequest<R, D> {
|
||||
pub enum ShellRequest<R> {
|
||||
/// A new shell surface was created
|
||||
///
|
||||
/// by default it has no kind and this should not be displayed
|
||||
NewShellSurface {
|
||||
/// The created surface
|
||||
surface: ShellSurface<R, D>,
|
||||
surface: ShellSurface<R>,
|
||||
},
|
||||
/// A pong event
|
||||
///
|
||||
|
@ -248,14 +227,14 @@ pub enum ShellRequest<R, D> {
|
|||
/// event, smithay has already checked that the responded serial was valid.
|
||||
Pong {
|
||||
/// The surface that sent the pong
|
||||
surface: ShellSurface<R, D>,
|
||||
surface: ShellSurface<R>,
|
||||
},
|
||||
/// Start of an interactive move
|
||||
///
|
||||
/// The surface requests that an interactive move is started on it
|
||||
Move {
|
||||
/// The surface requesting the move
|
||||
surface: ShellSurface<R, D>,
|
||||
surface: ShellSurface<R>,
|
||||
/// Serial of the implicit grab that initiated the move
|
||||
serial: u32,
|
||||
/// Seat associated with the move
|
||||
|
@ -266,7 +245,7 @@ pub enum ShellRequest<R, D> {
|
|||
/// The surface requests that an interactive resize is started on it
|
||||
Resize {
|
||||
/// The surface requesting the resize
|
||||
surface: ShellSurface<R, D>,
|
||||
surface: ShellSurface<R>,
|
||||
/// Serial of the implicit grab that initiated the resize
|
||||
serial: u32,
|
||||
/// Seat associated with the resize
|
||||
|
@ -277,7 +256,7 @@ pub enum ShellRequest<R, D> {
|
|||
/// The surface changed its kind
|
||||
SetKind {
|
||||
/// The surface
|
||||
surface: ShellSurface<R, D>,
|
||||
surface: ShellSurface<R>,
|
||||
/// Its new kind
|
||||
kind: ShellSurfaceKind,
|
||||
},
|
||||
|
@ -287,14 +266,13 @@ pub enum ShellRequest<R, D> {
|
|||
///
|
||||
/// This state allows you to retrieve a list of surfaces
|
||||
/// currently known to the shell global.
|
||||
pub struct ShellState<R, D> {
|
||||
known_surfaces: Vec<ShellSurface<R, D>>,
|
||||
pub struct ShellState<R> {
|
||||
known_surfaces: Vec<ShellSurface<R>>,
|
||||
}
|
||||
|
||||
impl<R, D> ShellState<R, D>
|
||||
impl<R> ShellState<R>
|
||||
where
|
||||
R: Role<ShellSurfaceRole<D>> + 'static,
|
||||
D: 'static,
|
||||
R: Role<ShellSurfaceRole> + 'static,
|
||||
{
|
||||
/// Cleans the internal surface storage by removing all dead surfaces
|
||||
pub(crate) fn cleanup_surfaces(&mut self) {
|
||||
|
@ -302,23 +280,22 @@ where
|
|||
}
|
||||
|
||||
/// Access all the shell surfaces known by this handler
|
||||
pub fn surfaces(&self) -> &[ShellSurface<R, D>] {
|
||||
pub fn surfaces(&self) -> &[ShellSurface<R>] {
|
||||
&self.known_surfaces[..]
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new `wl_shell` global
|
||||
pub fn wl_shell_init<R, D, L, Impl>(
|
||||
pub fn wl_shell_init<R, L, Impl>(
|
||||
display: &mut Display,
|
||||
ctoken: CompositorToken<R>,
|
||||
implementation: Impl,
|
||||
logger: L,
|
||||
) -> (Arc<Mutex<ShellState<R, D>>>, Global<wl_shell::WlShell>)
|
||||
) -> (Arc<Mutex<ShellState<R>>>, Global<wl_shell::WlShell>)
|
||||
where
|
||||
D: Default + 'static,
|
||||
R: Role<ShellSurfaceRole<D>> + 'static,
|
||||
R: Role<ShellSurfaceRole> + 'static,
|
||||
L: Into<Option<::slog::Logger>>,
|
||||
Impl: FnMut(ShellRequest<R, D>) + 'static,
|
||||
Impl: FnMut(ShellRequest<R>) + 'static,
|
||||
{
|
||||
let _log = crate::slog_or_stdlog(logger);
|
||||
|
||||
|
|
|
@ -13,15 +13,14 @@ use crate::wayland::compositor::{roles::Role, CompositorToken};
|
|||
|
||||
use super::{ShellRequest, ShellState, ShellSurface, ShellSurfaceKind, ShellSurfaceRole};
|
||||
|
||||
pub(crate) fn implement_shell<R, D, Impl>(
|
||||
pub(crate) fn implement_shell<R, Impl>(
|
||||
shell: NewResource<wl_shell::WlShell>,
|
||||
ctoken: CompositorToken<R>,
|
||||
implementation: Rc<RefCell<Impl>>,
|
||||
state: Arc<Mutex<ShellState<R, D>>>,
|
||||
state: Arc<Mutex<ShellState<R>>>,
|
||||
) where
|
||||
D: Default + 'static,
|
||||
R: Role<ShellSurfaceRole<D>> + 'static,
|
||||
Impl: FnMut(ShellRequest<R, D>) + 'static,
|
||||
R: Role<ShellSurfaceRole> + 'static,
|
||||
Impl: FnMut(ShellRequest<R>) + 'static,
|
||||
{
|
||||
shell.implement_closure(
|
||||
move |req, shell| {
|
||||
|
@ -33,7 +32,6 @@ pub(crate) fn implement_shell<R, D, Impl>(
|
|||
title: "".into(),
|
||||
class: "".into(),
|
||||
pending_ping: 0,
|
||||
user_data: Default::default(),
|
||||
};
|
||||
if ctoken.give_role_with(&surface, role_data).is_err() {
|
||||
shell
|
||||
|
@ -58,49 +56,46 @@ pub(crate) fn implement_shell<R, D, Impl>(
|
|||
);
|
||||
}
|
||||
|
||||
fn make_handle<R, SD>(
|
||||
fn make_handle<R>(
|
||||
shell_surface: &wl_shell_surface::WlShellSurface,
|
||||
token: CompositorToken<R>,
|
||||
) -> ShellSurface<R, SD>
|
||||
) -> ShellSurface<R>
|
||||
where
|
||||
R: Role<ShellSurfaceRole<SD>> + 'static,
|
||||
SD: 'static,
|
||||
R: Role<ShellSurfaceRole> + 'static,
|
||||
{
|
||||
let data = shell_surface
|
||||
.as_ref()
|
||||
.user_data::<ShellSurfaceUserData<R, SD>>()
|
||||
.user_data::<ShellSurfaceUserData<R>>()
|
||||
.unwrap();
|
||||
ShellSurface {
|
||||
wl_surface: data.surface.clone(),
|
||||
shell_surface: shell_surface.clone(),
|
||||
token,
|
||||
_d: ::std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct ShellSurfaceUserData<R, SD> {
|
||||
pub(crate) struct ShellSurfaceUserData<R> {
|
||||
surface: wl_surface::WlSurface,
|
||||
state: Arc<Mutex<ShellState<R, SD>>>,
|
||||
state: Arc<Mutex<ShellState<R>>>,
|
||||
}
|
||||
|
||||
fn implement_shell_surface<R, Impl, SD>(
|
||||
fn implement_shell_surface<R, Impl>(
|
||||
shell_surface: NewResource<wl_shell_surface::WlShellSurface>,
|
||||
surface: wl_surface::WlSurface,
|
||||
implementation: Rc<RefCell<Impl>>,
|
||||
ctoken: CompositorToken<R>,
|
||||
state: Arc<Mutex<ShellState<R, SD>>>,
|
||||
state: Arc<Mutex<ShellState<R>>>,
|
||||
) -> wl_shell_surface::WlShellSurface
|
||||
where
|
||||
SD: 'static,
|
||||
R: Role<ShellSurfaceRole<SD>> + 'static,
|
||||
Impl: FnMut(ShellRequest<R, SD>) + 'static,
|
||||
R: Role<ShellSurfaceRole> + 'static,
|
||||
Impl: FnMut(ShellRequest<R>) + 'static,
|
||||
{
|
||||
use self::wl_shell_surface::Request;
|
||||
shell_surface.implement_closure(
|
||||
move |req, shell_surface| {
|
||||
let data = shell_surface
|
||||
.as_ref()
|
||||
.user_data::<ShellSurfaceUserData<R, SD>>()
|
||||
.user_data::<ShellSurfaceUserData<R>>()
|
||||
.unwrap();
|
||||
let mut user_impl = implementation.borrow_mut();
|
||||
match req {
|
||||
|
@ -193,7 +188,7 @@ where
|
|||
Some(|shell_surface: wl_shell_surface::WlShellSurface| {
|
||||
let data = shell_surface
|
||||
.as_ref()
|
||||
.user_data::<ShellSurfaceUserData<R, SD>>()
|
||||
.user_data::<ShellSurfaceUserData<R>>()
|
||||
.unwrap();
|
||||
data.state.lock().unwrap().cleanup_surfaces();
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue