autocommit 2022-01-02 20:11:25 CET
This commit is contained in:
parent
c21f231ce7
commit
fc887b339e
29 changed files with 672 additions and 197 deletions
|
|
@ -1,10 +1,13 @@
|
|||
mod types;
|
||||
pub mod wl_subsurface;
|
||||
|
||||
use crate::client::{Client, RequestParser};
|
||||
use crate::ifs::wl_surface::wl_subsurface::WlSubsurface;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::pixman::Region;
|
||||
use crate::utils::buffd::{WlParser, WlParserError};
|
||||
use std::cell::Cell;
|
||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||
use ahash::AHashMap;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
|
|
@ -26,10 +29,19 @@ const INVALID_SCALE: u32 = 0;
|
|||
const INVALID_TRANSFORM: u32 = 1;
|
||||
const INVALID_SIZE: u32 = 2;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum SurfaceType {
|
||||
None,
|
||||
Subsurface,
|
||||
}
|
||||
|
||||
pub struct WlSurface {
|
||||
id: ObjectId,
|
||||
client: Rc<Client>,
|
||||
ty: Cell<SurfaceType>,
|
||||
pending: PendingState,
|
||||
children: RefCell<Option<Box<ParentData>>>,
|
||||
subsurface_data: RefCell<Option<Box<SubsurfaceData>>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -38,45 +50,82 @@ struct PendingState {
|
|||
input_region: Cell<Option<Region>>,
|
||||
}
|
||||
|
||||
struct SubsurfaceData {
|
||||
subsurface: Rc<WlSubsurface>,
|
||||
parent: Rc<WlSurface>,
|
||||
sync_requested: bool,
|
||||
sync_ancestor: bool,
|
||||
pending: bool,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ParentData {
|
||||
subsurfaces: AHashMap<ObjectId, Rc<WlSurface>>,
|
||||
pending_subsurfaces: AHashMap<ObjectId, Rc<WlSurface>>,
|
||||
}
|
||||
|
||||
impl WlSurface {
|
||||
pub fn new(id: ObjectId, client: &Rc<Client>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
client: client.clone(),
|
||||
ty: Cell::new(SurfaceType::None),
|
||||
pending: Default::default(),
|
||||
children: Default::default(),
|
||||
subsurface_data: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn break_loops(&self) {
|
||||
*self.children.borrow_mut() = None;
|
||||
*self.subsurface_data.borrow_mut() = None;
|
||||
}
|
||||
|
||||
pub fn get_root(self: &Rc<Self>) -> Rc<WlSurface> {
|
||||
let mut root = self.clone();
|
||||
loop {
|
||||
let tmp = root;
|
||||
let data = tmp.subsurface_data.borrow();
|
||||
match data.as_ref() {
|
||||
Some(d) => root = d.parent.clone(),
|
||||
None => {
|
||||
drop(data);
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse<'a, T: RequestParser<'a>>(
|
||||
&self,
|
||||
parser: WlParser<'_, 'a>,
|
||||
) -> Result<T, WlParserError> {
|
||||
parser: MsgParser<'_, 'a>,
|
||||
) -> Result<T, MsgParserError> {
|
||||
self.client.parse(self, parser)
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: WlParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let destroy: Destroy = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn attach(&self, parser: WlParser<'_, '_>) -> Result<(), AttachError> {
|
||||
async fn attach(&self, parser: MsgParser<'_, '_>) -> Result<(), AttachError> {
|
||||
let attach: Attach = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn damage(&self, parser: WlParser<'_, '_>) -> Result<(), DamageError> {
|
||||
async fn damage(&self, parser: MsgParser<'_, '_>) -> Result<(), DamageError> {
|
||||
let damage: Damage = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn frame(&self, parser: WlParser<'_, '_>) -> Result<(), FrameError> {
|
||||
async fn frame(&self, parser: MsgParser<'_, '_>) -> Result<(), FrameError> {
|
||||
let frame: Frame = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_opaque_region(
|
||||
&self,
|
||||
parser: WlParser<'_, '_>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), SetOpaqueRegionError> {
|
||||
let region: SetOpaqueRegion = self.parse(parser)?;
|
||||
let region = self.client.get_region(region.region)?;
|
||||
|
|
@ -84,32 +133,32 @@ impl WlSurface {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_input_region(&self, parser: WlParser<'_, '_>) -> Result<(), SetInputRegionError> {
|
||||
async fn set_input_region(&self, parser: MsgParser<'_, '_>) -> Result<(), SetInputRegionError> {
|
||||
let region: SetInputRegion = self.parse(parser)?;
|
||||
let region = self.client.get_region(region.region)?;
|
||||
self.pending.input_region.set(Some(region.region()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn commit(&self, parser: WlParser<'_, '_>) -> Result<(), CommitError> {
|
||||
async fn commit(&self, parser: MsgParser<'_, '_>) -> Result<(), CommitError> {
|
||||
let commit: Commit = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_buffer_transform(
|
||||
&self,
|
||||
parser: WlParser<'_, '_>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), SetBufferTransformError> {
|
||||
let transform: SetBufferTransform = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_buffer_scale(&self, parser: WlParser<'_, '_>) -> Result<(), SetBufferScaleError> {
|
||||
async fn set_buffer_scale(&self, parser: MsgParser<'_, '_>) -> Result<(), SetBufferScaleError> {
|
||||
let scale: SetBufferScale = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn damage_buffer(&self, parser: WlParser<'_, '_>) -> Result<(), DamageBufferError> {
|
||||
async fn damage_buffer(&self, parser: MsgParser<'_, '_>) -> Result<(), DamageBufferError> {
|
||||
let damage: DamageBuffer = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -117,7 +166,7 @@ impl WlSurface {
|
|||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlSurfaceError> {
|
||||
match request {
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::client::{ClientError, RequestParser};
|
||||
use crate::object::ObjectId;
|
||||
use crate::utils::buffd::{WlParser, WlParserError};
|
||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
@ -45,82 +45,82 @@ efrom!(WlSurfaceError, DamageBufferError, DamageBufferError);
|
|||
#[derive(Debug, Error)]
|
||||
pub enum DestroyError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(DestroyError, ParseFailed, WlParserError);
|
||||
efrom!(DestroyError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum AttachError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(AttachError, ParseFailed, WlParserError);
|
||||
efrom!(AttachError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DamageError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(DamageError, ParseFailed, WlParserError);
|
||||
efrom!(DamageError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum FrameError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(FrameError, ParseFailed, WlParserError);
|
||||
efrom!(FrameError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetOpaqueRegionError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(SetOpaqueRegionError, ParseFailed, WlParserError);
|
||||
efrom!(SetOpaqueRegionError, ParseFailed, MsgParserError);
|
||||
efrom!(SetOpaqueRegionError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetInputRegionError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(SetInputRegionError, ParseFailed, WlParserError);
|
||||
efrom!(SetInputRegionError, ParseFailed, MsgParserError);
|
||||
efrom!(SetInputRegionError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CommitError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(CommitError, ParseFailed, WlParserError);
|
||||
efrom!(CommitError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetBufferTransformError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(SetBufferTransformError, ParseFailed, WlParserError);
|
||||
efrom!(SetBufferTransformError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetBufferScaleError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(SetBufferScaleError, ParseFailed, WlParserError);
|
||||
efrom!(SetBufferScaleError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DamageBufferError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(DamageBufferError, ParseFailed, WlParserError);
|
||||
efrom!(DamageBufferError, ParseFailed, MsgParserError);
|
||||
|
||||
pub(super) struct Destroy;
|
||||
impl RequestParser<'_> for Destroy {
|
||||
fn parse(_parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ pub(super) struct Attach {
|
|||
pub y: i32,
|
||||
}
|
||||
impl RequestParser<'_> for Attach {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
buffer: parser.object()?,
|
||||
x: parser.int()?,
|
||||
|
|
@ -161,7 +161,7 @@ pub(super) struct Damage {
|
|||
pub height: i32,
|
||||
}
|
||||
impl RequestParser<'_> for Damage {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
x: parser.int()?,
|
||||
y: parser.int()?,
|
||||
|
|
@ -184,7 +184,7 @@ pub(super) struct Frame {
|
|||
pub callback: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for Frame {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
callback: parser.object()?,
|
||||
})
|
||||
|
|
@ -200,7 +200,7 @@ pub(super) struct SetOpaqueRegion {
|
|||
pub region: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for SetOpaqueRegion {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
region: parser.object()?,
|
||||
})
|
||||
|
|
@ -216,7 +216,7 @@ pub(super) struct SetInputRegion {
|
|||
pub region: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for SetInputRegion {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
region: parser.object()?,
|
||||
})
|
||||
|
|
@ -230,7 +230,7 @@ impl Debug for SetInputRegion {
|
|||
|
||||
pub(super) struct Commit;
|
||||
impl RequestParser<'_> for Commit {
|
||||
fn parse(_parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
|
|
@ -244,7 +244,7 @@ pub(super) struct SetBufferTransform {
|
|||
pub transform: i32,
|
||||
}
|
||||
impl RequestParser<'_> for SetBufferTransform {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
transform: parser.int()?,
|
||||
})
|
||||
|
|
@ -260,7 +260,7 @@ pub(super) struct SetBufferScale {
|
|||
pub scale: i32,
|
||||
}
|
||||
impl RequestParser<'_> for SetBufferScale {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
scale: parser.int()?,
|
||||
})
|
||||
|
|
@ -279,7 +279,7 @@ pub(super) struct DamageBuffer {
|
|||
pub height: i32,
|
||||
}
|
||||
impl RequestParser<'_> for DamageBuffer {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
x: parser.int()?,
|
||||
y: parser.int()?,
|
||||
|
|
|
|||
132
src/ifs/wl_surface/wl_subsurface/mod.rs
Normal file
132
src/ifs/wl_surface/wl_subsurface/mod.rs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
mod types;
|
||||
|
||||
use crate::ifs::wl_surface::{SubsurfaceData, SurfaceType, WlSurface};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const SET_POSITION: u32 = 1;
|
||||
const PLACE_ABOVE: u32 = 2;
|
||||
const PLACE_BELOW: u32 = 3;
|
||||
const SET_SYNC: u32 = 4;
|
||||
const SET_DESYNC: u32 = 5;
|
||||
|
||||
const BAD_SURFACE: u32 = 0;
|
||||
|
||||
pub struct WlSubsurface {
|
||||
id: ObjectId,
|
||||
surface: Rc<WlSurface>,
|
||||
}
|
||||
|
||||
impl WlSubsurface {
|
||||
pub fn new(id: ObjectId, surface: &Rc<WlSurface>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
surface: surface.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn install(self: &Rc<Self>, parent: &Rc<WlSurface>) -> Result<(), WlSubsurfaceError> {
|
||||
let old_ty = self.surface.ty.get();
|
||||
if !matches!(old_ty, SurfaceType::None | SurfaceType::Subsurface) {
|
||||
return Err(WlSubsurfaceError::IncompatibleType(self.surface.id, old_ty));
|
||||
}
|
||||
self.surface.ty.set(SurfaceType::Subsurface);
|
||||
let mut data = self.surface.subsurface_data.borrow_mut();
|
||||
if data.is_some() {
|
||||
return Err(WlSubsurfaceError::AlreadyAttached(self.surface.id));
|
||||
}
|
||||
if self.surface.id == parent.id {
|
||||
return Err(WlSubsurfaceError::OwnParent(self.surface.id));
|
||||
}
|
||||
if self.surface.id == parent.get_root().id {
|
||||
return Err(WlSubsurfaceError::Ancestor(self.surface.id, parent.id));
|
||||
}
|
||||
let mut sync_ancestor = false;
|
||||
{
|
||||
let data = parent.subsurface_data.borrow();
|
||||
if let Some(data) = data.as_ref() {
|
||||
sync_ancestor = data.sync_requested || data.sync_ancestor;
|
||||
}
|
||||
}
|
||||
*data = Some(Box::new(SubsurfaceData {
|
||||
subsurface: self.clone(),
|
||||
parent: parent.clone(),
|
||||
sync_requested: false,
|
||||
sync_ancestor,
|
||||
pending: true,
|
||||
}));
|
||||
{
|
||||
let mut data = parent.children.borrow_mut();
|
||||
let data = data.get_or_insert_with(|| Default::default());
|
||||
data.pending_subsurfaces
|
||||
.insert(self.surface.id, self.surface.clone());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_position(&self, parser: MsgParser<'_, '_>) -> Result<(), SetPositionError> {
|
||||
let req: SetPosition = self.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn place_above(&self, parser: MsgParser<'_, '_>) -> Result<(), PlaceAboveError> {
|
||||
let req: PlaceAbove = self.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn place_below(&self, parser: MsgParser<'_, '_>) -> Result<(), PlaceBelowError> {
|
||||
let req: PlaceBelow = self.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_sync(&self, parser: MsgParser<'_, '_>) -> Result<(), SetSyncError> {
|
||||
let _req: SetSync = self.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_desync(&self, parser: MsgParser<'_, '_>) -> Result<(), SetDesyncError> {
|
||||
let _req: SetDesync = self.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlSubsurfaceError> {
|
||||
match request {
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
SET_POSITION => self.set_position(parser).await?,
|
||||
PLACE_ABOVE => self.place_above(parser).await?,
|
||||
PLACE_BELOW => self.place_below(parser).await?,
|
||||
SET_SYNC => self.set_sync(parser).await?,
|
||||
SET_DESYNC => self.set_desync(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlSubsurface);
|
||||
|
||||
impl Object for WlSubsurface {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlSubsurface
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
SET_DESYNC + 1
|
||||
}
|
||||
}
|
||||
158
src/ifs/wl_surface/wl_subsurface/types.rs
Normal file
158
src/ifs/wl_surface/wl_subsurface/types.rs
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
use crate::client::{RequestParser};
|
||||
use crate::ifs::wl_surface::SurfaceType;
|
||||
use crate::object::ObjectId;
|
||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlSubsurfaceError {
|
||||
#[error("Could not process `destroy` request")]
|
||||
DestroyError(#[from] DestroyError),
|
||||
#[error("Could not process `set_position` request")]
|
||||
SetPosition(#[from] SetPositionError),
|
||||
#[error("Could not process `place_above` request")]
|
||||
PlaceAbove(#[from] PlaceAboveError),
|
||||
#[error("Could not process `place_below` request")]
|
||||
PlaceBelow(#[from] PlaceBelowError),
|
||||
#[error("Could not process `set_sync` request")]
|
||||
SetSync(#[from] SetSyncError),
|
||||
#[error("Could not process `set_desync` request")]
|
||||
SetDesync(#[from] SetDesyncError),
|
||||
#[error("Surface {0} cannot be assigned the role `Subsurface` because it already has the role `{1:?}`")]
|
||||
IncompatibleType(ObjectId, SurfaceType),
|
||||
#[error("Surface {0} already has an attached `wl_subsurface`")]
|
||||
AlreadyAttached(ObjectId),
|
||||
#[error("Surface {0} cannot be made its own parent")]
|
||||
OwnParent(ObjectId),
|
||||
#[error("Surface {0} cannot be made a subsurface of {1} because it's an ancestor of {1}")]
|
||||
Ancestor(ObjectId, ObjectId),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DestroyError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(DestroyError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetPositionError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(SetPositionError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum PlaceAboveError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(PlaceAboveError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum PlaceBelowError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(PlaceBelowError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetSyncError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(SetSyncError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetDesyncError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(SetDesyncError, ParseFailed, MsgParserError);
|
||||
|
||||
pub(in crate::ifs) 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(in crate::ifs) struct SetPosition {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
}
|
||||
impl RequestParser<'_> for SetPosition {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
x: parser.int()?,
|
||||
y: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for SetPosition {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "set_position(x: {}, y: {})", self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::ifs) struct PlaceAbove {
|
||||
pub sibling: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for PlaceAbove {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
sibling: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for PlaceAbove {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "place_above(sibling: {})", self.sibling,)
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::ifs) struct PlaceBelow {
|
||||
pub sibling: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for PlaceBelow {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
sibling: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for PlaceBelow {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "place_below(sibling: {})", self.sibling,)
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::ifs) struct SetSync;
|
||||
impl RequestParser<'_> for SetSync {
|
||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
impl Debug for SetSync {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "set_sync()")
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::ifs) struct SetDesync;
|
||||
impl RequestParser<'_> for SetDesync {
|
||||
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
impl Debug for SetDesync {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "set_desync()")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue