1
0
Fork 0
forked from wry/wry

autocommit 2022-02-05 18:14:24 CET

This commit is contained in:
Julian Orth 2022-02-05 18:14:24 +01:00
parent 2d8b3a200e
commit 3a4ae99b9a
71 changed files with 1626 additions and 1306 deletions

View file

@ -1,38 +1,8 @@
use crate::client::ClientId;
use crate::ifs::org_kde_kwin_server_decoration::OrgKdeKwinServerDecorationError;
use crate::ifs::org_kde_kwin_server_decoration_manager::OrgKdeKwinServerDecorationManagerError;
use crate::ifs::wl_buffer::{WlBufferError, WlBufferId};
use crate::ifs::wl_compositor::WlCompositorError;
use crate::ifs::wl_data_device::WlDataDeviceError;
use crate::ifs::wl_data_device_manager::WlDataDeviceManagerError;
use crate::ifs::wl_data_offer::WlDataOfferError;
use crate::ifs::wl_data_source::{WlDataSourceError, WlDataSourceId};
use crate::ifs::wl_display::WlDisplayError;
use crate::ifs::wl_drm::WlDrmError;
use crate::ifs::wl_output::WlOutputError;
use crate::ifs::wl_region::{WlRegionError, WlRegionId};
use crate::ifs::wl_registry::WlRegistryError;
use crate::ifs::wl_seat::wl_keyboard::WlKeyboardError;
use crate::ifs::wl_seat::wl_pointer::WlPointerError;
use crate::ifs::wl_seat::wl_touch::WlTouchError;
use crate::ifs::wl_seat::{WlSeatError, WlSeatId};
use crate::ifs::wl_shm::WlShmError;
use crate::ifs::wl_shm_pool::WlShmPoolError;
use crate::ifs::wl_subcompositor::WlSubcompositorError;
use crate::ifs::wl_surface::wl_subsurface::WlSubsurfaceError;
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopupError;
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevelError, XdgToplevelId};
use crate::ifs::wl_surface::xdg_surface::{XdgSurfaceError, XdgSurfaceId};
use crate::ifs::wl_surface::{WlSurfaceError, WlSurfaceId};
use crate::ifs::xdg_positioner::{XdgPositionerError, XdgPositionerId};
use crate::ifs::xdg_wm_base::XdgWmBaseError;
use crate::ifs::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1Error;
use crate::ifs::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1Error;
use crate::ifs::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Error;
use crate::ifs::zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1Error;
use crate::object::ObjectId;
use crate::object::{Interface, ObjectId};
use crate::utils::buffd::{BufFdError, MsgParserError};
use crate::AsyncError;
use std::error::Error;
use thiserror::Error;
#[derive(Debug, Error)]
@ -53,22 +23,6 @@ pub enum ClientError {
UnalignedMessage,
#[error("The requested client {0} does not exist")]
ClientDoesNotExist(ClientId),
#[error("There is no wl_region with id {0}")]
RegionDoesNotExist(WlRegionId),
#[error("There is no wl_buffer with id {0}")]
BufferDoesNotExist(WlBufferId),
#[error("There is no wl_surface with id {0}")]
SurfaceDoesNotExist(WlSurfaceId),
#[error("There is no xdg_surface with id {0}")]
XdgSurfaceDoesNotExist(XdgSurfaceId),
#[error("There is no wl_data_source with id {0}")]
WlDataSourceDoesNotExist(WlDataSourceId),
#[error("There is no xdg_toplevel with id {0}")]
XdgToplevelDoesNotExist(XdgToplevelId),
#[error("There is no xdg_positioner with id {0}")]
XdgPositionerDoesNotExist(XdgPositionerId),
#[error("There is no wl_seat with id {0}")]
WlSeatDoesNotExist(WlSeatId),
#[error("Cannot parse the message")]
ParserError(#[source] Box<MsgParserError>),
#[error("Server tried to allocate more than 0x1_00_00_00 ids")]
@ -81,109 +35,34 @@ pub enum ClientError {
IdAlreadyInUse,
#[error("The client object id is out of bounds")]
ClientIdOutOfBounds,
#[error("An error occurred in a `wl_display`")]
WlDisplayError(#[source] Box<WlDisplayError>),
#[error("An error occurred in a `wl_registry`")]
WlRegistryError(#[source] Box<WlRegistryError>),
#[error("Could not add object {0} to the client")]
AddObjectError(ObjectId, #[source] Box<ClientError>),
#[error("An error occurred in a `wl_surface`")]
WlSurfaceError(#[source] Box<WlSurfaceError>),
#[error("An error occurred in a `wl_compositor`")]
WlCompositorError(#[source] Box<WlCompositorError>),
#[error("An error occurred in a `wl_shm`")]
WlShmError(#[source] Box<WlShmError>),
#[error("An error occurred in a `wl_shm_pool`")]
WlShmPoolError(#[source] Box<WlShmPoolError>),
#[error("An error occurred in a `wl_region`")]
WlRegionError(#[source] Box<WlRegionError>),
#[error("An error occurred in a `wl_subsurface`")]
WlSubsurfaceError(#[source] Box<WlSubsurfaceError>),
#[error("An error occurred in a `wl_subcompositor`")]
WlSubcompositorError(#[source] Box<WlSubcompositorError>),
#[error("An error occurred in a `xdg_surface`")]
XdgSurfaceError(#[source] Box<XdgSurfaceError>),
#[error("An error occurred in a `xdg_positioner`")]
XdgPositionerError(#[source] Box<XdgPositionerError>),
#[error("An error occurred in a `xdg_popup`")]
XdgPopupError(#[source] Box<XdgPopupError>),
#[error("An error occurred in a `xdg_toplevel`")]
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("An error occurred in a `wl_output`")]
WlOutputError(#[source] Box<WlOutputError>),
#[error("An error occurred in a `wl_seat`")]
WlSeatError(#[source] Box<WlSeatError>),
#[error("An error occurred in a `wl_pointer`")]
WlPointerError(#[source] Box<WlPointerError>),
#[error("An error occurred in a `wl_keyboard`")]
WlKeyboardError(#[source] Box<WlKeyboardError>),
#[error("An error occurred in a `wl_touch`")]
WlTouchError(#[source] Box<WlTouchError>),
#[error("Object {0} is not a display")]
NotADisplay(ObjectId),
#[error("An error occurred in a `wl_data_device`")]
WlDataDeviceError(#[source] Box<WlDataDeviceError>),
#[error("An error occurred in a `wl_data_device_manager`")]
WlDataDeviceManagerError(#[source] Box<WlDataDeviceManagerError>),
#[error("An error occurred in a `wl_data_offer`")]
WlDataOfferError(#[source] Box<WlDataOfferError>),
#[error("An error occurred in a `wl_data_source`")]
WlDataSourceError(#[source] Box<WlDataSourceError>),
#[error("An error occurred in a `zwp_linx_dmabuf_v1`")]
ZwpLinuxDmabufV1Error(#[source] Box<ZwpLinuxDmabufV1Error>),
#[error("An error occurred in a `zwp_linx_buffer_params_v1`")]
ZwpLinuxBufferParamsV1Error(#[source] Box<ZwpLinuxBufferParamsV1Error>),
#[error("An error occurred in a `wl_drm`")]
WlDrmError(#[source] Box<WlDrmError>),
#[error("An error occurred in a `zxdg_decoration_manager_v1`")]
ZxdgDecorationManagerV1Error(#[source] Box<ZxdgDecorationManagerV1Error>),
#[error("An error occurred in a `zxdg_toplevel_decoration_v1`")]
ZxdgToplevelDecorationV1Error(#[source] Box<ZxdgToplevelDecorationV1Error>),
#[error("An error occurred in a `org_kde_kwin_server_decoration_manager`")]
OrgKdeKwinServerDecorationManagerError(#[source] Box<OrgKdeKwinServerDecorationManagerError>),
#[error("An error occurred in a `org_kde_kwin_server_decoration`")]
OrgKdeKwinServerDecorationError(#[source] Box<OrgKdeKwinServerDecorationError>),
#[error(transparent)]
ObjectError(ObjectError),
#[error(transparent)]
LookupError(LookupError),
#[error("Could not add object {0} to the client")]
AddObjectError(ObjectId, #[source] Box<ClientError>),
}
efrom!(ClientError, ParserError, MsgParserError);
efrom!(ClientError, WlDisplayError);
efrom!(ClientError, WlRegistryError);
efrom!(ClientError, WlSurfaceError);
efrom!(ClientError, WlCompositorError);
efrom!(ClientError, WlShmError);
efrom!(ClientError, WlShmPoolError);
efrom!(ClientError, WlRegionError);
efrom!(ClientError, WlSubsurfaceError);
efrom!(ClientError, WlSubcompositorError);
efrom!(ClientError, XdgSurfaceError);
efrom!(ClientError, XdgPositionerError);
efrom!(ClientError, XdgWmBaseError);
efrom!(ClientError, XdgToplevelError);
efrom!(ClientError, XdgPopupError);
efrom!(ClientError, WlBufferError);
efrom!(ClientError, WlOutputError);
efrom!(ClientError, WlSeatError);
efrom!(ClientError, WlTouchError);
efrom!(ClientError, WlPointerError);
efrom!(ClientError, WlKeyboardError);
efrom!(ClientError, WlDataDeviceManagerError);
efrom!(ClientError, WlDataDeviceError);
efrom!(ClientError, WlDataSourceError);
efrom!(ClientError, WlDataOfferError);
efrom!(ClientError, ZwpLinuxDmabufV1Error);
efrom!(ClientError, ZwpLinuxBufferParamsV1Error);
efrom!(ClientError, WlDrmError);
efrom!(ClientError, ZxdgDecorationManagerV1Error);
efrom!(ClientError, ZxdgToplevelDecorationV1Error);
efrom!(ClientError, OrgKdeKwinServerDecorationManagerError);
efrom!(ClientError, OrgKdeKwinServerDecorationError);
impl ClientError {
pub fn peer_closed(&self) -> bool {
matches!(self, ClientError::Io(BufFdError::Closed))
}
}
#[derive(Debug, Error)]
#[error("An error occurred in a `{}`", .interface.name())]
pub struct ObjectError {
pub interface: Interface,
#[source]
pub error: Box<dyn Error + 'static>,
}
#[derive(Debug, Error)]
#[error("There is no `{}` with id {}", .interface.name(), .id)]
pub struct LookupError {
pub interface: Interface,
pub id: ObjectId,
}

View file

@ -1,38 +1,10 @@
use crate::async_engine::{AsyncFd, SpawnedFuture};
use crate::client::error::LookupError;
use crate::client::objects::Objects;
use crate::ifs::org_kde_kwin_server_decoration::OrgKdeKwinServerDecoration;
use crate::ifs::org_kde_kwin_server_decoration_manager::OrgKdeKwinServerDecorationManagerObj;
use crate::ifs::wl_buffer::{WlBuffer, WlBufferId};
use crate::ifs::wl_callback::WlCallback;
use crate::ifs::wl_compositor::WlCompositorObj;
use crate::ifs::wl_data_device::WlDataDevice;
use crate::ifs::wl_data_device_manager::WlDataDeviceManagerObj;
use crate::ifs::wl_data_offer::WlDataOffer;
use crate::ifs::wl_data_source::{WlDataSource, WlDataSourceId};
use crate::ifs::wl_display::WlDisplay;
use crate::ifs::wl_drm::WlDrmObj;
use crate::ifs::wl_output::WlOutputObj;
use crate::ifs::wl_region::{WlRegion, WlRegionId};
use crate::ifs::wl_registry::{WlRegistry, WlRegistryId};
use crate::ifs::wl_seat::wl_keyboard::WlKeyboard;
use crate::ifs::wl_seat::wl_pointer::WlPointer;
use crate::ifs::wl_seat::wl_touch::WlTouch;
use crate::ifs::wl_seat::{WlSeatId, WlSeatObj};
use crate::ifs::wl_shm::WlShmObj;
use crate::ifs::wl_shm_pool::WlShmPool;
use crate::ifs::wl_subcompositor::WlSubcompositorObj;
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, XdgToplevelId};
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId};
use crate::ifs::wl_surface::{WlSurface, WlSurfaceId};
use crate::ifs::xdg_positioner::{XdgPositioner, XdgPositionerId};
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
use crate::ifs::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1;
use crate::ifs::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1Obj;
use crate::ifs::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Obj;
use crate::ifs::zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1;
use crate::object::{Object, ObjectId, WL_DISPLAY_ID};
use crate::object::{Interface, Object, ObjectId, WL_DISPLAY_ID};
use crate::state::State;
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use crate::utils::numcell::NumCell;
@ -40,7 +12,7 @@ use crate::utils::oneshot::{oneshot, OneshotTx};
use crate::utils::queue::AsyncQueue;
use crate::ErrorFmt;
use ahash::AHashMap;
pub use error::ClientError;
pub use error::{ClientError, ObjectError};
use std::cell::{Cell, RefCell, RefMut};
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
@ -332,65 +304,6 @@ impl Client {
self.checking_queue_size.set(false);
}
pub fn get_buffer(&self, id: WlBufferId) -> Result<Rc<WlBuffer>, ClientError> {
match self.objects.buffers.get(&id) {
Some(r) => Ok(r),
_ => Err(ClientError::BufferDoesNotExist(id)),
}
}
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: 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)),
}
}
pub fn get_wl_data_source(&self, id: WlDataSourceId) -> Result<Rc<WlDataSource>, ClientError> {
match self.objects.wl_data_source.get(&id) {
Some(r) => Ok(r),
_ => Err(ClientError::WlDataSourceDoesNotExist(id)),
}
}
pub fn get_xdg_toplevel(&self, id: XdgToplevelId) -> Result<Rc<XdgToplevel>, ClientError> {
match self.objects.xdg_toplevel.get(&id) {
Some(r) => Ok(r),
_ => Err(ClientError::XdgToplevelDoesNotExist(id)),
}
}
pub fn get_xdg_positioner(
&self,
id: XdgPositionerId,
) -> Result<Rc<XdgPositioner>, ClientError> {
match self.objects.xdg_positioners.get(&id) {
Some(r) => Ok(r),
_ => Err(ClientError::XdgPositionerDoesNotExist(id)),
}
}
pub fn get_wl_seat(&self, id: WlSeatId) -> Result<Rc<WlSeatObj>, ClientError> {
match self.objects.seats.get(&id) {
Some(r) => Ok(r),
_ => Err(ClientError::WlSeatDoesNotExist(id)),
}
}
pub fn lock_registries(&self) -> RefMut<AHashMap<WlRegistryId, Rc<WlRegistry>>> {
self.objects.registries()
}
@ -432,6 +345,18 @@ impl Client {
obj.remove(self);
self.objects.remove_obj(self, obj.id())
}
pub fn lookup<Id: WaylandObjectLookup>(&self, id: Id) -> Result<Rc<Id::Object>, ClientError> {
match Id::lookup(self, id) {
Some(t) => Ok(t),
_ => {
return Err(ClientError::LookupError(LookupError {
interface: Id::INTERFACE,
id: id.into(),
}))
}
}
}
}
pub trait WaylandObject: Object {
@ -443,54 +368,9 @@ pub trait WaylandObject: Object {
}
}
macro_rules! simple_add_obj {
($ty:ty) => {
impl WaylandObject for $ty {}
};
pub trait WaylandObjectLookup: Copy + Into<ObjectId> {
type Object;
const INTERFACE: Interface;
fn lookup(client: &Client, id: Self) -> Option<Rc<Self::Object>>;
}
simple_add_obj!(WlCompositorObj);
simple_add_obj!(WlCallback);
simple_add_obj!(WlRegistry);
simple_add_obj!(WlShmObj);
simple_add_obj!(WlShmPool);
simple_add_obj!(WlSubcompositorObj);
simple_add_obj!(WlSubsurface);
simple_add_obj!(XdgPopup);
simple_add_obj!(WlOutputObj);
simple_add_obj!(WlKeyboard);
simple_add_obj!(WlPointer);
simple_add_obj!(WlTouch);
simple_add_obj!(WlDataDeviceManagerObj);
simple_add_obj!(WlDataDevice);
simple_add_obj!(WlDataOffer);
simple_add_obj!(ZwpLinuxDmabufV1Obj);
simple_add_obj!(ZwpLinuxBufferParamsV1);
simple_add_obj!(WlDrmObj);
simple_add_obj!(ZxdgToplevelDecorationV1);
simple_add_obj!(ZxdgDecorationManagerV1Obj);
simple_add_obj!(OrgKdeKwinServerDecorationManagerObj);
simple_add_obj!(OrgKdeKwinServerDecoration);
macro_rules! dedicated_add_obj {
($ty:ty, $field:ident) => {
impl WaylandObject for $ty {
fn add(self: Rc<Self>, client: &Client) {
client.objects.$field.set(self.id().into(), self);
}
fn remove(&self, client: &Client) {
client.objects.$field.remove(&self.id().into());
}
}
};
}
dedicated_add_obj!(WlRegion, regions);
dedicated_add_obj!(WlSurface, surfaces);
dedicated_add_obj!(XdgWmBaseObj, xdg_wm_bases);
dedicated_add_obj!(XdgSurface, xdg_surfaces);
dedicated_add_obj!(WlBuffer, buffers);
dedicated_add_obj!(WlSeatObj, seats);
dedicated_add_obj!(XdgPositioner, xdg_positioners);
dedicated_add_obj!(XdgToplevel, xdg_toplevel);
dedicated_add_obj!(WlDataSource, wl_data_source);

View file

@ -4,12 +4,15 @@ use crate::ifs::wl_data_source::{WlDataSource, WlDataSourceId};
use crate::ifs::wl_display::WlDisplay;
use crate::ifs::wl_region::{WlRegion, WlRegionId};
use crate::ifs::wl_registry::{WlRegistry, WlRegistryId};
use crate::ifs::wl_seat::{WlSeatId, WlSeatObj};
use crate::ifs::wl_seat::{WlSeat, WlSeatId};
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, XdgToplevelId};
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId};
use crate::ifs::wl_surface::{WlSurface, WlSurfaceId};
use crate::ifs::xdg_positioner::{XdgPositioner, XdgPositionerId};
use crate::ifs::xdg_wm_base::{XdgWmBaseId, XdgWmBaseObj};
use crate::ifs::xdg_wm_base::{XdgWmBase, XdgWmBaseId};
use crate::ifs::zwp_primary_selection_source_v1::{
ZwpPrimarySelectionSourceV1, ZwpPrimarySelectionSourceV1Id,
};
use crate::object::{Object, ObjectId};
use crate::tree::Node;
use crate::utils::clonecell::CloneCell;
@ -27,11 +30,13 @@ pub struct Objects {
pub xdg_surfaces: CopyHashMap<XdgSurfaceId, Rc<XdgSurface>>,
pub xdg_toplevel: CopyHashMap<XdgToplevelId, Rc<XdgToplevel>>,
pub wl_data_source: CopyHashMap<WlDataSourceId, Rc<WlDataSource>>,
pub zwp_primary_selection_source:
CopyHashMap<ZwpPrimarySelectionSourceV1Id, Rc<ZwpPrimarySelectionSourceV1>>,
pub xdg_positioners: CopyHashMap<XdgPositionerId, Rc<XdgPositioner>>,
pub regions: CopyHashMap<WlRegionId, Rc<WlRegion>>,
pub buffers: CopyHashMap<WlBufferId, Rc<WlBuffer>>,
pub xdg_wm_bases: CopyHashMap<XdgWmBaseId, Rc<XdgWmBaseObj>>,
pub seats: CopyHashMap<WlSeatId, Rc<WlSeatObj>>,
pub xdg_wm_bases: CopyHashMap<XdgWmBaseId, Rc<XdgWmBase>>,
pub seats: CopyHashMap<WlSeatId, Rc<WlSeat>>,
ids: RefCell<Vec<usize>>,
}
@ -48,6 +53,7 @@ impl Objects {
xdg_surfaces: Default::default(),
xdg_toplevel: Default::default(),
wl_data_source: Default::default(),
zwp_primary_selection_source: Default::default(),
xdg_positioners: Default::default(),
regions: Default::default(),
buffers: Default::default(),
@ -73,12 +79,16 @@ impl Objects {
registry.clear();
}
self.display.set(None);
self.regions.clear();
self.registries.clear();
self.surfaces.clear();
self.xdg_wm_bases.clear();
self.xdg_surfaces.clear();
self.wl_data_source.clear();
self.zwp_primary_selection_source.clear();
self.xdg_positioners.clear();
self.regions.clear();
self.buffers.clear();
self.xdg_wm_bases.clear();
self.seats.clear();
}
pub fn id<T>(&self, client_data: &Client) -> Result<T, ClientError>