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
|
|
@ -3,16 +3,16 @@ use crate::client::objects::Objects;
|
|||
use crate::ifs::wl_callback::WlCallback;
|
||||
use crate::ifs::wl_compositor::{WlCompositorError, WlCompositorObj};
|
||||
use crate::ifs::wl_display::{WlDisplay, WlDisplayError};
|
||||
use crate::ifs::wl_region::{WlRegion, WlRegionError};
|
||||
use crate::ifs::wl_registry::{WlRegistry, WlRegistryError};
|
||||
use crate::ifs::wl_region::{WlRegion, WlRegionError, WlRegionId};
|
||||
use crate::ifs::wl_registry::{WlRegistry, WlRegistryError, WlRegistryId};
|
||||
use crate::ifs::wl_shm::{WlShmError, WlShmObj};
|
||||
use crate::ifs::wl_shm_pool::{WlShmPool, WlShmPoolError};
|
||||
use crate::ifs::wl_subcompositor::{WlSubcompositorError, WlSubcompositorObj};
|
||||
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_toplevel::XdgToplevelError;
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError};
|
||||
use crate::ifs::wl_surface::{WlSurface, WlSurfaceError};
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::{XdgPopup, XdgPopupError};
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, XdgToplevelError};
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceId};
|
||||
use crate::ifs::wl_surface::{WlSurface, WlSurfaceError, WlSurfaceId};
|
||||
use crate::ifs::xdg_positioner::{XdgPositioner, XdgPositionerError};
|
||||
use crate::ifs::xdg_wm_base::{XdgWmBaseError, XdgWmBaseObj};
|
||||
use crate::object::{Object, ObjectId, WL_DISPLAY_ID};
|
||||
|
|
@ -30,6 +30,7 @@ use std::mem;
|
|||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use uapi::OwnedFd;
|
||||
use crate::ifs::wl_buffer::{WlBuffer, WlBufferError};
|
||||
|
||||
mod objects;
|
||||
mod tasks;
|
||||
|
|
@ -54,10 +55,12 @@ pub enum ClientError {
|
|||
OutBufferOverflow,
|
||||
#[error("The requested client {0} does not exist")]
|
||||
ClientDoesNotExist(ClientId),
|
||||
#[error("There is no region with id {0}")]
|
||||
RegionDoesNotExist(ObjectId),
|
||||
#[error("There is no surface with id {0}")]
|
||||
SurfaceDoesNotExist(ObjectId),
|
||||
#[error("There is no wl_region with id {0}")]
|
||||
RegionDoesNotExist(WlRegionId),
|
||||
#[error("There is no wl_surface with id {0}")]
|
||||
SurfaceDoesNotExist(WlSurfaceId),
|
||||
#[error("There is no xdg_surface with id {0}")]
|
||||
XdgSurfaceDoesNotExist(XdgSurfaceId),
|
||||
#[error("Cannot parse the message")]
|
||||
ParserError(#[source] Box<MsgParserError>),
|
||||
#[error("Server tried to allocate more than 0x1_00_00_00 ids")]
|
||||
|
|
@ -100,6 +103,8 @@ pub enum ClientError {
|
|||
XdgToplevelError(#[source] Box<XdgToplevelError>),
|
||||
#[error("An error occurred in a `xdg_wm_base`")]
|
||||
XdgWmBaseError(#[source] Box<XdgWmBaseError>),
|
||||
#[error("An error occurred in a `wl_buffer`")]
|
||||
WlBufferError(#[source] Box<WlBufferError>),
|
||||
#[error("Object {0} is not a display")]
|
||||
NotADisplay(ObjectId),
|
||||
}
|
||||
|
|
@ -119,6 +124,7 @@ efrom!(ClientError, XdgPositionerError, XdgPositionerError);
|
|||
efrom!(ClientError, XdgWmBaseError, XdgWmBaseError);
|
||||
efrom!(ClientError, XdgToplevelError, XdgToplevelError);
|
||||
efrom!(ClientError, XdgPopupError, XdgPopupError);
|
||||
efrom!(ClientError, WlBufferError, WlBufferError);
|
||||
|
||||
impl ClientError {
|
||||
fn peer_closed(&self) -> bool {
|
||||
|
|
@ -353,20 +359,27 @@ impl Client {
|
|||
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) {
|
||||
Some(r) => Ok(r),
|
||||
_ => 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) {
|
||||
Some(r) => Ok(r),
|
||||
_ => 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> {
|
||||
if client {
|
||||
self.objects.add_client_object(obj.clone())
|
||||
|
|
@ -383,7 +396,7 @@ impl Client {
|
|||
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()
|
||||
}
|
||||
|
||||
|
|
@ -438,7 +451,9 @@ simple_add_obj!(WlShmPool);
|
|||
simple_add_obj!(WlSubcompositorObj);
|
||||
simple_add_obj!(WlSubsurface);
|
||||
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 {
|
||||
($ty:ty, $field:ident) => {
|
||||
|
|
@ -447,11 +462,11 @@ macro_rules! dedicated_add_obj {
|
|||
|
||||
fn add_obj(&self, obj: &Rc<$ty>, client: bool) -> Result<(), ClientError> {
|
||||
self.simple_add_obj(obj, client)?;
|
||||
self.objects.$field.set(obj.id(), obj.clone());
|
||||
self.objects.$field.set(obj.id().into(), obj.clone());
|
||||
Ok(())
|
||||
}
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
@ -461,3 +476,4 @@ macro_rules! dedicated_add_obj {
|
|||
dedicated_add_obj!(WlRegion, regions);
|
||||
dedicated_add_obj!(WlSurface, surfaces);
|
||||
dedicated_add_obj!(XdgWmBaseObj, xdg_wm_bases);
|
||||
dedicated_add_obj!(XdgSurface, xdg_surfaces);
|
||||
|
|
|
|||
|
|
@ -1,23 +1,25 @@
|
|||
use crate::client::{Client, ClientError};
|
||||
use crate::ifs::wl_display::WlDisplay;
|
||||
use crate::ifs::wl_region::WlRegion;
|
||||
use crate::ifs::wl_registry::WlRegistry;
|
||||
use crate::ifs::wl_surface::WlSurface;
|
||||
use crate::ifs::wl_region::{WlRegion, WlRegionId};
|
||||
use crate::ifs::wl_registry::{WlRegistry, WlRegistryId};
|
||||
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::utils::copyhashmap::CopyHashMap;
|
||||
use ahash::AHashMap;
|
||||
use std::cell::{RefCell, RefMut};
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
|
||||
|
||||
pub struct Objects {
|
||||
pub display: RefCell<Option<Rc<WlDisplay>>>,
|
||||
registry: CopyHashMap<ObjectId, Rc<dyn Object>>,
|
||||
registries: CopyHashMap<ObjectId, Rc<WlRegistry>>,
|
||||
pub surfaces: CopyHashMap<ObjectId, Rc<WlSurface>>,
|
||||
pub regions: CopyHashMap<ObjectId, Rc<WlRegion>>,
|
||||
pub xdg_wm_bases: CopyHashMap<ObjectId, Rc<XdgWmBaseObj>>,
|
||||
registries: CopyHashMap<WlRegistryId, Rc<WlRegistry>>,
|
||||
pub surfaces: CopyHashMap<WlSurfaceId, Rc<WlSurface>>,
|
||||
pub xdg_surfaces: CopyHashMap<XdgSurfaceId, Rc<XdgSurface>>,
|
||||
pub regions: CopyHashMap<WlRegionId, Rc<WlRegion>>,
|
||||
pub xdg_wm_bases: CopyHashMap<XdgWmBaseId, Rc<XdgWmBaseObj>>,
|
||||
ids: RefCell<Vec<usize>>,
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +33,7 @@ impl Objects {
|
|||
registry: Default::default(),
|
||||
registries: Default::default(),
|
||||
surfaces: Default::default(),
|
||||
xdg_surfaces: Default::default(),
|
||||
regions: Default::default(),
|
||||
xdg_wm_bases: Default::default(),
|
||||
ids: RefCell::new(vec![]),
|
||||
|
|
@ -39,25 +42,24 @@ impl Objects {
|
|||
|
||||
pub fn destroy(&self) {
|
||||
{
|
||||
let mut surfaces = self.surfaces.lock();
|
||||
for surface in surfaces.values_mut() {
|
||||
surface.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();
|
||||
let mut registry = self.registry.lock();
|
||||
for obj in registry.values_mut() {
|
||||
obj.break_loops();
|
||||
}
|
||||
registry.clear();
|
||||
}
|
||||
*self.display.borrow_mut() = None;
|
||||
self.registry.clear();
|
||||
self.regions.clear();
|
||||
self.registries.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;
|
||||
let offset = self.id_offset();
|
||||
if offset > MAX_ID_OFFSET {
|
||||
|
|
@ -68,7 +70,7 @@ impl Objects {
|
|||
);
|
||||
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> {
|
||||
|
|
@ -123,7 +125,7 @@ impl Objects {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn registries(&self) -> RefMut<AHashMap<ObjectId, Rc<WlRegistry>>> {
|
||||
pub fn registries(&self) -> RefMut<AHashMap<WlRegistryId, Rc<WlRegistry>>> {
|
||||
self.registries.lock()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue