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
|
|
@ -2,7 +2,7 @@ mod types;
|
|||
|
||||
use crate::client::{ClientError, DynEventFormatter};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
use types::*;
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ impl WlCallback {
|
|||
async fn handle_request_(
|
||||
&self,
|
||||
_request: u32,
|
||||
_parser: WlParser<'_, '_>,
|
||||
_parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ClientError> {
|
||||
unreachable!();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::client::EventFormatter;
|
||||
use crate::ifs::wl_callback::{WlCallback, DONE};
|
||||
use crate::object::Object;
|
||||
use crate::utils::buffd::WlFormatter;
|
||||
use crate::utils::buffd::MsgFormatter;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ pub(super) struct Done {
|
|||
pub obj: Rc<WlCallback>,
|
||||
}
|
||||
impl EventFormatter for Done {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, DONE).uint(0);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::globals::{Global, GlobalName};
|
|||
use crate::ifs::wl_region::WlRegion;
|
||||
use crate::ifs::wl_surface::WlSurface;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
|
|
@ -46,14 +46,14 @@ impl WlCompositorGlobal {
|
|||
}
|
||||
|
||||
impl WlCompositorObj {
|
||||
async fn create_surface(&self, parser: WlParser<'_, '_>) -> Result<(), CreateSurfaceError> {
|
||||
async fn create_surface(&self, parser: MsgParser<'_, '_>) -> Result<(), CreateSurfaceError> {
|
||||
let surface: CreateSurface = self.client.parse(self, parser)?;
|
||||
let surface = Rc::new(WlSurface::new(surface.id, &self.client));
|
||||
self.client.add_client_obj(&surface)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn create_region(&self, parser: WlParser<'_, '_>) -> Result<(), CreateRegionError> {
|
||||
async fn create_region(&self, parser: MsgParser<'_, '_>) -> Result<(), CreateRegionError> {
|
||||
let region: CreateRegion = self.client.parse(self, parser)?;
|
||||
let region = Rc::new(WlRegion::new(region.id, &self.client));
|
||||
self.client.add_client_obj(®ion)?;
|
||||
|
|
@ -63,7 +63,7 @@ impl WlCompositorObj {
|
|||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlCompositorError> {
|
||||
match request {
|
||||
CREATE_SURFACE => self.create_surface(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;
|
||||
|
||||
|
|
@ -21,30 +21,30 @@ efrom!(WlCompositorError, CreateRegionError, CreateRegionError);
|
|||
#[derive(Debug, Error)]
|
||||
pub enum CreateSurfaceError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
|
||||
efrom!(CreateSurfaceError, ParseFailed, WlParserError);
|
||||
efrom!(CreateSurfaceError, ParseFailed, MsgParserError);
|
||||
efrom!(CreateSurfaceError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CreateRegionError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
|
||||
efrom!(CreateRegionError, ParseFailed, WlParserError);
|
||||
efrom!(CreateRegionError, ParseFailed, MsgParserError);
|
||||
efrom!(CreateRegionError, ClientError, ClientError);
|
||||
|
||||
pub(super) struct CreateSurface {
|
||||
pub id: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for CreateSurface {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
})
|
||||
|
|
@ -60,7 +60,7 @@ pub(super) struct CreateRegion {
|
|||
pub id: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for CreateRegion {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::client::{AddObj, Client, ClientError, DynEventFormatter};
|
|||
use crate::ifs::wl_callback::WlCallback;
|
||||
use crate::ifs::wl_registry::WlRegistry;
|
||||
use crate::object::{Interface, Object, ObjectId, WL_DISPLAY_ID};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ impl WlDisplay {
|
|||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlDisplayError> {
|
||||
match request {
|
||||
SYNC => self.sync(parser).await?,
|
||||
|
|
@ -43,7 +43,7 @@ impl WlDisplay {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn sync(&self, parser: WlParser<'_, '_>) -> Result<(), SyncError> {
|
||||
async fn sync(&self, parser: MsgParser<'_, '_>) -> Result<(), SyncError> {
|
||||
let sync: Sync = self.client.parse(self, parser)?;
|
||||
let cb = Rc::new(WlCallback::new(sync.callback));
|
||||
self.client.add_client_obj(&cb)?;
|
||||
|
|
@ -52,7 +52,7 @@ impl WlDisplay {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_registry(&self, parser: WlParser<'_, '_>) -> Result<(), GetRegistryError> {
|
||||
async fn get_registry(&self, parser: MsgParser<'_, '_>) -> Result<(), GetRegistryError> {
|
||||
let gr: GetRegistry = self.client.parse(self, parser)?;
|
||||
let registry = Rc::new(WlRegistry::new(gr.registry, &self.client));
|
||||
self.client.add_client_obj(®istry)?;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::client::{ClientError, EventFormatter, RequestParser};
|
|||
use crate::globals::GlobalError;
|
||||
use crate::ifs::wl_display::{WlDisplay, DELETE_ID, ERROR};
|
||||
use crate::object::{Object, ObjectId, WL_DISPLAY_ID};
|
||||
use crate::utils::buffd::{WlFormatter, WlParser, WlParserError};
|
||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
|
|
@ -21,33 +21,33 @@ efrom!(WlDisplayError, SyncError, SyncError);
|
|||
#[derive(Debug, Error)]
|
||||
pub enum GetRegistryError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("An error occurred while processing globals")]
|
||||
GlobalError(#[source] Box<GlobalError>),
|
||||
}
|
||||
|
||||
efrom!(GetRegistryError, ParseFailed, WlParserError);
|
||||
efrom!(GetRegistryError, ParseFailed, MsgParserError);
|
||||
efrom!(GetRegistryError, GlobalError, GlobalError);
|
||||
efrom!(GetRegistryError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SyncError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
|
||||
efrom!(SyncError, ParseFailed, WlParserError);
|
||||
efrom!(SyncError, ParseFailed, MsgParserError);
|
||||
efrom!(SyncError, ClientError, ClientError);
|
||||
|
||||
pub(super) struct GetRegistry {
|
||||
pub registry: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for GetRegistry {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
registry: parser.object()?,
|
||||
})
|
||||
|
|
@ -63,7 +63,7 @@ pub(super) struct Sync {
|
|||
pub callback: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for Sync {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
callback: parser.object()?,
|
||||
})
|
||||
|
|
@ -80,7 +80,7 @@ pub(super) struct DeleteId {
|
|||
pub id: ObjectId,
|
||||
}
|
||||
impl EventFormatter for DeleteId {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(WL_DISPLAY_ID, DELETE_ID).object(self.id);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
|
|
@ -100,7 +100,7 @@ pub(super) struct Error {
|
|||
pub message: String,
|
||||
}
|
||||
impl EventFormatter for Error {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(WL_DISPLAY_ID, ERROR)
|
||||
.object(self.object_id)
|
||||
.uint(self.code)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ mod types;
|
|||
use crate::client::{AddObj, Client};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::pixman::Region;
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
|
@ -31,13 +31,13 @@ impl WlRegion {
|
|||
self.rect.borrow().clone()
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: WlParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _destroy: Destroy = self.client.parse(self, parser)?;
|
||||
self.client.remove_obj(self).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn add(&self, parser: WlParser<'_, '_>) -> Result<(), AddError> {
|
||||
async fn add(&self, parser: MsgParser<'_, '_>) -> Result<(), AddError> {
|
||||
let add: Add = self.client.parse(self, parser)?;
|
||||
if add.width < 0 || add.height < 0 {
|
||||
return Err(AddError::NegativeExtents);
|
||||
|
|
@ -47,7 +47,7 @@ impl WlRegion {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn subtract(&self, parser: WlParser<'_, '_>) -> Result<(), SubtractError> {
|
||||
async fn subtract(&self, parser: MsgParser<'_, '_>) -> Result<(), SubtractError> {
|
||||
let subtract: Subtract = self.client.parse(self, parser)?;
|
||||
if subtract.width < 0 || subtract.height < 0 {
|
||||
return Err(SubtractError::NegativeExtents);
|
||||
|
|
@ -65,7 +65,7 @@ impl WlRegion {
|
|||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlRegionError> {
|
||||
match request {
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::client::{ClientError, RequestParser};
|
||||
use crate::utils::buffd::{WlParser, WlParserError};
|
||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
@ -16,34 +16,34 @@ pub enum WlRegionError {
|
|||
#[derive(Debug, Error)]
|
||||
pub enum DestroyError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(DestroyError, ParseFailed, WlParserError);
|
||||
efrom!(DestroyError, ParseFailed, MsgParserError);
|
||||
efrom!(DestroyError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum AddError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error("width and/or height are negative")]
|
||||
NegativeExtents,
|
||||
}
|
||||
efrom!(AddError, ParseFailed, WlParserError);
|
||||
efrom!(AddError, ParseFailed, MsgParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SubtractError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error("width and/or height are negative")]
|
||||
NegativeExtents,
|
||||
}
|
||||
efrom!(SubtractError, ParseFailed, WlParserError);
|
||||
efrom!(SubtractError, 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)
|
||||
}
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ pub(super) struct Add {
|
|||
pub height: i32,
|
||||
}
|
||||
impl RequestParser<'_> for Add {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
x: parser.int()?,
|
||||
y: parser.int()?,
|
||||
|
|
@ -86,7 +86,7 @@ pub(super) struct Subtract {
|
|||
pub height: i32,
|
||||
}
|
||||
impl RequestParser<'_> for Subtract {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
x: parser.int()?,
|
||||
y: parser.int()?,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ mod types;
|
|||
use crate::client::{Client, DynEventFormatter};
|
||||
use crate::globals::{Global, GlobalName};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ impl WlRegistry {
|
|||
})
|
||||
}
|
||||
|
||||
async fn bind(&self, parser: WlParser<'_, '_>) -> Result<(), BindError> {
|
||||
async fn bind(&self, parser: MsgParser<'_, '_>) -> Result<(), BindError> {
|
||||
let bind: Bind = self.client.parse(self, parser)?;
|
||||
let global = self.client.state.globals.get(bind.name)?;
|
||||
if global.interface().name() != bind.interface {
|
||||
|
|
@ -64,7 +64,7 @@ impl WlRegistry {
|
|||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlRegistryError> {
|
||||
match request {
|
||||
BIND => self.bind(parser).await?,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::client::{EventFormatter, RequestParser};
|
|||
use crate::globals::{Global, GlobalError, GlobalName};
|
||||
use crate::ifs::wl_registry::{WlRegistry, GLOBAL, GLOBAL_REMOVE};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::{WlFormatter, WlParser, WlParserError};
|
||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
|
|
@ -18,7 +18,7 @@ efrom!(WlRegistryError, BindError, BindError);
|
|||
#[derive(Debug, Error)]
|
||||
pub enum BindError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
GlobalError(Box<GlobalError>),
|
||||
#[error("Tried to bind to global {} of type {} using interface {}", .0.name, .0.interface.name(), .0.actual)]
|
||||
|
|
@ -42,7 +42,7 @@ pub struct VersionError {
|
|||
pub actual: u32,
|
||||
}
|
||||
|
||||
efrom!(BindError, ParseError, WlParserError);
|
||||
efrom!(BindError, ParseError, MsgParserError);
|
||||
efrom!(BindError, GlobalError, GlobalError);
|
||||
|
||||
pub(super) struct GlobalE {
|
||||
|
|
@ -50,7 +50,7 @@ pub(super) struct GlobalE {
|
|||
pub global: Rc<dyn Global>,
|
||||
}
|
||||
impl EventFormatter for GlobalE {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, GLOBAL)
|
||||
.uint(self.global.name().raw())
|
||||
.string(self.global.interface().name())
|
||||
|
|
@ -77,7 +77,7 @@ pub(super) struct GlobalRemove {
|
|||
pub name: GlobalName,
|
||||
}
|
||||
impl EventFormatter for GlobalRemove {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, GLOBAL_REMOVE).uint(self.name.raw());
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
|
|
@ -97,7 +97,7 @@ pub(super) struct Bind<'a> {
|
|||
pub version: u32,
|
||||
}
|
||||
impl<'a> RequestParser<'a> for Bind<'a> {
|
||||
fn parse(parser: &mut WlParser<'_, 'a>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
name: parser.global()?,
|
||||
interface: parser.string()?,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::client::{AddObj, Client};
|
|||
use crate::globals::{Global, GlobalName};
|
||||
use crate::ifs::wl_shm_pool::WlShmPool;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ impl WlShmGlobal {
|
|||
}
|
||||
|
||||
impl WlShmObj {
|
||||
async fn create_pool(&self, parser: WlParser<'_, '_>) -> Result<(), CreatePoolError> {
|
||||
async fn create_pool(&self, parser: MsgParser<'_, '_>) -> Result<(), CreatePoolError> {
|
||||
let create: CreatePool = self.client.parse(self, parser)?;
|
||||
if create.size < 0 {
|
||||
return Err(CreatePoolError::NegativeSize);
|
||||
|
|
@ -70,7 +70,7 @@ impl WlShmObj {
|
|||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlShmError> {
|
||||
match request {
|
||||
CREATE_POOL => self.create_pool(parser).await?,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::client::{ClientError, EventFormatter, RequestParser};
|
|||
use crate::ifs::wl_shm::{Format, WlShmObj, FORMAT};
|
||||
use crate::ifs::wl_shm_pool::WlShmPoolError;
|
||||
use crate::object::{Object, ObjectId};
|
||||
use crate::utils::buffd::{WlFormatter, WlParser, WlParserError};
|
||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
|
|
@ -20,7 +20,7 @@ efrom!(WlShmError, ClientError, ClientError);
|
|||
#[derive(Debug, Error)]
|
||||
pub enum CreatePoolError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error("The passed size is negative")]
|
||||
NegativeSize,
|
||||
#[error(transparent)]
|
||||
|
|
@ -28,7 +28,7 @@ pub enum CreatePoolError {
|
|||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(CreatePoolError, ParseError, WlParserError);
|
||||
efrom!(CreatePoolError, ParseError, MsgParserError);
|
||||
efrom!(CreatePoolError, WlShmPoolError, WlShmPoolError);
|
||||
efrom!(CreatePoolError, ClientError, ClientError);
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ pub(super) struct CreatePool {
|
|||
pub size: i32,
|
||||
}
|
||||
impl RequestParser<'_> for CreatePool {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
fd: parser.fd()?,
|
||||
|
|
@ -63,7 +63,7 @@ pub(super) struct FormatE {
|
|||
pub format: Format,
|
||||
}
|
||||
impl EventFormatter for FormatE {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, FORMAT).uint(self.format.uint());
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ mod types;
|
|||
use crate::client::{AddObj, Client};
|
||||
use crate::clientmem::ClientMem;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
|
@ -35,18 +35,18 @@ impl WlShmPool {
|
|||
})
|
||||
}
|
||||
|
||||
async fn create_buffer(&self, parser: WlParser<'_, '_>) -> Result<(), CreateBufferError> {
|
||||
async fn create_buffer(&self, parser: MsgParser<'_, '_>) -> Result<(), CreateBufferError> {
|
||||
let create: CreateBuffer = self.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: WlParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _destroy: Destroy = self.client.parse(self, parser)?;
|
||||
self.client.remove_obj(self).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn resize(&self, parser: WlParser<'_, '_>) -> Result<(), ResizeError> {
|
||||
async fn resize(&self, parser: MsgParser<'_, '_>) -> Result<(), ResizeError> {
|
||||
let resize: Resize = self.client.parse(self, parser)?;
|
||||
let mut mem = self.mem.borrow_mut();
|
||||
if resize.size < 0 {
|
||||
|
|
@ -62,7 +62,7 @@ impl WlShmPool {
|
|||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlShmPoolError> {
|
||||
match request {
|
||||
CREATE_BUFFER => self.create_buffer(parser).await?,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::client::{ClientError, RequestParser};
|
||||
use crate::clientmem::ClientMemError;
|
||||
use crate::object::ObjectId;
|
||||
use crate::utils::buffd::{WlParser, WlParserError};
|
||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
@ -24,27 +24,27 @@ efrom!(WlShmPoolError, ClientMemError, ClientMemError);
|
|||
#[derive(Debug, Error)]
|
||||
pub enum CreateBufferError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(CreateBufferError, ParseError, WlParserError);
|
||||
efrom!(CreateBufferError, ParseError, MsgParserError);
|
||||
efrom!(CreateBufferError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DestroyError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(DestroyError, ParseError, WlParserError);
|
||||
efrom!(DestroyError, ParseError, MsgParserError);
|
||||
efrom!(DestroyError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ResizeError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error("Tried to shrink the pool")]
|
||||
CannotShrink,
|
||||
#[error("Requested size is negative")]
|
||||
|
|
@ -52,7 +52,7 @@ pub enum ResizeError {
|
|||
#[error(transparent)]
|
||||
ClientMemError(Box<ClientMemError>),
|
||||
}
|
||||
efrom!(ResizeError, ParseError, WlParserError);
|
||||
efrom!(ResizeError, ParseError, MsgParserError);
|
||||
efrom!(ResizeError, ClientMemError, ClientMemError);
|
||||
|
||||
pub(super) struct CreateBuffer {
|
||||
|
|
@ -64,7 +64,7 @@ pub(super) struct CreateBuffer {
|
|||
pub format: u32,
|
||||
}
|
||||
impl RequestParser<'_> for CreateBuffer {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
offset: parser.int()?,
|
||||
|
|
@ -87,7 +87,7 @@ impl Debug for CreateBuffer {
|
|||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ pub(super) struct Resize {
|
|||
pub size: i32,
|
||||
}
|
||||
impl RequestParser<'_> for Resize {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
size: parser.int()?,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,12 +1,18 @@
|
|||
mod types;
|
||||
|
||||
use crate::client::{AddObj, Client, ClientError};
|
||||
use crate::client::{AddObj, Client};
|
||||
use crate::globals::{Global, GlobalName};
|
||||
use crate::ifs::wl_surface::wl_subsurface::WlSubsurface;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const GET_SUBSURFACE: u32 = 1;
|
||||
|
||||
const BAD_SURFACE: u32 = 0;
|
||||
|
||||
pub struct WlSubcompositorGlobal {
|
||||
name: GlobalName,
|
||||
}
|
||||
|
|
@ -14,6 +20,7 @@ pub struct WlSubcompositorGlobal {
|
|||
pub struct WlSubcompositorObj {
|
||||
global: Rc<WlSubcompositorGlobal>,
|
||||
id: ObjectId,
|
||||
client: Rc<Client>,
|
||||
}
|
||||
|
||||
impl WlSubcompositorGlobal {
|
||||
|
|
@ -24,22 +31,47 @@ impl WlSubcompositorGlobal {
|
|||
async fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: ObjectId,
|
||||
client: &Client,
|
||||
client: &Rc<Client>,
|
||||
_version: u32,
|
||||
) -> Result<(), WlSubcompositorError> {
|
||||
let obj = Rc::new(WlSubcompositorObj { global: self, id });
|
||||
let obj = Rc::new(WlSubcompositorObj {
|
||||
global: self,
|
||||
id,
|
||||
client: client.clone(),
|
||||
});
|
||||
client.add_client_obj(&obj)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl WlSubcompositorObj {
|
||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.client.parse(self, parser)?;
|
||||
self.client.remove_obj(self).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_subsurface(&self, parser: MsgParser<'_, '_>) -> Result<(), GetSubsurfaceError> {
|
||||
let req: GetSubsurface = self.client.parse(self, parser)?;
|
||||
let surface = self.client.get_surface(req.surface)?;
|
||||
let parent = self.client.get_surface(req.parent)?;
|
||||
let subsurface = Rc::new(WlSubsurface::new(req.id, &surface));
|
||||
self.client.add_client_obj(&subsurface)?;
|
||||
subsurface.install(&parent)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
self: &Rc<Self>,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), ClientError> {
|
||||
unreachable!();
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), WlSubcompositorError> {
|
||||
match request {
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
GET_SUBSURFACE => self.get_subsurface(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,6 +107,6 @@ impl Object for WlSubcompositorObj {
|
|||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
0
|
||||
GET_SUBSURFACE + 1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,76 @@
|
|||
use crate::client::ClientError;
|
||||
use crate::client::{ClientError, RequestParser};
|
||||
use crate::ifs::wl_surface::wl_subsurface::WlSubsurfaceError;
|
||||
use crate::object::ObjectId;
|
||||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlSubcompositorError {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("Could not process `destroy` request")]
|
||||
DestroyError(#[from] DestroyError),
|
||||
#[error("Could not process `get_subsurface` request")]
|
||||
GetSubsurfaceError(#[from] GetSubsurfaceError),
|
||||
}
|
||||
efrom!(WlSubcompositorError, ClientError, ClientError);
|
||||
|
||||
#[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);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GetSubsurfaceError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error(transparent)]
|
||||
SubsurfaceError(Box<WlSubsurfaceError>),
|
||||
}
|
||||
efrom!(GetSubsurfaceError, ParseFailed, MsgParserError);
|
||||
efrom!(GetSubsurfaceError, ClientError, ClientError);
|
||||
efrom!(GetSubsurfaceError, SubsurfaceError, WlSubsurfaceError);
|
||||
|
||||
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()")
|
||||
}
|
||||
}
|
||||
|
||||
efrom!(WlSubcompositorError, ClientError, ClientError);
|
||||
pub(super) struct GetSubsurface {
|
||||
pub id: ObjectId,
|
||||
pub surface: ObjectId,
|
||||
pub parent: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for GetSubsurface {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
surface: parser.object()?,
|
||||
parent: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for GetSubsurface {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"get_subsurface(id: {}, surface: {}, parent: {})",
|
||||
self.id, self.surface, self.parent,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()")
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ mod types;
|
|||
use crate::client::{AddObj, Client, ClientError};
|
||||
use crate::globals::{Global, GlobalName};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ impl XdgWmBaseObj {
|
|||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ClientError> {
|
||||
unreachable!();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue