autocommit 2022-01-04 15:30:21 CET
This commit is contained in:
parent
30376c595c
commit
cbbc41a463
40 changed files with 725 additions and 189 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
|
@ -212,6 +212,7 @@ dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"uapi",
|
"uapi",
|
||||||
"waker-fn",
|
"waker-fn",
|
||||||
|
"xcb-dl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -226,6 +227,16 @@ version = "0.2.112"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
|
checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libloading"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "afe203d669ec979b7128619bae5a63b7b42e9203c1b29146079ee05e2f604b52"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.14"
|
version = "0.4.14"
|
||||||
|
|
@ -440,3 +451,13 @@ name = "winapi-x86_64-pc-windows-gnu"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xcb-dl"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4ce37e57249f12cbdf43844a3c9b3162f528ec27a1dc1dd7c6f46826063f51e8"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"libloading",
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,4 @@ waker-fn = "1.1.0"
|
||||||
num-traits = "0.2.14"
|
num-traits = "0.2.14"
|
||||||
num-derive = "0.3.3"
|
num-derive = "0.3.3"
|
||||||
bitflags = "1.3.2"
|
bitflags = "1.3.2"
|
||||||
|
xcb-dl = "0.2.0"
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,16 @@ use crate::client::objects::Objects;
|
||||||
use crate::ifs::wl_callback::WlCallback;
|
use crate::ifs::wl_callback::WlCallback;
|
||||||
use crate::ifs::wl_compositor::{WlCompositorError, WlCompositorObj};
|
use crate::ifs::wl_compositor::{WlCompositorError, WlCompositorObj};
|
||||||
use crate::ifs::wl_display::{WlDisplay, WlDisplayError};
|
use crate::ifs::wl_display::{WlDisplay, WlDisplayError};
|
||||||
use crate::ifs::wl_region::{WlRegion, WlRegionError};
|
use crate::ifs::wl_region::{WlRegion, WlRegionError, WlRegionId};
|
||||||
use crate::ifs::wl_registry::{WlRegistry, WlRegistryError};
|
use crate::ifs::wl_registry::{WlRegistry, WlRegistryError, WlRegistryId};
|
||||||
use crate::ifs::wl_shm::{WlShmError, WlShmObj};
|
use crate::ifs::wl_shm::{WlShmError, WlShmObj};
|
||||||
use crate::ifs::wl_shm_pool::{WlShmPool, WlShmPoolError};
|
use crate::ifs::wl_shm_pool::{WlShmPool, WlShmPoolError};
|
||||||
use crate::ifs::wl_subcompositor::{WlSubcompositorError, WlSubcompositorObj};
|
use crate::ifs::wl_subcompositor::{WlSubcompositorError, WlSubcompositorObj};
|
||||||
use crate::ifs::wl_surface::wl_subsurface::{WlSubsurface, WlSubsurfaceError};
|
use crate::ifs::wl_surface::wl_subsurface::{WlSubsurface, WlSubsurfaceError};
|
||||||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopupError;
|
use crate::ifs::wl_surface::xdg_surface::xdg_popup::{XdgPopup, XdgPopupError};
|
||||||
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevelError;
|
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, XdgToplevelError};
|
||||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError};
|
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceId};
|
||||||
use crate::ifs::wl_surface::{WlSurface, WlSurfaceError};
|
use crate::ifs::wl_surface::{WlSurface, WlSurfaceError, WlSurfaceId};
|
||||||
use crate::ifs::xdg_positioner::{XdgPositioner, XdgPositionerError};
|
use crate::ifs::xdg_positioner::{XdgPositioner, XdgPositionerError};
|
||||||
use crate::ifs::xdg_wm_base::{XdgWmBaseError, XdgWmBaseObj};
|
use crate::ifs::xdg_wm_base::{XdgWmBaseError, XdgWmBaseObj};
|
||||||
use crate::object::{Object, ObjectId, WL_DISPLAY_ID};
|
use crate::object::{Object, ObjectId, WL_DISPLAY_ID};
|
||||||
|
|
@ -30,6 +30,7 @@ use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use uapi::OwnedFd;
|
use uapi::OwnedFd;
|
||||||
|
use crate::ifs::wl_buffer::{WlBuffer, WlBufferError};
|
||||||
|
|
||||||
mod objects;
|
mod objects;
|
||||||
mod tasks;
|
mod tasks;
|
||||||
|
|
@ -54,10 +55,12 @@ pub enum ClientError {
|
||||||
OutBufferOverflow,
|
OutBufferOverflow,
|
||||||
#[error("The requested client {0} does not exist")]
|
#[error("The requested client {0} does not exist")]
|
||||||
ClientDoesNotExist(ClientId),
|
ClientDoesNotExist(ClientId),
|
||||||
#[error("There is no region with id {0}")]
|
#[error("There is no wl_region with id {0}")]
|
||||||
RegionDoesNotExist(ObjectId),
|
RegionDoesNotExist(WlRegionId),
|
||||||
#[error("There is no surface with id {0}")]
|
#[error("There is no wl_surface with id {0}")]
|
||||||
SurfaceDoesNotExist(ObjectId),
|
SurfaceDoesNotExist(WlSurfaceId),
|
||||||
|
#[error("There is no xdg_surface with id {0}")]
|
||||||
|
XdgSurfaceDoesNotExist(XdgSurfaceId),
|
||||||
#[error("Cannot parse the message")]
|
#[error("Cannot parse the message")]
|
||||||
ParserError(#[source] Box<MsgParserError>),
|
ParserError(#[source] Box<MsgParserError>),
|
||||||
#[error("Server tried to allocate more than 0x1_00_00_00 ids")]
|
#[error("Server tried to allocate more than 0x1_00_00_00 ids")]
|
||||||
|
|
@ -100,6 +103,8 @@ pub enum ClientError {
|
||||||
XdgToplevelError(#[source] Box<XdgToplevelError>),
|
XdgToplevelError(#[source] Box<XdgToplevelError>),
|
||||||
#[error("An error occurred in a `xdg_wm_base`")]
|
#[error("An error occurred in a `xdg_wm_base`")]
|
||||||
XdgWmBaseError(#[source] Box<XdgWmBaseError>),
|
XdgWmBaseError(#[source] Box<XdgWmBaseError>),
|
||||||
|
#[error("An error occurred in a `wl_buffer`")]
|
||||||
|
WlBufferError(#[source] Box<WlBufferError>),
|
||||||
#[error("Object {0} is not a display")]
|
#[error("Object {0} is not a display")]
|
||||||
NotADisplay(ObjectId),
|
NotADisplay(ObjectId),
|
||||||
}
|
}
|
||||||
|
|
@ -119,6 +124,7 @@ efrom!(ClientError, XdgPositionerError, XdgPositionerError);
|
||||||
efrom!(ClientError, XdgWmBaseError, XdgWmBaseError);
|
efrom!(ClientError, XdgWmBaseError, XdgWmBaseError);
|
||||||
efrom!(ClientError, XdgToplevelError, XdgToplevelError);
|
efrom!(ClientError, XdgToplevelError, XdgToplevelError);
|
||||||
efrom!(ClientError, XdgPopupError, XdgPopupError);
|
efrom!(ClientError, XdgPopupError, XdgPopupError);
|
||||||
|
efrom!(ClientError, WlBufferError, WlBufferError);
|
||||||
|
|
||||||
impl ClientError {
|
impl ClientError {
|
||||||
fn peer_closed(&self) -> bool {
|
fn peer_closed(&self) -> bool {
|
||||||
|
|
@ -353,20 +359,27 @@ impl Client {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_region(&self, id: ObjectId) -> Result<Rc<WlRegion>, ClientError> {
|
pub fn get_region(&self, id: WlRegionId) -> Result<Rc<WlRegion>, ClientError> {
|
||||||
match self.objects.regions.get(&id) {
|
match self.objects.regions.get(&id) {
|
||||||
Some(r) => Ok(r),
|
Some(r) => Ok(r),
|
||||||
_ => Err(ClientError::RegionDoesNotExist(id)),
|
_ => Err(ClientError::RegionDoesNotExist(id)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_surface(&self, id: ObjectId) -> Result<Rc<WlSurface>, ClientError> {
|
pub fn get_surface(&self, id: WlSurfaceId) -> Result<Rc<WlSurface>, ClientError> {
|
||||||
match self.objects.surfaces.get(&id) {
|
match self.objects.surfaces.get(&id) {
|
||||||
Some(r) => Ok(r),
|
Some(r) => Ok(r),
|
||||||
_ => Err(ClientError::SurfaceDoesNotExist(id)),
|
_ => Err(ClientError::SurfaceDoesNotExist(id)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_xdg_surface(&self, id: XdgSurfaceId) -> Result<Rc<XdgSurface>, ClientError> {
|
||||||
|
match self.objects.xdg_surfaces.get(&id) {
|
||||||
|
Some(r) => Ok(r),
|
||||||
|
_ => Err(ClientError::XdgSurfaceDoesNotExist(id)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn simple_add_obj<T: Object>(&self, obj: &Rc<T>, client: bool) -> Result<(), ClientError> {
|
fn simple_add_obj<T: Object>(&self, obj: &Rc<T>, client: bool) -> Result<(), ClientError> {
|
||||||
if client {
|
if client {
|
||||||
self.objects.add_client_object(obj.clone())
|
self.objects.add_client_object(obj.clone())
|
||||||
|
|
@ -383,7 +396,7 @@ impl Client {
|
||||||
self.objects.remove_obj(self, id)
|
self.objects.remove_obj(self, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lock_registries(&self) -> RefMut<AHashMap<ObjectId, Rc<WlRegistry>>> {
|
pub fn lock_registries(&self) -> RefMut<AHashMap<WlRegistryId, Rc<WlRegistry>>> {
|
||||||
self.objects.registries()
|
self.objects.registries()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -438,7 +451,9 @@ simple_add_obj!(WlShmPool);
|
||||||
simple_add_obj!(WlSubcompositorObj);
|
simple_add_obj!(WlSubcompositorObj);
|
||||||
simple_add_obj!(WlSubsurface);
|
simple_add_obj!(WlSubsurface);
|
||||||
simple_add_obj!(XdgPositioner);
|
simple_add_obj!(XdgPositioner);
|
||||||
simple_add_obj!(XdgSurface);
|
simple_add_obj!(XdgToplevel);
|
||||||
|
simple_add_obj!(XdgPopup);
|
||||||
|
simple_add_obj!(WlBuffer);
|
||||||
|
|
||||||
macro_rules! dedicated_add_obj {
|
macro_rules! dedicated_add_obj {
|
||||||
($ty:ty, $field:ident) => {
|
($ty:ty, $field:ident) => {
|
||||||
|
|
@ -447,11 +462,11 @@ macro_rules! dedicated_add_obj {
|
||||||
|
|
||||||
fn add_obj(&self, obj: &Rc<$ty>, client: bool) -> Result<(), ClientError> {
|
fn add_obj(&self, obj: &Rc<$ty>, client: bool) -> Result<(), ClientError> {
|
||||||
self.simple_add_obj(obj, client)?;
|
self.simple_add_obj(obj, client)?;
|
||||||
self.objects.$field.set(obj.id(), obj.clone());
|
self.objects.$field.set(obj.id().into(), obj.clone());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn remove_obj<'a>(&'a self, obj: &'a $ty) -> Self::RemoveObj<'a> {
|
fn remove_obj<'a>(&'a self, obj: &'a $ty) -> Self::RemoveObj<'a> {
|
||||||
self.objects.$field.remove(&obj.id());
|
self.objects.$field.remove(&obj.id().into());
|
||||||
self.simple_remove_obj(obj.id())
|
self.simple_remove_obj(obj.id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -461,3 +476,4 @@ macro_rules! dedicated_add_obj {
|
||||||
dedicated_add_obj!(WlRegion, regions);
|
dedicated_add_obj!(WlRegion, regions);
|
||||||
dedicated_add_obj!(WlSurface, surfaces);
|
dedicated_add_obj!(WlSurface, surfaces);
|
||||||
dedicated_add_obj!(XdgWmBaseObj, xdg_wm_bases);
|
dedicated_add_obj!(XdgWmBaseObj, xdg_wm_bases);
|
||||||
|
dedicated_add_obj!(XdgSurface, xdg_surfaces);
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,25 @@
|
||||||
use crate::client::{Client, ClientError};
|
use crate::client::{Client, ClientError};
|
||||||
use crate::ifs::wl_display::WlDisplay;
|
use crate::ifs::wl_display::WlDisplay;
|
||||||
use crate::ifs::wl_region::WlRegion;
|
use crate::ifs::wl_region::{WlRegion, WlRegionId};
|
||||||
use crate::ifs::wl_registry::WlRegistry;
|
use crate::ifs::wl_registry::{WlRegistry, WlRegistryId};
|
||||||
use crate::ifs::wl_surface::WlSurface;
|
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId};
|
||||||
|
use crate::ifs::wl_surface::{WlSurface, WlSurfaceId};
|
||||||
|
use crate::ifs::xdg_wm_base::{XdgWmBaseId, XdgWmBaseObj};
|
||||||
use crate::object::{Object, ObjectId};
|
use crate::object::{Object, ObjectId};
|
||||||
use crate::utils::copyhashmap::CopyHashMap;
|
use crate::utils::copyhashmap::CopyHashMap;
|
||||||
use ahash::AHashMap;
|
use ahash::AHashMap;
|
||||||
use std::cell::{RefCell, RefMut};
|
use std::cell::{RefCell, RefMut};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
|
|
||||||
|
|
||||||
pub struct Objects {
|
pub struct Objects {
|
||||||
pub display: RefCell<Option<Rc<WlDisplay>>>,
|
pub display: RefCell<Option<Rc<WlDisplay>>>,
|
||||||
registry: CopyHashMap<ObjectId, Rc<dyn Object>>,
|
registry: CopyHashMap<ObjectId, Rc<dyn Object>>,
|
||||||
registries: CopyHashMap<ObjectId, Rc<WlRegistry>>,
|
registries: CopyHashMap<WlRegistryId, Rc<WlRegistry>>,
|
||||||
pub surfaces: CopyHashMap<ObjectId, Rc<WlSurface>>,
|
pub surfaces: CopyHashMap<WlSurfaceId, Rc<WlSurface>>,
|
||||||
pub regions: CopyHashMap<ObjectId, Rc<WlRegion>>,
|
pub xdg_surfaces: CopyHashMap<XdgSurfaceId, Rc<XdgSurface>>,
|
||||||
pub xdg_wm_bases: CopyHashMap<ObjectId, Rc<XdgWmBaseObj>>,
|
pub regions: CopyHashMap<WlRegionId, Rc<WlRegion>>,
|
||||||
|
pub xdg_wm_bases: CopyHashMap<XdgWmBaseId, Rc<XdgWmBaseObj>>,
|
||||||
ids: RefCell<Vec<usize>>,
|
ids: RefCell<Vec<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,6 +33,7 @@ impl Objects {
|
||||||
registry: Default::default(),
|
registry: Default::default(),
|
||||||
registries: Default::default(),
|
registries: Default::default(),
|
||||||
surfaces: Default::default(),
|
surfaces: Default::default(),
|
||||||
|
xdg_surfaces: Default::default(),
|
||||||
regions: Default::default(),
|
regions: Default::default(),
|
||||||
xdg_wm_bases: Default::default(),
|
xdg_wm_bases: Default::default(),
|
||||||
ids: RefCell::new(vec![]),
|
ids: RefCell::new(vec![]),
|
||||||
|
|
@ -39,25 +42,24 @@ impl Objects {
|
||||||
|
|
||||||
pub fn destroy(&self) {
|
pub fn destroy(&self) {
|
||||||
{
|
{
|
||||||
let mut surfaces = self.surfaces.lock();
|
let mut registry = self.registry.lock();
|
||||||
for surface in surfaces.values_mut() {
|
for obj in registry.values_mut() {
|
||||||
surface.break_loops();
|
obj.break_loops();
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let mut xdg_wm_bases = self.xdg_wm_bases.lock();
|
|
||||||
for xdg_wm_base in xdg_wm_bases.values_mut() {
|
|
||||||
xdg_wm_base.break_loops();
|
|
||||||
}
|
}
|
||||||
|
registry.clear();
|
||||||
}
|
}
|
||||||
*self.display.borrow_mut() = None;
|
*self.display.borrow_mut() = None;
|
||||||
self.registry.clear();
|
|
||||||
self.regions.clear();
|
self.regions.clear();
|
||||||
self.registries.clear();
|
self.registries.clear();
|
||||||
self.surfaces.clear();
|
self.surfaces.clear();
|
||||||
|
self.xdg_wm_bases.clear();
|
||||||
|
self.xdg_surfaces.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(&self, client_data: &Client) -> Result<ObjectId, ClientError> {
|
fn id<T>(&self, client_data: &Client) -> Result<T, ClientError>
|
||||||
|
where
|
||||||
|
ObjectId: Into<T>,
|
||||||
|
{
|
||||||
const MAX_ID_OFFSET: u32 = u32::MAX - MIN_SERVER_ID;
|
const MAX_ID_OFFSET: u32 = u32::MAX - MIN_SERVER_ID;
|
||||||
let offset = self.id_offset();
|
let offset = self.id_offset();
|
||||||
if offset > MAX_ID_OFFSET {
|
if offset > MAX_ID_OFFSET {
|
||||||
|
|
@ -68,7 +70,7 @@ impl Objects {
|
||||||
);
|
);
|
||||||
return Err(ClientError::TooManyIds);
|
return Err(ClientError::TooManyIds);
|
||||||
}
|
}
|
||||||
Ok(ObjectId::from_raw(MIN_SERVER_ID + offset))
|
Ok(ObjectId::from_raw(MIN_SERVER_ID + offset).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_obj(&self, id: ObjectId) -> Result<Rc<dyn Object>, ClientError> {
|
pub fn get_obj(&self, id: ObjectId) -> Result<Rc<dyn Object>, ClientError> {
|
||||||
|
|
@ -123,7 +125,7 @@ impl Objects {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn registries(&self) -> RefMut<AHashMap<ObjectId, Rc<WlRegistry>>> {
|
pub fn registries(&self) -> RefMut<AHashMap<WlRegistryId, Rc<WlRegistry>>> {
|
||||||
self.registries.lock()
|
self.registries.lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use ahash::AHashMap;
|
||||||
pub struct Format {
|
pub struct Format {
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
|
pub bpp: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn formats() -> AHashMap<u32, &'static Format> {
|
pub fn formats() -> AHashMap<u32, &'static Format> {
|
||||||
|
|
@ -22,10 +23,12 @@ static FORMATS: &[Format] = &[
|
||||||
Format {
|
Format {
|
||||||
id: 0,
|
id: 0,
|
||||||
name: "argb8888",
|
name: "argb8888",
|
||||||
|
bpp: 4,
|
||||||
},
|
},
|
||||||
Format {
|
Format {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: "xrgb8888",
|
name: "xrgb8888",
|
||||||
|
bpp: 4,
|
||||||
},
|
},
|
||||||
// Format {
|
// Format {
|
||||||
// id: fourcc_code('C', '8', ' ', ' '),
|
// id: fourcc_code('C', '8', ' ', ' '),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
|
pub mod wl_buffer;
|
||||||
pub mod wl_callback;
|
pub mod wl_callback;
|
||||||
pub mod wl_compositor;
|
pub mod wl_compositor;
|
||||||
pub mod wl_display;
|
pub mod wl_display;
|
||||||
|
pub mod wl_output;
|
||||||
pub mod wl_region;
|
pub mod wl_region;
|
||||||
pub mod wl_registry;
|
pub mod wl_registry;
|
||||||
|
pub mod wl_seat;
|
||||||
pub mod wl_shm;
|
pub mod wl_shm;
|
||||||
pub mod wl_shm_pool;
|
pub mod wl_shm_pool;
|
||||||
pub mod wl_subcompositor;
|
pub mod wl_subcompositor;
|
||||||
|
|
|
||||||
91
src/ifs/wl_buffer/mod.rs
Normal file
91
src/ifs/wl_buffer/mod.rs
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
mod types;
|
||||||
|
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use crate::client::{AddObj, Client};
|
||||||
|
use crate::clientmem::ClientMem;
|
||||||
|
use crate::format::Format;
|
||||||
|
use crate::object::{Interface, Object, ObjectId};
|
||||||
|
use std::rc::Rc;
|
||||||
|
pub use types::*;
|
||||||
|
use crate::utils::buffd::MsgParser;
|
||||||
|
|
||||||
|
const DESTROY: u32 = 0;
|
||||||
|
|
||||||
|
const RELEASE: u32 = 0;
|
||||||
|
|
||||||
|
id!(WlBufferId);
|
||||||
|
|
||||||
|
pub struct WlBuffer {
|
||||||
|
id: WlBufferId,
|
||||||
|
client: Rc<Client>,
|
||||||
|
offset: usize,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
stride: u32,
|
||||||
|
format: &'static Format,
|
||||||
|
mem: RefCell<Option<Rc<ClientMem>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WlBuffer {
|
||||||
|
pub fn new(
|
||||||
|
id: WlBufferId,
|
||||||
|
client: &Rc<Client>,
|
||||||
|
offset: usize,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
stride: u32,
|
||||||
|
format: &'static Format,
|
||||||
|
mem: &Rc<ClientMem>,
|
||||||
|
) -> Result<Self, WlBufferError> {
|
||||||
|
let bytes = stride as u64 * height as u64;
|
||||||
|
let required = bytes + offset as u64;
|
||||||
|
if required > mem.len() as u64 {
|
||||||
|
return Err(WlBufferError::OutOfBounds);
|
||||||
|
}
|
||||||
|
let min_row_size = width as u64 * format.bpp as u64;
|
||||||
|
if (stride as u64) < min_row_size {
|
||||||
|
return Err(WlBufferError::StrideTooSmall);
|
||||||
|
}
|
||||||
|
Ok(Self {
|
||||||
|
id,
|
||||||
|
client: client.clone(),
|
||||||
|
offset,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
stride,
|
||||||
|
format,
|
||||||
|
mem: RefCell::new(Some(mem.clone())),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||||
|
let _req: Destroy = self.client.parse(self, parser)?;
|
||||||
|
*self.mem.borrow_mut() = None;
|
||||||
|
self.client.remove_obj(self).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_request_(&self, request: u32, parser: MsgParser<'_, '_>) -> Result<(), WlBufferError> {
|
||||||
|
match request {
|
||||||
|
DESTROY => self.destroy(parser).await?,
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_request!(WlBuffer);
|
||||||
|
|
||||||
|
impl Object for WlBuffer {
|
||||||
|
fn id(&self) -> ObjectId {
|
||||||
|
self.id.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn interface(&self) -> Interface {
|
||||||
|
Interface::WlBuffer
|
||||||
|
}
|
||||||
|
|
||||||
|
fn num_requests(&self) -> u32 {
|
||||||
|
DESTROY + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
56
src/ifs/wl_buffer/types.rs
Normal file
56
src/ifs/wl_buffer/types.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
use std::fmt::{Debug, Formatter};
|
||||||
|
use std::rc::Rc;
|
||||||
|
use thiserror::Error;
|
||||||
|
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||||
|
use crate::ifs::wl_buffer::{RELEASE, WlBuffer};
|
||||||
|
use crate::object::Object;
|
||||||
|
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum WlBufferError {
|
||||||
|
#[error("The requested memory region is out of bounds for the pool")]
|
||||||
|
OutOfBounds,
|
||||||
|
#[error("The stride does not fit all pixels in a row")]
|
||||||
|
StrideTooSmall,
|
||||||
|
#[error("Could not handle a `destroy` request")]
|
||||||
|
DestroyError(#[from] DestroyError),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum DestroyError {
|
||||||
|
#[error("Parsing failed")]
|
||||||
|
ParseFailed(#[source] Box<MsgParserError>),
|
||||||
|
#[error(transparent)]
|
||||||
|
ClientError(Box<ClientError>),
|
||||||
|
}
|
||||||
|
efrom!(DestroyError, ParseFailed, MsgParserError);
|
||||||
|
efrom!(DestroyError, ClientError, ClientError);
|
||||||
|
|
||||||
|
pub(super) struct Destroy;
|
||||||
|
impl RequestParser<'_> for Destroy {
|
||||||
|
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
Ok(Self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Debug for Destroy {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "destroy()")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) struct Release {
|
||||||
|
pub obj: Rc<WlBuffer>,
|
||||||
|
}
|
||||||
|
impl EventFormatter for Release {
|
||||||
|
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||||
|
fmt.header(self.obj.id, RELEASE);
|
||||||
|
}
|
||||||
|
fn obj(&self) -> &dyn Object {
|
||||||
|
&*self.obj
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Debug for Release {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "release()")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,12 +8,14 @@ use types::*;
|
||||||
|
|
||||||
const DONE: u32 = 0;
|
const DONE: u32 = 0;
|
||||||
|
|
||||||
|
id!(WlCallbackId);
|
||||||
|
|
||||||
pub struct WlCallback {
|
pub struct WlCallback {
|
||||||
id: ObjectId,
|
id: WlCallbackId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WlCallback {
|
impl WlCallback {
|
||||||
pub fn new(id: ObjectId) -> Self {
|
pub fn new(id: WlCallbackId) -> Self {
|
||||||
Self { id }
|
Self { id }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,7 +36,7 @@ handle_request!(WlCallback);
|
||||||
|
|
||||||
impl Object for WlCallback {
|
impl Object for WlCallback {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,15 @@ pub use types::*;
|
||||||
const CREATE_SURFACE: u32 = 0;
|
const CREATE_SURFACE: u32 = 0;
|
||||||
const CREATE_REGION: u32 = 1;
|
const CREATE_REGION: u32 = 1;
|
||||||
|
|
||||||
|
id!(WlCompositorId);
|
||||||
|
|
||||||
pub struct WlCompositorGlobal {
|
pub struct WlCompositorGlobal {
|
||||||
name: GlobalName,
|
name: GlobalName,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WlCompositorObj {
|
pub struct WlCompositorObj {
|
||||||
global: Rc<WlCompositorGlobal>,
|
global: Rc<WlCompositorGlobal>,
|
||||||
id: ObjectId,
|
id: WlCompositorId,
|
||||||
client: Rc<Client>,
|
client: Rc<Client>,
|
||||||
version: u32,
|
version: u32,
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +32,7 @@ impl WlCompositorGlobal {
|
||||||
|
|
||||||
async fn bind_(
|
async fn bind_(
|
||||||
self: Rc<Self>,
|
self: Rc<Self>,
|
||||||
id: ObjectId,
|
id: WlCompositorId,
|
||||||
client: &Rc<Client>,
|
client: &Rc<Client>,
|
||||||
version: u32,
|
version: u32,
|
||||||
) -> Result<(), WlCompositorError> {
|
) -> Result<(), WlCompositorError> {
|
||||||
|
|
@ -98,7 +100,7 @@ handle_request!(WlCompositorObj);
|
||||||
|
|
||||||
impl Object for WlCompositorObj {
|
impl Object for WlCompositorObj {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::client::{ClientError, RequestParser};
|
use crate::client::{ClientError, RequestParser};
|
||||||
use crate::object::ObjectId;
|
use crate::ifs::wl_region::WlRegionId;
|
||||||
|
use crate::ifs::wl_surface::WlSurfaceId;
|
||||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
@ -41,7 +42,7 @@ efrom!(CreateRegionError, ParseFailed, MsgParserError);
|
||||||
efrom!(CreateRegionError, ClientError, ClientError);
|
efrom!(CreateRegionError, ClientError, ClientError);
|
||||||
|
|
||||||
pub(super) struct CreateSurface {
|
pub(super) struct CreateSurface {
|
||||||
pub id: ObjectId,
|
pub id: WlSurfaceId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for CreateSurface {
|
impl RequestParser<'_> for CreateSurface {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
@ -57,7 +58,7 @@ impl Debug for CreateSurface {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct CreateRegion {
|
pub(super) struct CreateRegion {
|
||||||
pub id: ObjectId,
|
pub id: WlRegionId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for CreateRegion {
|
impl RequestParser<'_> for CreateRegion {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ impl WlDisplay {
|
||||||
|
|
||||||
async fn sync(&self, parser: MsgParser<'_, '_>) -> Result<(), SyncError> {
|
async fn sync(&self, parser: MsgParser<'_, '_>) -> Result<(), SyncError> {
|
||||||
let sync: Sync = self.client.parse(self, parser)?;
|
let sync: Sync = self.client.parse(self, parser)?;
|
||||||
let cb = Rc::new(WlCallback::new(sync.callback));
|
let cb = Rc::new(WlCallback::new(sync.callback.into()));
|
||||||
self.client.add_client_obj(&cb)?;
|
self.client.add_client_obj(&cb)?;
|
||||||
self.client.event(cb.done()).await?;
|
self.client.event(cb.done()).await?;
|
||||||
self.client.remove_obj(&*cb).await?;
|
self.client.remove_obj(&*cb).await?;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||||
use crate::globals::GlobalError;
|
use crate::globals::GlobalError;
|
||||||
|
use crate::ifs::wl_callback::WlCallbackId;
|
||||||
use crate::ifs::wl_display::{WlDisplay, DELETE_ID, ERROR};
|
use crate::ifs::wl_display::{WlDisplay, DELETE_ID, ERROR};
|
||||||
|
use crate::ifs::wl_registry::WlRegistryId;
|
||||||
use crate::object::{Object, ObjectId, WL_DISPLAY_ID};
|
use crate::object::{Object, ObjectId, WL_DISPLAY_ID};
|
||||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
|
|
@ -44,7 +46,7 @@ efrom!(SyncError, ParseFailed, MsgParserError);
|
||||||
efrom!(SyncError, ClientError, ClientError);
|
efrom!(SyncError, ClientError, ClientError);
|
||||||
|
|
||||||
pub(super) struct GetRegistry {
|
pub(super) struct GetRegistry {
|
||||||
pub registry: ObjectId,
|
pub registry: WlRegistryId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for GetRegistry {
|
impl RequestParser<'_> for GetRegistry {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
@ -60,7 +62,7 @@ impl Debug for GetRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct Sync {
|
pub(super) struct Sync {
|
||||||
pub callback: ObjectId,
|
pub callback: WlCallbackId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for Sync {
|
impl RequestParser<'_> for Sync {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
|
||||||
1
src/ifs/wl_output/mod.rs
Normal file
1
src/ifs/wl_output/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
id!(WlOutputId);
|
||||||
|
|
@ -12,14 +12,16 @@ const DESTROY: u32 = 0;
|
||||||
const ADD: u32 = 1;
|
const ADD: u32 = 1;
|
||||||
const SUBTRACT: u32 = 2;
|
const SUBTRACT: u32 = 2;
|
||||||
|
|
||||||
|
id!(WlRegionId);
|
||||||
|
|
||||||
pub struct WlRegion {
|
pub struct WlRegion {
|
||||||
id: ObjectId,
|
id: WlRegionId,
|
||||||
client: Rc<Client>,
|
client: Rc<Client>,
|
||||||
rect: RefCell<Region>,
|
rect: RefCell<Region>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WlRegion {
|
impl WlRegion {
|
||||||
pub fn new(id: ObjectId, client: &Rc<Client>) -> Self {
|
pub fn new(id: WlRegionId, client: &Rc<Client>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
|
|
@ -81,7 +83,7 @@ handle_request!(WlRegion);
|
||||||
|
|
||||||
impl Object for WlRegion {
|
impl Object for WlRegion {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,15 @@ const BIND: u32 = 0;
|
||||||
const GLOBAL: u32 = 0;
|
const GLOBAL: u32 = 0;
|
||||||
const GLOBAL_REMOVE: u32 = 1;
|
const GLOBAL_REMOVE: u32 = 1;
|
||||||
|
|
||||||
|
id!(WlRegistryId);
|
||||||
|
|
||||||
pub struct WlRegistry {
|
pub struct WlRegistry {
|
||||||
id: ObjectId,
|
id: WlRegistryId,
|
||||||
client: Rc<Client>,
|
client: Rc<Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WlRegistry {
|
impl WlRegistry {
|
||||||
pub fn new(id: ObjectId, client: &Rc<Client>) -> Self {
|
pub fn new(id: WlRegistryId, client: &Rc<Client>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
|
|
@ -78,7 +80,7 @@ handle_request!(WlRegistry);
|
||||||
|
|
||||||
impl Object for WlRegistry {
|
impl Object for WlRegistry {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
1
src/ifs/wl_seat/mod.rs
Normal file
1
src/ifs/wl_seat/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
id!(WlSeatId);
|
||||||
|
|
@ -12,13 +12,15 @@ const CREATE_POOL: u32 = 0;
|
||||||
|
|
||||||
const FORMAT: u32 = 0;
|
const FORMAT: u32 = 0;
|
||||||
|
|
||||||
|
id!(WlShmId);
|
||||||
|
|
||||||
pub struct WlShmGlobal {
|
pub struct WlShmGlobal {
|
||||||
name: GlobalName,
|
name: GlobalName,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WlShmObj {
|
pub struct WlShmObj {
|
||||||
global: Rc<WlShmGlobal>,
|
global: Rc<WlShmGlobal>,
|
||||||
id: ObjectId,
|
id: WlShmId,
|
||||||
client: Rc<Client>,
|
client: Rc<Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +31,7 @@ impl WlShmGlobal {
|
||||||
|
|
||||||
async fn bind_(
|
async fn bind_(
|
||||||
self: Rc<Self>,
|
self: Rc<Self>,
|
||||||
id: ObjectId,
|
id: WlShmId,
|
||||||
client: &Rc<Client>,
|
client: &Rc<Client>,
|
||||||
_version: u32,
|
_version: u32,
|
||||||
) -> Result<(), WlShmError> {
|
) -> Result<(), WlShmError> {
|
||||||
|
|
@ -104,7 +106,7 @@ handle_request!(WlShmObj);
|
||||||
|
|
||||||
impl Object for WlShmObj {
|
impl Object for WlShmObj {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||||
use crate::format::Format;
|
use crate::format::Format;
|
||||||
use crate::ifs::wl_shm::{WlShmObj, FORMAT};
|
use crate::ifs::wl_shm::{WlShmObj, FORMAT};
|
||||||
use crate::ifs::wl_shm_pool::WlShmPoolError;
|
use crate::ifs::wl_shm_pool::{WlShmPoolError, WlShmPoolId};
|
||||||
use crate::object::{Object, ObjectId};
|
use crate::object::Object;
|
||||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
@ -34,7 +34,7 @@ efrom!(CreatePoolError, WlShmPoolError, WlShmPoolError);
|
||||||
efrom!(CreatePoolError, ClientError, ClientError);
|
efrom!(CreatePoolError, ClientError, ClientError);
|
||||||
|
|
||||||
pub(super) struct CreatePool {
|
pub(super) struct CreatePool {
|
||||||
pub id: ObjectId,
|
pub id: WlShmPoolId,
|
||||||
pub fd: OwnedFd,
|
pub fd: OwnedFd,
|
||||||
pub size: i32,
|
pub size: i32,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ mod types;
|
||||||
|
|
||||||
use crate::client::{AddObj, Client};
|
use crate::client::{AddObj, Client};
|
||||||
use crate::clientmem::ClientMem;
|
use crate::clientmem::ClientMem;
|
||||||
|
use crate::ifs::wl_buffer::WlBuffer;
|
||||||
use crate::object::{Interface, Object, ObjectId};
|
use crate::object::{Interface, Object, ObjectId};
|
||||||
use crate::utils::buffd::MsgParser;
|
use crate::utils::buffd::MsgParser;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
@ -13,8 +14,10 @@ const CREATE_BUFFER: u32 = 0;
|
||||||
const DESTROY: u32 = 1;
|
const DESTROY: u32 = 1;
|
||||||
const RESIZE: u32 = 2;
|
const RESIZE: u32 = 2;
|
||||||
|
|
||||||
|
id!(WlShmPoolId);
|
||||||
|
|
||||||
pub struct WlShmPool {
|
pub struct WlShmPool {
|
||||||
id: ObjectId,
|
id: WlShmPoolId,
|
||||||
client: Rc<Client>,
|
client: Rc<Client>,
|
||||||
fd: OwnedFd,
|
fd: OwnedFd,
|
||||||
mem: RefCell<Rc<ClientMem>>,
|
mem: RefCell<Rc<ClientMem>>,
|
||||||
|
|
@ -22,7 +25,7 @@ pub struct WlShmPool {
|
||||||
|
|
||||||
impl WlShmPool {
|
impl WlShmPool {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
id: ObjectId,
|
id: WlShmPoolId,
|
||||||
client: &Rc<Client>,
|
client: &Rc<Client>,
|
||||||
fd: OwnedFd,
|
fd: OwnedFd,
|
||||||
len: usize,
|
len: usize,
|
||||||
|
|
@ -37,6 +40,25 @@ impl WlShmPool {
|
||||||
|
|
||||||
async fn create_buffer(&self, parser: MsgParser<'_, '_>) -> Result<(), CreateBufferError> {
|
async fn create_buffer(&self, parser: MsgParser<'_, '_>) -> Result<(), CreateBufferError> {
|
||||||
let req: CreateBuffer = self.client.parse(self, parser)?;
|
let req: CreateBuffer = self.client.parse(self, parser)?;
|
||||||
|
let format = match self.client.state.formats.get(&req.format) {
|
||||||
|
Some(f) => *f,
|
||||||
|
_ => return Err(CreateBufferError::InvalidFormat(req.format)),
|
||||||
|
};
|
||||||
|
if req.height < 0 || req.width < 0 || req.stride < 0 || req.offset < 0 {
|
||||||
|
return Err(CreateBufferError::NegativeParameters);
|
||||||
|
}
|
||||||
|
let mem = self.mem.borrow();
|
||||||
|
let buffer = Rc::new(WlBuffer::new(
|
||||||
|
req.id,
|
||||||
|
&self.client,
|
||||||
|
req.offset as usize,
|
||||||
|
req.width as u32,
|
||||||
|
req.height as u32,
|
||||||
|
req.stride as u32,
|
||||||
|
format,
|
||||||
|
&mem,
|
||||||
|
)?);
|
||||||
|
self.client.add_client_obj(&buffer)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +100,7 @@ handle_request!(WlShmPool);
|
||||||
|
|
||||||
impl Object for WlShmPool {
|
impl Object for WlShmPool {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::client::{ClientError, RequestParser};
|
use crate::client::{ClientError, RequestParser};
|
||||||
use crate::clientmem::ClientMemError;
|
use crate::clientmem::ClientMemError;
|
||||||
use crate::object::ObjectId;
|
use crate::ifs::wl_buffer::{WlBufferError, WlBufferId};
|
||||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
@ -27,9 +27,16 @@ pub enum CreateBufferError {
|
||||||
ParseError(#[source] Box<MsgParserError>),
|
ParseError(#[source] Box<MsgParserError>),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ClientError(Box<ClientError>),
|
ClientError(Box<ClientError>),
|
||||||
|
#[error("Format {0} is not supported")]
|
||||||
|
InvalidFormat(u32),
|
||||||
|
#[error("All parameters in a create_buffer request must be non-negative")]
|
||||||
|
NegativeParameters,
|
||||||
|
#[error(transparent)]
|
||||||
|
WlBufferError(Box<WlBufferError>),
|
||||||
}
|
}
|
||||||
efrom!(CreateBufferError, ParseError, MsgParserError);
|
efrom!(CreateBufferError, ParseError, MsgParserError);
|
||||||
efrom!(CreateBufferError, ClientError, ClientError);
|
efrom!(CreateBufferError, ClientError, ClientError);
|
||||||
|
efrom!(CreateBufferError, WlBufferError, WlBufferError);
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum DestroyError {
|
pub enum DestroyError {
|
||||||
|
|
@ -56,7 +63,7 @@ efrom!(ResizeError, ParseError, MsgParserError);
|
||||||
efrom!(ResizeError, ClientMemError, ClientMemError);
|
efrom!(ResizeError, ClientMemError, ClientMemError);
|
||||||
|
|
||||||
pub(super) struct CreateBuffer {
|
pub(super) struct CreateBuffer {
|
||||||
pub id: ObjectId,
|
pub id: WlBufferId,
|
||||||
pub offset: i32,
|
pub offset: i32,
|
||||||
pub width: i32,
|
pub width: i32,
|
||||||
pub height: i32,
|
pub height: i32,
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,15 @@ const GET_SUBSURFACE: u32 = 1;
|
||||||
|
|
||||||
const BAD_SURFACE: u32 = 0;
|
const BAD_SURFACE: u32 = 0;
|
||||||
|
|
||||||
|
id!(WlSubcompositorId);
|
||||||
|
|
||||||
pub struct WlSubcompositorGlobal {
|
pub struct WlSubcompositorGlobal {
|
||||||
name: GlobalName,
|
name: GlobalName,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WlSubcompositorObj {
|
pub struct WlSubcompositorObj {
|
||||||
global: Rc<WlSubcompositorGlobal>,
|
global: Rc<WlSubcompositorGlobal>,
|
||||||
id: ObjectId,
|
id: WlSubcompositorId,
|
||||||
client: Rc<Client>,
|
client: Rc<Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +32,7 @@ impl WlSubcompositorGlobal {
|
||||||
|
|
||||||
async fn bind_(
|
async fn bind_(
|
||||||
self: Rc<Self>,
|
self: Rc<Self>,
|
||||||
id: ObjectId,
|
id: WlSubcompositorId,
|
||||||
client: &Rc<Client>,
|
client: &Rc<Client>,
|
||||||
_version: u32,
|
_version: u32,
|
||||||
) -> Result<(), WlSubcompositorError> {
|
) -> Result<(), WlSubcompositorError> {
|
||||||
|
|
@ -99,7 +101,7 @@ handle_request!(WlSubcompositorObj);
|
||||||
|
|
||||||
impl Object for WlSubcompositorObj {
|
impl Object for WlSubcompositorObj {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::client::{ClientError, RequestParser};
|
use crate::client::{ClientError, RequestParser};
|
||||||
use crate::ifs::wl_surface::wl_subsurface::WlSubsurfaceError;
|
use crate::ifs::wl_surface::wl_subsurface::{WlSubsurfaceError, WlSubsurfaceId};
|
||||||
use crate::object::ObjectId;
|
use crate::ifs::wl_surface::WlSurfaceId;
|
||||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
@ -52,9 +52,9 @@ impl Debug for Destroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct GetSubsurface {
|
pub(super) struct GetSubsurface {
|
||||||
pub id: ObjectId,
|
pub id: WlSubsurfaceId,
|
||||||
pub surface: ObjectId,
|
pub surface: WlSurfaceId,
|
||||||
pub parent: ObjectId,
|
pub parent: WlSurfaceId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for GetSubsurface {
|
impl RequestParser<'_> for GetSubsurface {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,18 @@ pub mod xdg_surface;
|
||||||
|
|
||||||
use crate::client::{AddObj, Client, RequestParser};
|
use crate::client::{AddObj, Client, RequestParser};
|
||||||
use crate::ifs::wl_surface::wl_subsurface::WlSubsurface;
|
use crate::ifs::wl_surface::wl_subsurface::WlSubsurface;
|
||||||
|
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopup;
|
||||||
|
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel;
|
||||||
|
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
||||||
use crate::object::{Interface, Object, ObjectId};
|
use crate::object::{Interface, Object, ObjectId};
|
||||||
use crate::pixman::Region;
|
use crate::pixman::Region;
|
||||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||||
|
use crate::utils::copyhashmap::CopyHashMap;
|
||||||
use crate::utils::linkedlist::{LinkedList, Node};
|
use crate::utils::linkedlist::{LinkedList, Node};
|
||||||
use ahash::AHashMap;
|
use ahash::AHashMap;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
pub use types::*;
|
pub use types::*;
|
||||||
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
|
||||||
|
|
||||||
const DESTROY: u32 = 0;
|
const DESTROY: u32 = 0;
|
||||||
const ATTACH: u32 = 1;
|
const ATTACH: u32 = 1;
|
||||||
|
|
@ -32,6 +35,8 @@ const INVALID_SCALE: u32 = 0;
|
||||||
const INVALID_TRANSFORM: u32 = 1;
|
const INVALID_TRANSFORM: u32 = 1;
|
||||||
const INVALID_SIZE: u32 = 2;
|
const INVALID_SIZE: u32 = 2;
|
||||||
|
|
||||||
|
id!(WlSurfaceId);
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum SurfaceRole {
|
pub enum SurfaceRole {
|
||||||
None,
|
None,
|
||||||
|
|
@ -50,7 +55,7 @@ impl SurfaceRole {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WlSurface {
|
pub struct WlSurface {
|
||||||
id: ObjectId,
|
id: WlSurfaceId,
|
||||||
client: Rc<Client>,
|
client: Rc<Client>,
|
||||||
role: Cell<SurfaceRole>,
|
role: Cell<SurfaceRole>,
|
||||||
pending: PendingState,
|
pending: PendingState,
|
||||||
|
|
@ -78,21 +83,44 @@ struct PendingState {
|
||||||
|
|
||||||
struct XdgSurfaceData {
|
struct XdgSurfaceData {
|
||||||
xdg_surface: Rc<XdgSurface>,
|
xdg_surface: Rc<XdgSurface>,
|
||||||
|
committed: bool,
|
||||||
role: XdgSurfaceRole,
|
role: XdgSurfaceRole,
|
||||||
|
role_data: XdgSurfaceRoleData,
|
||||||
|
popups: CopyHashMap<WlSurfaceId, Rc<XdgPopup>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
enum XdgSurfaceRole {
|
enum XdgSurfaceRole {
|
||||||
|
None,
|
||||||
|
Popup,
|
||||||
|
Toplevel,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl XdgSurfaceRole {
|
||||||
|
fn is_compatible(self, role: XdgSurfaceRole) -> bool {
|
||||||
|
self == XdgSurfaceRole::None || self == role
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum XdgSurfaceRoleData {
|
||||||
None,
|
None,
|
||||||
Popup(XdgPopupData),
|
Popup(XdgPopupData),
|
||||||
Toplevel(XdgToplevelData),
|
Toplevel(XdgToplevelData),
|
||||||
}
|
}
|
||||||
|
|
||||||
struct XdgPopupData {
|
impl XdgSurfaceRoleData {
|
||||||
|
fn is_some(&self) -> bool {
|
||||||
|
!matches!(self, XdgSurfaceRoleData::None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct XdgPopupData {
|
||||||
|
popup: Rc<XdgPopup>,
|
||||||
|
parent: Option<Rc<XdgSurface>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct XdgToplevelData {
|
struct XdgToplevelData {
|
||||||
|
toplevel: Rc<XdgToplevel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SubsurfaceData {
|
struct SubsurfaceData {
|
||||||
|
|
@ -114,7 +142,7 @@ struct PendingSubsurfaceData {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ParentData {
|
struct ParentData {
|
||||||
subsurfaces: AHashMap<ObjectId, Rc<WlSurface>>,
|
subsurfaces: AHashMap<WlSurfaceId, Rc<WlSurface>>,
|
||||||
below: LinkedList<StackElement>,
|
below: LinkedList<StackElement>,
|
||||||
above: LinkedList<StackElement>,
|
above: LinkedList<StackElement>,
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +153,7 @@ struct StackElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WlSurface {
|
impl WlSurface {
|
||||||
pub fn new(id: ObjectId, client: &Rc<Client>) -> Self {
|
pub fn new(id: WlSurfaceId, client: &Rc<Client>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
|
|
@ -136,11 +164,6 @@ impl WlSurface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn break_loops(&self) {
|
|
||||||
*self.children.borrow_mut() = None;
|
|
||||||
*self.role_data.borrow_mut() = RoleData::None;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_root(self: &Rc<Self>) -> Rc<WlSurface> {
|
pub fn get_root(self: &Rc<Self>) -> Rc<WlSurface> {
|
||||||
let mut root = self.clone();
|
let mut root = self.clone();
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -165,8 +188,47 @@ impl WlSurface {
|
||||||
|
|
||||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||||
let _req: Destroy = self.parse(parser)?;
|
let _req: Destroy = self.parse(parser)?;
|
||||||
*self.children.borrow_mut() = None;
|
{
|
||||||
*self.role_data.borrow_mut() = RoleData::None;
|
let mut children = self.children.borrow_mut();
|
||||||
|
if let Some(children) = &mut *children {
|
||||||
|
for surface in children.subsurfaces.values() {
|
||||||
|
*surface.role_data.borrow_mut() = RoleData::None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*children = None;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mut data = self.role_data.borrow_mut();
|
||||||
|
match &mut *data {
|
||||||
|
RoleData::None => {}
|
||||||
|
RoleData::Subsurface(ss) => {
|
||||||
|
let mut children = ss.subsurface.parent.children.borrow_mut();
|
||||||
|
if let Some(children) = &mut *children {
|
||||||
|
children.subsurfaces.remove(&self.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RoleData::XdgSurface(xdg) => {
|
||||||
|
let children = xdg.popups.lock();
|
||||||
|
for child in children.values() {
|
||||||
|
let mut rd = child.surface.surface.role_data.borrow_mut();
|
||||||
|
if let RoleData::XdgSurface(xdg) = &mut *rd {
|
||||||
|
if let XdgSurfaceRoleData::Popup(p) = &mut xdg.role_data {
|
||||||
|
p.parent = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let XdgSurfaceRoleData::Popup(p) = &mut xdg.role_data {
|
||||||
|
if let Some(p) = &p.parent {
|
||||||
|
let mut rd = p.surface.role_data.borrow_mut();
|
||||||
|
if let RoleData::XdgSurface(xdg) = &mut *rd {
|
||||||
|
xdg.popups.remove(&self.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*data = RoleData::None;
|
||||||
|
}
|
||||||
self.client.remove_obj(self).await?;
|
self.client.remove_obj(self).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -252,7 +314,7 @@ handle_request!(WlSurface);
|
||||||
|
|
||||||
impl Object for WlSurface {
|
impl Object for WlSurface {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
@ -262,4 +324,9 @@ impl Object for WlSurface {
|
||||||
fn num_requests(&self) -> u32 {
|
fn num_requests(&self) -> u32 {
|
||||||
DAMAGE_BUFFER + 1
|
DAMAGE_BUFFER + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn break_loops(&self) {
|
||||||
|
*self.children.borrow_mut() = None;
|
||||||
|
*self.role_data.borrow_mut() = RoleData::None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::client::{ClientError, RequestParser};
|
use crate::client::{ClientError, RequestParser};
|
||||||
use crate::object::ObjectId;
|
use crate::ifs::wl_callback::WlCallbackId;
|
||||||
|
use crate::ifs::wl_region::WlRegionId;
|
||||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
@ -134,7 +135,7 @@ impl Debug for Destroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct Attach {
|
pub(super) struct Attach {
|
||||||
pub buffer: ObjectId,
|
pub buffer: crate::ifs::wl_buffer::WlBufferId,
|
||||||
pub x: i32,
|
pub x: i32,
|
||||||
pub y: i32,
|
pub y: i32,
|
||||||
}
|
}
|
||||||
|
|
@ -184,7 +185,7 @@ impl Debug for Damage {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct Frame {
|
pub(super) struct Frame {
|
||||||
pub callback: ObjectId,
|
pub callback: WlCallbackId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for Frame {
|
impl RequestParser<'_> for Frame {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
@ -200,7 +201,7 @@ impl Debug for Frame {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct SetOpaqueRegion {
|
pub(super) struct SetOpaqueRegion {
|
||||||
pub region: ObjectId,
|
pub region: WlRegionId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for SetOpaqueRegion {
|
impl RequestParser<'_> for SetOpaqueRegion {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
@ -216,7 +217,7 @@ impl Debug for SetOpaqueRegion {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct SetInputRegion {
|
pub(super) struct SetInputRegion {
|
||||||
pub region: ObjectId,
|
pub region: WlRegionId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for SetInputRegion {
|
impl RequestParser<'_> for SetInputRegion {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
mod types;
|
mod types;
|
||||||
|
|
||||||
use crate::client::AddObj;
|
use crate::client::AddObj;
|
||||||
use crate::ifs::wl_surface::{RoleData, StackElement, SubsurfaceData, SurfaceRole, WlSurface};
|
use crate::ifs::wl_surface::{
|
||||||
|
RoleData, StackElement, SubsurfaceData, SurfaceRole, WlSurface, WlSurfaceId,
|
||||||
|
};
|
||||||
use crate::object::{Interface, Object, ObjectId};
|
use crate::object::{Interface, Object, ObjectId};
|
||||||
use crate::utils::buffd::MsgParser;
|
use crate::utils::buffd::MsgParser;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
@ -19,8 +21,10 @@ const BAD_SURFACE: u32 = 0;
|
||||||
|
|
||||||
const MAX_SUBSURFACE_DEPTH: u32 = 100;
|
const MAX_SUBSURFACE_DEPTH: u32 = 100;
|
||||||
|
|
||||||
|
id!(WlSubsurfaceId);
|
||||||
|
|
||||||
pub struct WlSubsurface {
|
pub struct WlSubsurface {
|
||||||
id: ObjectId,
|
id: WlSubsurfaceId,
|
||||||
surface: Rc<WlSurface>,
|
surface: Rc<WlSurface>,
|
||||||
pub(super) parent: Rc<WlSurface>,
|
pub(super) parent: Rc<WlSurface>,
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +71,7 @@ fn update_children_attach(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WlSubsurface {
|
impl WlSubsurface {
|
||||||
pub fn new(id: ObjectId, surface: &Rc<WlSurface>, parent: &Rc<WlSurface>) -> Self {
|
pub fn new(id: WlSubsurfaceId, surface: &Rc<WlSurface>, parent: &Rc<WlSurface>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
surface: surface.clone(),
|
surface: surface.clone(),
|
||||||
|
|
@ -150,7 +154,7 @@ impl WlSubsurface {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn place(&self, sibling: ObjectId, above: bool) -> Result<(), PlacementError> {
|
fn place(&self, sibling: WlSurfaceId, above: bool) -> Result<(), PlacementError> {
|
||||||
if sibling == self.surface.id {
|
if sibling == self.surface.id {
|
||||||
return Err(PlacementError::AboveSelf(sibling));
|
return Err(PlacementError::AboveSelf(sibling));
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +251,7 @@ handle_request!(WlSubsurface);
|
||||||
|
|
||||||
impl Object for WlSubsurface {
|
impl Object for WlSubsurface {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::client::{ClientError, RequestParser};
|
use crate::client::{ClientError, RequestParser};
|
||||||
use crate::ifs::wl_surface::SurfaceRole;
|
use crate::ifs::wl_surface::{SurfaceRole, WlSurfaceId};
|
||||||
use crate::object::ObjectId;
|
|
||||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
@ -20,13 +19,13 @@ pub enum WlSubsurfaceError {
|
||||||
#[error("Could not process `set_desync` request")]
|
#[error("Could not process `set_desync` request")]
|
||||||
SetDesync(#[from] SetDesyncError),
|
SetDesync(#[from] SetDesyncError),
|
||||||
#[error("Surface {0} cannot be assigned the role `Subsurface` because it already has the role `{1:?}`")]
|
#[error("Surface {0} cannot be assigned the role `Subsurface` because it already has the role `{1:?}`")]
|
||||||
IncompatibleType(ObjectId, SurfaceRole),
|
IncompatibleType(WlSurfaceId, SurfaceRole),
|
||||||
#[error("Surface {0} already has an attached `wl_subsurface`")]
|
#[error("Surface {0} already has an attached `wl_subsurface`")]
|
||||||
AlreadyAttached(ObjectId),
|
AlreadyAttached(WlSurfaceId),
|
||||||
#[error("Surface {0} cannot be made its own parent")]
|
#[error("Surface {0} cannot be made its own parent")]
|
||||||
OwnParent(ObjectId),
|
OwnParent(WlSurfaceId),
|
||||||
#[error("Surface {0} cannot be made a subsurface of {1} because it's an ancestor of {1}")]
|
#[error("Surface {0} cannot be made a subsurface of {1} because it's an ancestor of {1}")]
|
||||||
Ancestor(ObjectId, ObjectId),
|
Ancestor(WlSurfaceId, WlSurfaceId),
|
||||||
#[error("Subsurfaces cannot be nested deeper than 100 levels")]
|
#[error("Subsurfaces cannot be nested deeper than 100 levels")]
|
||||||
MaxDepthExceeded,
|
MaxDepthExceeded,
|
||||||
}
|
}
|
||||||
|
|
@ -60,9 +59,9 @@ efrom!(PlaceAboveError, ParseFailed, MsgParserError);
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum PlacementError {
|
pub enum PlacementError {
|
||||||
#[error("Cannot place {0} above/below itself")]
|
#[error("Cannot place {0} above/below itself")]
|
||||||
AboveSelf(ObjectId),
|
AboveSelf(WlSurfaceId),
|
||||||
#[error("{0} is not a sibling of {1}")]
|
#[error("{0} is not a sibling of {1}")]
|
||||||
NotASibling(ObjectId, ObjectId),
|
NotASibling(WlSurfaceId, WlSurfaceId),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
|
@ -88,7 +87,7 @@ pub enum SetDesyncError {
|
||||||
}
|
}
|
||||||
efrom!(SetDesyncError, ParseFailed, MsgParserError);
|
efrom!(SetDesyncError, ParseFailed, MsgParserError);
|
||||||
|
|
||||||
pub(in crate::ifs) struct Destroy;
|
pub(super) struct Destroy;
|
||||||
impl RequestParser<'_> for Destroy {
|
impl RequestParser<'_> for Destroy {
|
||||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
Ok(Self)
|
Ok(Self)
|
||||||
|
|
@ -100,7 +99,7 @@ impl Debug for Destroy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(in crate::ifs) struct SetPosition {
|
pub(super) struct SetPosition {
|
||||||
pub x: i32,
|
pub x: i32,
|
||||||
pub y: i32,
|
pub y: i32,
|
||||||
}
|
}
|
||||||
|
|
@ -118,8 +117,8 @@ impl Debug for SetPosition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(in crate::ifs) struct PlaceAbove {
|
pub(super) struct PlaceAbove {
|
||||||
pub sibling: ObjectId,
|
pub sibling: WlSurfaceId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for PlaceAbove {
|
impl RequestParser<'_> for PlaceAbove {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
@ -134,8 +133,8 @@ impl Debug for PlaceAbove {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(in crate::ifs) struct PlaceBelow {
|
pub(super) struct PlaceBelow {
|
||||||
pub sibling: ObjectId,
|
pub sibling: WlSurfaceId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for PlaceBelow {
|
impl RequestParser<'_> for PlaceBelow {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
@ -150,7 +149,7 @@ impl Debug for PlaceBelow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(in crate::ifs) struct SetSync;
|
pub(super) struct SetSync;
|
||||||
impl RequestParser<'_> for SetSync {
|
impl RequestParser<'_> for SetSync {
|
||||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
Ok(Self)
|
Ok(Self)
|
||||||
|
|
@ -162,7 +161,7 @@ impl Debug for SetSync {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(in crate::ifs) struct SetDesync;
|
pub(super) struct SetDesync;
|
||||||
impl RequestParser<'_> for SetDesync {
|
impl RequestParser<'_> for SetDesync {
|
||||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
Ok(Self)
|
Ok(Self)
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,18 @@ mod types;
|
||||||
pub mod xdg_popup;
|
pub mod xdg_popup;
|
||||||
pub mod xdg_toplevel;
|
pub mod xdg_toplevel;
|
||||||
|
|
||||||
use crate::ifs::wl_surface::{RoleData, SurfaceRole, WlSurface, XdgSurfaceData};
|
use crate::client::AddObj;
|
||||||
|
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopup;
|
||||||
|
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel;
|
||||||
|
use crate::ifs::wl_surface::{
|
||||||
|
RoleData, SurfaceRole, WlSurface, XdgPopupData, XdgSurfaceData, XdgSurfaceRole,
|
||||||
|
XdgSurfaceRoleData, XdgToplevelData,
|
||||||
|
};
|
||||||
|
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
|
||||||
use crate::object::{Interface, Object, ObjectId};
|
use crate::object::{Interface, Object, ObjectId};
|
||||||
use crate::utils::buffd::MsgParser;
|
use crate::utils::buffd::MsgParser;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
pub use types::*;
|
pub use types::*;
|
||||||
use crate::client::AddObj;
|
|
||||||
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
|
|
||||||
|
|
||||||
const DESTROY: u32 = 0;
|
const DESTROY: u32 = 0;
|
||||||
const GET_TOPLEVEL: u32 = 1;
|
const GET_TOPLEVEL: u32 = 1;
|
||||||
|
|
@ -22,15 +27,22 @@ const NOT_CONSTRUCTED: u32 = 1;
|
||||||
const ALREADY_CONSTRUCTED: u32 = 2;
|
const ALREADY_CONSTRUCTED: u32 = 2;
|
||||||
const UNCONFIGURED_BUFFER: u32 = 3;
|
const UNCONFIGURED_BUFFER: u32 = 3;
|
||||||
|
|
||||||
|
id!(XdgSurfaceId);
|
||||||
|
|
||||||
pub struct XdgSurface {
|
pub struct XdgSurface {
|
||||||
id: ObjectId,
|
id: XdgSurfaceId,
|
||||||
wm_base: Rc<XdgWmBaseObj>,
|
wm_base: Rc<XdgWmBaseObj>,
|
||||||
surface: Rc<WlSurface>,
|
pub(super) surface: Rc<WlSurface>,
|
||||||
version: u32,
|
version: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XdgSurface {
|
impl XdgSurface {
|
||||||
pub fn new(wm_base: &Rc<XdgWmBaseObj>, id: ObjectId, surface: &Rc<WlSurface>, version: u32) -> Self {
|
pub fn new(
|
||||||
|
wm_base: &Rc<XdgWmBaseObj>,
|
||||||
|
id: XdgSurfaceId,
|
||||||
|
surface: &Rc<WlSurface>,
|
||||||
|
version: u32,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
wm_base: wm_base.clone(),
|
wm_base: wm_base.clone(),
|
||||||
|
|
@ -50,25 +62,101 @@ impl XdgSurface {
|
||||||
}
|
}
|
||||||
*data = RoleData::XdgSurface(Box::new(XdgSurfaceData {
|
*data = RoleData::XdgSurface(Box::new(XdgSurfaceData {
|
||||||
xdg_surface: self.clone(),
|
xdg_surface: self.clone(),
|
||||||
|
committed: false,
|
||||||
|
role: XdgSurfaceRole::None,
|
||||||
|
role_data: XdgSurfaceRoleData::None,
|
||||||
|
popups: Default::default(),
|
||||||
}));
|
}));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||||
let _req: Destroy = self.surface.client.parse(self, parser)?;
|
let _req: Destroy = self.surface.client.parse(self, parser)?;
|
||||||
*self.surface.role_data.borrow_mut() = RoleData::None;
|
{
|
||||||
|
let mut data = self.surface.role_data.borrow_mut();
|
||||||
|
if let RoleData::XdgSurface(rd) = &*data {
|
||||||
|
if rd.role_data.is_some() {
|
||||||
|
return Err(DestroyError::RoleNotYetDestroyed(self.id));
|
||||||
|
}
|
||||||
|
let children = rd.popups.lock();
|
||||||
|
for child in children.values() {
|
||||||
|
let mut data = child.surface.surface.role_data.borrow_mut();
|
||||||
|
if let RoleData::XdgSurface(xdg) = &mut *data {
|
||||||
|
if let XdgSurfaceRoleData::Popup(p) = &mut xdg.role_data {
|
||||||
|
p.parent = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*data = RoleData::None;
|
||||||
|
}
|
||||||
self.wm_base.surfaces.remove(&self.id);
|
self.wm_base.surfaces.remove(&self.id);
|
||||||
self.surface.client.remove_obj(self).await?;
|
self.surface.client.remove_obj(self).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_toplevel(&self, parser: MsgParser<'_, '_>) -> Result<(), GetToplevelError> {
|
async fn get_toplevel(
|
||||||
let _req: GetToplevel = self.surface.client.parse(self, parser)?;
|
self: &Rc<Self>,
|
||||||
|
parser: MsgParser<'_, '_>,
|
||||||
|
) -> Result<(), GetToplevelError> {
|
||||||
|
let req: GetToplevel = self.surface.client.parse(&**self, parser)?;
|
||||||
|
let mut data = self.surface.role_data.borrow_mut();
|
||||||
|
if let RoleData::XdgSurface(data) = &mut *data {
|
||||||
|
if !data.role.is_compatible(XdgSurfaceRole::Toplevel) {
|
||||||
|
return Err(GetToplevelError::IncompatibleRole);
|
||||||
|
}
|
||||||
|
if data.role_data.is_some() {
|
||||||
|
self.surface.client.protocol_error(
|
||||||
|
&**self,
|
||||||
|
ALREADY_CONSTRUCTED,
|
||||||
|
format!(
|
||||||
|
"wl_surface {} already has an assigned xdg_toplevel",
|
||||||
|
self.surface.id
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return Err(GetToplevelError::AlreadyConstructed);
|
||||||
|
}
|
||||||
|
data.role = XdgSurfaceRole::Toplevel;
|
||||||
|
let toplevel = Rc::new(XdgToplevel::new(req.id, self, self.version));
|
||||||
|
self.surface.client.add_client_obj(&toplevel)?;
|
||||||
|
data.role_data = XdgSurfaceRoleData::Toplevel(XdgToplevelData { toplevel });
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_popup(&self, parser: MsgParser<'_, '_>) -> Result<(), GetPopupError> {
|
async fn get_popup(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetPopupError> {
|
||||||
let _req: GetPopup = self.surface.client.parse(self, parser)?;
|
let req: GetPopup = self.surface.client.parse(&**self, parser)?;
|
||||||
|
let mut data = self.surface.role_data.borrow_mut();
|
||||||
|
if let RoleData::XdgSurface(data) = &mut *data {
|
||||||
|
let mut parent = None;
|
||||||
|
if req.parent.is_some() {
|
||||||
|
parent = Some(self.surface.client.get_xdg_surface(req.parent)?);
|
||||||
|
}
|
||||||
|
if !data.role.is_compatible(XdgSurfaceRole::Popup) {
|
||||||
|
return Err(GetPopupError::IncompatibleRole);
|
||||||
|
}
|
||||||
|
if data.role_data.is_some() {
|
||||||
|
self.surface.client.protocol_error(
|
||||||
|
&**self,
|
||||||
|
ALREADY_CONSTRUCTED,
|
||||||
|
format!(
|
||||||
|
"wl_surface {} already has an assigned xdg_popup",
|
||||||
|
self.surface.id
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return Err(GetPopupError::AlreadyConstructed);
|
||||||
|
}
|
||||||
|
data.role = XdgSurfaceRole::Popup;
|
||||||
|
let popup = Rc::new(XdgPopup::new(req.id, self, self.version));
|
||||||
|
self.surface.client.add_client_obj(&popup)?;
|
||||||
|
if let Some(parent) = &parent {
|
||||||
|
let mut data = parent.surface.role_data.borrow_mut();
|
||||||
|
if let RoleData::XdgSurface(xdg) = &mut *data {
|
||||||
|
xdg.popups.set(self.surface.id, popup.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.role_data = XdgSurfaceRoleData::Popup(XdgPopupData { popup, parent });
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,7 +174,7 @@ impl XdgSurface {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_request_(
|
async fn handle_request_(
|
||||||
&self,
|
self: &Rc<Self>,
|
||||||
request: u32,
|
request: u32,
|
||||||
parser: MsgParser<'_, '_>,
|
parser: MsgParser<'_, '_>,
|
||||||
) -> Result<(), XdgSurfaceError> {
|
) -> Result<(), XdgSurfaceError> {
|
||||||
|
|
@ -106,7 +194,7 @@ handle_request!(XdgSurface);
|
||||||
|
|
||||||
impl Object for XdgSurface {
|
impl Object for XdgSurface {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, CONFIGURE};
|
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopupId;
|
||||||
use crate::object::{Object, ObjectId};
|
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevelId;
|
||||||
|
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId, CONFIGURE};
|
||||||
|
use crate::ifs::wl_surface::{SurfaceRole, WlSurfaceId};
|
||||||
|
use crate::ifs::xdg_positioner::XdgPositionerId;
|
||||||
|
use crate::object::Object;
|
||||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use crate::ifs::wl_surface::SurfaceRole;
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum XdgSurfaceError {
|
pub enum XdgSurfaceError {
|
||||||
|
|
@ -20,9 +23,9 @@ pub enum XdgSurfaceError {
|
||||||
#[error("Could not process `ack_configure` request")]
|
#[error("Could not process `ack_configure` request")]
|
||||||
AckConfigureError(#[from] AckConfigureError),
|
AckConfigureError(#[from] AckConfigureError),
|
||||||
#[error("Surface {0} cannot be turned into a xdg_surface because it already has the role {}", .1.name())]
|
#[error("Surface {0} cannot be turned into a xdg_surface because it already has the role {}", .1.name())]
|
||||||
IncompatibleRole(ObjectId, SurfaceRole),
|
IncompatibleRole(WlSurfaceId, SurfaceRole),
|
||||||
#[error("Surface {0} cannot be turned into a xdg_surface because it already has an attached xdg_surface")]
|
#[error("Surface {0} cannot be turned into a xdg_surface because it already has an attached xdg_surface")]
|
||||||
AlreadyAttached(ObjectId),
|
AlreadyAttached(WlSurfaceId),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
|
@ -31,6 +34,8 @@ pub enum DestroyError {
|
||||||
ParseFailed(#[source] Box<MsgParserError>),
|
ParseFailed(#[source] Box<MsgParserError>),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ClientError(Box<ClientError>),
|
ClientError(Box<ClientError>),
|
||||||
|
#[error("Cannot destroy xdg_surface {0} because it's associated xdg_toplevel/popup is not yet destroyed")]
|
||||||
|
RoleNotYetDestroyed(XdgSurfaceId),
|
||||||
}
|
}
|
||||||
efrom!(DestroyError, ParseFailed, MsgParserError);
|
efrom!(DestroyError, ParseFailed, MsgParserError);
|
||||||
efrom!(DestroyError, ClientError, ClientError);
|
efrom!(DestroyError, ClientError, ClientError);
|
||||||
|
|
@ -41,6 +46,10 @@ pub enum GetToplevelError {
|
||||||
ParseFailed(#[source] Box<MsgParserError>),
|
ParseFailed(#[source] Box<MsgParserError>),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ClientError(Box<ClientError>),
|
ClientError(Box<ClientError>),
|
||||||
|
#[error("The surface already has a different role")]
|
||||||
|
IncompatibleRole,
|
||||||
|
#[error("The surface already has an assigned xdg_toplevel")]
|
||||||
|
AlreadyConstructed,
|
||||||
}
|
}
|
||||||
efrom!(GetToplevelError, ParseFailed, MsgParserError);
|
efrom!(GetToplevelError, ParseFailed, MsgParserError);
|
||||||
efrom!(GetToplevelError, ClientError, ClientError);
|
efrom!(GetToplevelError, ClientError, ClientError);
|
||||||
|
|
@ -51,6 +60,10 @@ pub enum GetPopupError {
|
||||||
ParseFailed(#[source] Box<MsgParserError>),
|
ParseFailed(#[source] Box<MsgParserError>),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ClientError(Box<ClientError>),
|
ClientError(Box<ClientError>),
|
||||||
|
#[error("The surface already has a different role")]
|
||||||
|
IncompatibleRole,
|
||||||
|
#[error("The surface already has an assigned xdg_popup")]
|
||||||
|
AlreadyConstructed,
|
||||||
}
|
}
|
||||||
efrom!(GetPopupError, ParseFailed, MsgParserError);
|
efrom!(GetPopupError, ParseFailed, MsgParserError);
|
||||||
efrom!(GetPopupError, ClientError, ClientError);
|
efrom!(GetPopupError, ClientError, ClientError);
|
||||||
|
|
@ -88,7 +101,7 @@ impl Debug for Destroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct GetToplevel {
|
pub(super) struct GetToplevel {
|
||||||
pub id: ObjectId,
|
pub id: XdgToplevelId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for GetToplevel {
|
impl RequestParser<'_> for GetToplevel {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
@ -104,9 +117,9 @@ impl Debug for GetToplevel {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct GetPopup {
|
pub(super) struct GetPopup {
|
||||||
pub id: ObjectId,
|
pub id: XdgPopupId,
|
||||||
pub parent: ObjectId,
|
pub parent: XdgSurfaceId,
|
||||||
pub positioner: ObjectId,
|
pub positioner: XdgPositionerId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for GetPopup {
|
impl RequestParser<'_> for GetPopup {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
mod types;
|
mod types;
|
||||||
|
|
||||||
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
||||||
|
use crate::ifs::wl_surface::{RoleData, XdgSurfaceRoleData};
|
||||||
use crate::object::{Interface, Object, ObjectId};
|
use crate::object::{Interface, Object, ObjectId};
|
||||||
use crate::utils::buffd::MsgParser;
|
use crate::utils::buffd::MsgParser;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
@ -16,14 +17,16 @@ const REPOSITIONED: u32 = 2;
|
||||||
|
|
||||||
const INVALID_GRAB: u32 = 1;
|
const INVALID_GRAB: u32 = 1;
|
||||||
|
|
||||||
|
id!(XdgPopupId);
|
||||||
|
|
||||||
pub struct XdgPopup {
|
pub struct XdgPopup {
|
||||||
id: ObjectId,
|
id: XdgPopupId,
|
||||||
surface: Rc<XdgSurface>,
|
pub(in super::super) surface: Rc<XdgSurface>,
|
||||||
version: u32,
|
version: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XdgPopup {
|
impl XdgPopup {
|
||||||
pub fn new(id: ObjectId, surface: &Rc<XdgSurface>, version: u32) -> Self {
|
pub fn new(id: XdgPopupId, surface: &Rc<XdgSurface>, version: u32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
surface: surface.clone(),
|
surface: surface.clone(),
|
||||||
|
|
@ -33,6 +36,20 @@ impl XdgPopup {
|
||||||
|
|
||||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||||
let _req: Destroy = self.surface.surface.client.parse(self, parser)?;
|
let _req: Destroy = self.surface.surface.client.parse(self, parser)?;
|
||||||
|
{
|
||||||
|
let mut rd = self.surface.surface.role_data.borrow_mut();
|
||||||
|
if let RoleData::XdgSurface(xdg) = &mut *rd {
|
||||||
|
if let XdgSurfaceRoleData::Popup(p) = &xdg.role_data {
|
||||||
|
if let Some(p) = &p.parent {
|
||||||
|
let mut rd = p.surface.role_data.borrow_mut();
|
||||||
|
if let RoleData::XdgSurface(xdg) = &mut *rd {
|
||||||
|
xdg.popups.remove(&self.surface.surface.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xdg.role_data = XdgSurfaceRoleData::None;
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,7 +82,7 @@ handle_request!(XdgPopup);
|
||||||
|
|
||||||
impl Object for XdgPopup {
|
impl Object for XdgPopup {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||||
|
use crate::ifs::wl_seat::WlSeatId;
|
||||||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::{
|
use crate::ifs::wl_surface::xdg_surface::xdg_popup::{
|
||||||
XdgPopup, CONFIGURE, POPUP_DONE, REPOSITIONED,
|
XdgPopup, CONFIGURE, POPUP_DONE, REPOSITIONED,
|
||||||
};
|
};
|
||||||
use crate::object::{Object, ObjectId};
|
use crate::ifs::xdg_positioner::XdgPositionerId;
|
||||||
|
use crate::object::Object;
|
||||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
@ -61,7 +63,7 @@ impl Debug for Destroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct Grab {
|
pub(super) struct Grab {
|
||||||
pub seat: ObjectId,
|
pub seat: WlSeatId,
|
||||||
pub serial: u32,
|
pub serial: u32,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for Grab {
|
impl RequestParser<'_> for Grab {
|
||||||
|
|
@ -79,7 +81,7 @@ impl Debug for Grab {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct Reposition {
|
pub(super) struct Reposition {
|
||||||
pub positioner: ObjectId,
|
pub positioner: XdgPositionerId,
|
||||||
pub token: u32,
|
pub token: u32,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for Reposition {
|
impl RequestParser<'_> for Reposition {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
mod types;
|
mod types;
|
||||||
|
|
||||||
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
||||||
|
use crate::ifs::wl_surface::{RoleData, XdgSurfaceRoleData};
|
||||||
use crate::object::{Interface, Object, ObjectId};
|
use crate::object::{Interface, Object, ObjectId};
|
||||||
use crate::utils::buffd::MsgParser;
|
use crate::utils::buffd::MsgParser;
|
||||||
use num_derive::FromPrimitive;
|
use num_derive::FromPrimitive;
|
||||||
|
|
@ -47,14 +48,16 @@ const STATE_TILED_RIGHT: u32 = 6;
|
||||||
const STATE_TILED_TOP: u32 = 7;
|
const STATE_TILED_TOP: u32 = 7;
|
||||||
const STATE_TILED_BOTTOM: u32 = 8;
|
const STATE_TILED_BOTTOM: u32 = 8;
|
||||||
|
|
||||||
|
id!(XdgToplevelId);
|
||||||
|
|
||||||
pub struct XdgToplevel {
|
pub struct XdgToplevel {
|
||||||
id: ObjectId,
|
id: XdgToplevelId,
|
||||||
surface: Rc<XdgSurface>,
|
surface: Rc<XdgSurface>,
|
||||||
version: u32,
|
version: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XdgToplevel {
|
impl XdgToplevel {
|
||||||
pub fn new(id: ObjectId, surface: &Rc<XdgSurface>, version: u32) -> Self {
|
pub fn new(id: XdgToplevelId, surface: &Rc<XdgSurface>, version: u32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
surface: surface.clone(),
|
surface: surface.clone(),
|
||||||
|
|
@ -64,6 +67,12 @@ impl XdgToplevel {
|
||||||
|
|
||||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||||
let _req: Destroy = self.surface.surface.client.parse(self, parser)?;
|
let _req: Destroy = self.surface.surface.client.parse(self, parser)?;
|
||||||
|
{
|
||||||
|
let mut rd = self.surface.surface.role_data.borrow_mut();
|
||||||
|
if let RoleData::XdgSurface(rd) = &mut *rd {
|
||||||
|
rd.role_data = XdgSurfaceRoleData::None;
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,7 +174,7 @@ handle_request!(XdgToplevel);
|
||||||
|
|
||||||
impl Object for XdgToplevel {
|
impl Object for XdgToplevel {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
use super::CONFIGURE;
|
use super::CONFIGURE;
|
||||||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||||
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, CLOSE};
|
use crate::ifs::wl_seat::WlSeatId;
|
||||||
use crate::object::{Object, ObjectId};
|
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, XdgToplevelId, CLOSE};
|
||||||
|
use crate::object::Object;
|
||||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
@ -192,11 +193,13 @@ impl Debug for Destroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct SetParent {
|
pub(super) struct SetParent {
|
||||||
pub parent: ObjectId,
|
pub parent: XdgToplevelId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for SetParent {
|
impl RequestParser<'_> for SetParent {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
Ok(Self { parent: parser.object()? })
|
Ok(Self {
|
||||||
|
parent: parser.object()?,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Debug for SetParent {
|
impl Debug for SetParent {
|
||||||
|
|
@ -210,7 +213,9 @@ pub(super) struct SetTitle<'a> {
|
||||||
}
|
}
|
||||||
impl<'a> RequestParser<'a> for SetTitle<'a> {
|
impl<'a> RequestParser<'a> for SetTitle<'a> {
|
||||||
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
|
||||||
Ok(Self { title: parser.string()? })
|
Ok(Self {
|
||||||
|
title: parser.string()?,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> Debug for SetTitle<'a> {
|
impl<'a> Debug for SetTitle<'a> {
|
||||||
|
|
@ -224,7 +229,9 @@ pub(super) struct SetAppId<'a> {
|
||||||
}
|
}
|
||||||
impl<'a> RequestParser<'a> for SetAppId<'a> {
|
impl<'a> RequestParser<'a> for SetAppId<'a> {
|
||||||
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
|
||||||
Ok(Self { app_id: parser.string()? })
|
Ok(Self {
|
||||||
|
app_id: parser.string()?,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> Debug for SetAppId<'a> {
|
impl<'a> Debug for SetAppId<'a> {
|
||||||
|
|
@ -234,7 +241,7 @@ impl<'a> Debug for SetAppId<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct ShowWindowMenu {
|
pub(super) struct ShowWindowMenu {
|
||||||
pub seat: ObjectId,
|
pub seat: WlSeatId,
|
||||||
pub serial: u32,
|
pub serial: u32,
|
||||||
pub x: i32,
|
pub x: i32,
|
||||||
pub y: i32,
|
pub y: i32,
|
||||||
|
|
@ -251,17 +258,24 @@ impl RequestParser<'_> for ShowWindowMenu {
|
||||||
}
|
}
|
||||||
impl Debug for ShowWindowMenu {
|
impl Debug for ShowWindowMenu {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "show_window_menu(seat: {}, serial: {}, x: {}, y: {})", self.seat, self.serial, self.x, self.y)
|
write!(
|
||||||
|
f,
|
||||||
|
"show_window_menu(seat: {}, serial: {}, x: {}, y: {})",
|
||||||
|
self.seat, self.serial, self.x, self.y
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct Move {
|
pub(super) struct Move {
|
||||||
pub seat: ObjectId,
|
pub seat: WlSeatId,
|
||||||
pub serial: u32,
|
pub serial: u32,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for Move {
|
impl RequestParser<'_> for Move {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
Ok(Self { seat: parser.object()?, serial: parser.uint()? })
|
Ok(Self {
|
||||||
|
seat: parser.object()?,
|
||||||
|
serial: parser.uint()?,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Debug for Move {
|
impl Debug for Move {
|
||||||
|
|
@ -271,7 +285,7 @@ impl Debug for Move {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct Resize {
|
pub(super) struct Resize {
|
||||||
pub seat: ObjectId,
|
pub seat: WlSeatId,
|
||||||
pub serial: u32,
|
pub serial: u32,
|
||||||
pub edges: u32,
|
pub edges: u32,
|
||||||
}
|
}
|
||||||
|
|
@ -286,7 +300,11 @@ impl RequestParser<'_> for Resize {
|
||||||
}
|
}
|
||||||
impl Debug for Resize {
|
impl Debug for Resize {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "resize(seat: {}, serial: {}, edges: {})", self.seat, self.serial, self.edges)
|
write!(
|
||||||
|
f,
|
||||||
|
"resize(seat: {}, serial: {}, edges: {})",
|
||||||
|
self.seat, self.serial, self.edges
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -296,12 +314,19 @@ pub(super) struct SetMaxSize {
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for SetMaxSize {
|
impl RequestParser<'_> for SetMaxSize {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
Ok(Self { width: parser.int()?, height: parser.int()? })
|
Ok(Self {
|
||||||
|
width: parser.int()?,
|
||||||
|
height: parser.int()?,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Debug for SetMaxSize {
|
impl Debug for SetMaxSize {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "set_max_size(width: {}, height: {})", self.width, self.height)
|
write!(
|
||||||
|
f,
|
||||||
|
"set_max_size(width: {}, height: {})",
|
||||||
|
self.width, self.height
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,12 +336,19 @@ pub(super) struct SetMinSize {
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for SetMinSize {
|
impl RequestParser<'_> for SetMinSize {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
Ok(Self { width: parser.int()?, height: parser.int()? })
|
Ok(Self {
|
||||||
|
width: parser.int()?,
|
||||||
|
height: parser.int()?,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Debug for SetMinSize {
|
impl Debug for SetMinSize {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "set_min_size(width: {}, height: {})", self.width, self.height)
|
write!(
|
||||||
|
f,
|
||||||
|
"set_min_size(width: {}, height: {})",
|
||||||
|
self.width, self.height
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -345,11 +377,13 @@ impl Debug for UnsetMaximized {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct SetFullscreen {
|
pub(super) struct SetFullscreen {
|
||||||
pub output: ObjectId,
|
pub output: crate::ifs::wl_output::WlOutputId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for SetFullscreen {
|
impl RequestParser<'_> for SetFullscreen {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
Ok(Self { output: parser.object()? })
|
Ok(Self {
|
||||||
|
output: parser.object()?,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Debug for SetFullscreen {
|
impl Debug for SetFullscreen {
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,10 @@ bitflags! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id!(XdgPositionerId);
|
||||||
|
|
||||||
pub struct XdgPositioner {
|
pub struct XdgPositioner {
|
||||||
id: ObjectId,
|
id: XdgPositionerId,
|
||||||
client: Rc<Client>,
|
client: Rc<Client>,
|
||||||
version: u32,
|
version: u32,
|
||||||
position: RefCell<XdgPositioned>,
|
position: RefCell<XdgPositioned>,
|
||||||
|
|
@ -101,7 +103,7 @@ pub struct XdgPositioned {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XdgPositioner {
|
impl XdgPositioner {
|
||||||
pub fn new(id: ObjectId, client: &Rc<Client>, version: u32) -> Self {
|
pub fn new(id: XdgPositionerId, client: &Rc<Client>, version: u32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
|
|
@ -256,7 +258,7 @@ handle_request!(XdgPositioner);
|
||||||
|
|
||||||
impl Object for XdgPositioner {
|
impl Object for XdgPositioner {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ mod types;
|
||||||
|
|
||||||
use crate::client::{AddObj, Client};
|
use crate::client::{AddObj, Client};
|
||||||
use crate::globals::{Global, GlobalName};
|
use crate::globals::{Global, GlobalName};
|
||||||
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId};
|
||||||
use crate::ifs::xdg_positioner::XdgPositioner;
|
use crate::ifs::xdg_positioner::XdgPositioner;
|
||||||
use crate::object::{Interface, Object, ObjectId};
|
use crate::object::{Interface, Object, ObjectId};
|
||||||
use crate::utils::buffd::MsgParser;
|
use crate::utils::buffd::MsgParser;
|
||||||
|
|
@ -24,16 +24,18 @@ const INVALID_POPUP_PARENT: u32 = 3;
|
||||||
const INVALID_SURFACE_STATE: u32 = 4;
|
const INVALID_SURFACE_STATE: u32 = 4;
|
||||||
const INVALID_POSITIONER: u32 = 5;
|
const INVALID_POSITIONER: u32 = 5;
|
||||||
|
|
||||||
|
id!(XdgWmBaseId);
|
||||||
|
|
||||||
pub struct XdgWmBaseGlobal {
|
pub struct XdgWmBaseGlobal {
|
||||||
name: GlobalName,
|
name: GlobalName,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct XdgWmBaseObj {
|
pub struct XdgWmBaseObj {
|
||||||
global: Rc<XdgWmBaseGlobal>,
|
global: Rc<XdgWmBaseGlobal>,
|
||||||
id: ObjectId,
|
id: XdgWmBaseId,
|
||||||
client: Rc<Client>,
|
client: Rc<Client>,
|
||||||
version: u32,
|
version: u32,
|
||||||
pub(super) surfaces: CopyHashMap<ObjectId, Rc<XdgSurface>>,
|
pub(super) surfaces: CopyHashMap<XdgSurfaceId, Rc<XdgSurface>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XdgWmBaseGlobal {
|
impl XdgWmBaseGlobal {
|
||||||
|
|
@ -43,7 +45,7 @@ impl XdgWmBaseGlobal {
|
||||||
|
|
||||||
async fn bind_(
|
async fn bind_(
|
||||||
self: Rc<Self>,
|
self: Rc<Self>,
|
||||||
id: ObjectId,
|
id: XdgWmBaseId,
|
||||||
client: &Rc<Client>,
|
client: &Rc<Client>,
|
||||||
version: u32,
|
version: u32,
|
||||||
) -> Result<(), XdgWmBaseError> {
|
) -> Result<(), XdgWmBaseError> {
|
||||||
|
|
@ -60,10 +62,6 @@ impl XdgWmBaseGlobal {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XdgWmBaseObj {
|
impl XdgWmBaseObj {
|
||||||
pub fn break_loops(&self) {
|
|
||||||
self.surfaces.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||||
let _req: Destroy = self.client.parse(self, parser)?;
|
let _req: Destroy = self.client.parse(self, parser)?;
|
||||||
if !self.surfaces.is_empty() {
|
if !self.surfaces.is_empty() {
|
||||||
|
|
@ -91,7 +89,10 @@ impl XdgWmBaseObj {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_xdg_surface(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetXdgSurfaceError> {
|
async fn get_xdg_surface(
|
||||||
|
self: &Rc<Self>,
|
||||||
|
parser: MsgParser<'_, '_>,
|
||||||
|
) -> Result<(), GetXdgSurfaceError> {
|
||||||
let req: GetXdgSurface = self.client.parse(&**self, parser)?;
|
let req: GetXdgSurface = self.client.parse(&**self, parser)?;
|
||||||
let surface = self.client.get_surface(req.surface)?;
|
let surface = self.client.get_surface(req.surface)?;
|
||||||
let xdg_surface = Rc::new(XdgSurface::new(self, req.id, &surface, 3));
|
let xdg_surface = Rc::new(XdgSurface::new(self, req.id, &surface, 3));
|
||||||
|
|
@ -146,7 +147,7 @@ handle_request!(XdgWmBaseObj);
|
||||||
|
|
||||||
impl Object for XdgWmBaseObj {
|
impl Object for XdgWmBaseObj {
|
||||||
fn id(&self) -> ObjectId {
|
fn id(&self) -> ObjectId {
|
||||||
self.id
|
self.id.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interface(&self) -> Interface {
|
fn interface(&self) -> Interface {
|
||||||
|
|
@ -156,4 +157,8 @@ impl Object for XdgWmBaseObj {
|
||||||
fn num_requests(&self) -> u32 {
|
fn num_requests(&self) -> u32 {
|
||||||
PONG + 1
|
PONG + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn break_loops(&self) {
|
||||||
|
self.surfaces.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||||
|
use crate::ifs::wl_surface::xdg_surface::{XdgSurfaceError, XdgSurfaceId};
|
||||||
|
use crate::ifs::wl_surface::WlSurfaceId;
|
||||||
|
use crate::ifs::xdg_positioner::XdgPositionerId;
|
||||||
use crate::ifs::xdg_wm_base::{XdgWmBaseObj, PING};
|
use crate::ifs::xdg_wm_base::{XdgWmBaseObj, PING};
|
||||||
use crate::object::{Object, ObjectId};
|
use crate::object::Object;
|
||||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use crate::ifs::wl_surface::xdg_surface::XdgSurfaceError;
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum XdgWmBaseError {
|
pub enum XdgWmBaseError {
|
||||||
|
|
@ -77,7 +79,7 @@ impl Debug for Destroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct CreatePositioner {
|
pub(super) struct CreatePositioner {
|
||||||
pub id: ObjectId,
|
pub id: XdgPositionerId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for CreatePositioner {
|
impl RequestParser<'_> for CreatePositioner {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
@ -93,8 +95,8 @@ impl Debug for CreatePositioner {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct GetXdgSurface {
|
pub(super) struct GetXdgSurface {
|
||||||
pub id: ObjectId,
|
pub id: XdgSurfaceId,
|
||||||
pub surface: ObjectId,
|
pub surface: WlSurfaceId,
|
||||||
}
|
}
|
||||||
impl RequestParser<'_> for GetXdgSurface {
|
impl RequestParser<'_> for GetXdgSurface {
|
||||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,56 @@ macro_rules! bind {
|
||||||
Box<dyn std::future::Future<Output = Result<(), crate::globals::GlobalError>> + 'a>,
|
Box<dyn std::future::Future<Output = Result<(), crate::globals::GlobalError>> + 'a>,
|
||||||
> {
|
> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
self.bind_(id, client, version).await?;
|
self.bind_(id.into(), client, version).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! id {
|
||||||
|
($name:ident) => {
|
||||||
|
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
|
||||||
|
pub struct $name(u32);
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
impl $name {
|
||||||
|
pub const NONE: Self = $name(0);
|
||||||
|
|
||||||
|
pub fn from_raw(raw: u32) -> Self {
|
||||||
|
Self(raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn raw(self) -> u32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_some(self) -> bool {
|
||||||
|
self.0 != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_none(self) -> bool {
|
||||||
|
self.0 == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<crate::object::ObjectId> for $name {
|
||||||
|
fn from(f: crate::object::ObjectId) -> Self {
|
||||||
|
Self(f.raw())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<$name> for crate::object::ObjectId {
|
||||||
|
fn from(f: $name) -> Self {
|
||||||
|
crate::object::ObjectId::from_raw(f.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for $name {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
std::fmt::Display::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ pub const WL_DISPLAY_ID: ObjectId = ObjectId(1);
|
||||||
pub struct ObjectId(u32);
|
pub struct ObjectId(u32);
|
||||||
|
|
||||||
impl ObjectId {
|
impl ObjectId {
|
||||||
|
pub const NONE: Self = ObjectId(0);
|
||||||
|
|
||||||
pub fn from_raw(raw: u32) -> Self {
|
pub fn from_raw(raw: u32) -> Self {
|
||||||
Self(raw)
|
Self(raw)
|
||||||
}
|
}
|
||||||
|
|
@ -38,6 +40,7 @@ pub trait Object: ObjectHandleRequest + 'static {
|
||||||
fn id(&self) -> ObjectId;
|
fn id(&self) -> ObjectId;
|
||||||
fn interface(&self) -> Interface;
|
fn interface(&self) -> Interface;
|
||||||
fn num_requests(&self) -> u32;
|
fn num_requests(&self) -> u32;
|
||||||
|
fn break_loops(&self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
@ -57,6 +60,7 @@ pub enum Interface {
|
||||||
XdgPopup,
|
XdgPopup,
|
||||||
XdgToplevel,
|
XdgToplevel,
|
||||||
WlRegion,
|
WlRegion,
|
||||||
|
WlBuffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Interface {
|
impl Interface {
|
||||||
|
|
@ -77,6 +81,7 @@ impl Interface {
|
||||||
Interface::XdgPositioner => "xdg_positioner",
|
Interface::XdgPositioner => "xdg_positioner",
|
||||||
Interface::XdgPopup => "xdg_popup",
|
Interface::XdgPopup => "xdg_popup",
|
||||||
Interface::XdgToplevel => "xdg_toplevel",
|
Interface::XdgToplevel => "xdg_toplevel",
|
||||||
|
Interface::WlBuffer => "wl_buffer",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::object::ObjectId;
|
use crate::object::ObjectId;
|
||||||
use crate::utils::buffd::buf_out::{BufFdOut, MsgFds};
|
use crate::utils::buffd::buf_out::{BufFdOut, MsgFds};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::mem::{MaybeUninit};
|
use std::mem::MaybeUninit;
|
||||||
use uapi::OwnedFd;
|
use uapi::OwnedFd;
|
||||||
|
|
||||||
pub struct MsgFormatter<'a> {
|
pub struct MsgFormatter<'a> {
|
||||||
|
|
@ -50,11 +50,11 @@ impl<'a> MsgFormatter<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn object(&mut self, obj: ObjectId) -> &mut Self {
|
pub fn object<T: Into<ObjectId>>(&mut self, obj: T) -> &mut Self {
|
||||||
self.uint(obj.raw())
|
self.uint(obj.into().raw())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn header(&mut self, obj: ObjectId, event: u32) -> &mut Self {
|
pub fn header<T: Into<ObjectId>>(&mut self, obj: T, event: u32) -> &mut Self {
|
||||||
self.object(obj).uint(event)
|
self.object(obj).uint(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,11 @@ impl<'a, 'b> MsgParser<'a, 'b> {
|
||||||
self.int().map(|i| i as u32)
|
self.int().map(|i| i as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn object(&mut self) -> Result<ObjectId, MsgParserError> {
|
pub fn object<T>(&mut self) -> Result<T, MsgParserError>
|
||||||
self.int().map(|i| ObjectId::from_raw(i as u32))
|
where
|
||||||
|
ObjectId: Into<T>,
|
||||||
|
{
|
||||||
|
self.int().map(|i| ObjectId::from_raw(i as u32).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn global(&mut self) -> Result<GlobalName, MsgParserError> {
|
pub fn global(&mut self) -> Result<GlobalName, MsgParserError> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue