1
0
Fork 0
forked from wry/wry

wire: generate trait for request handling

This commit is contained in:
Julian Orth 2024-04-08 17:37:35 +02:00
parent e3a1a0b30f
commit acb391335b
102 changed files with 1632 additions and 2086 deletions

View file

@ -4,10 +4,7 @@ use {
ifs::wl_seat::WlSeat,
leaks::Tracker,
object::{Object, Version},
utils::{
buffd::{MsgParser, MsgParserError},
oserror::OsError,
},
utils::oserror::OsError,
wire::{wl_keyboard::*, WlKeyboardId, WlSurfaceId},
},
std::rc::Rc,
@ -100,9 +97,12 @@ impl WlKeyboard {
delay,
})
}
}
fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), WlKeyboardError> {
let _req: Release = self.seat.client.parse(self, parser)?;
impl WlKeyboardRequestHandler for WlKeyboard {
type Error = WlKeyboardError;
fn release(&self, _req: Release, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.seat.keyboards.remove(&self.id);
self.seat.client.remove_obj(self)?;
Ok(())
@ -111,8 +111,7 @@ impl WlKeyboard {
object_base! {
self = WlKeyboard;
RELEASE => release if self.seat.version >= 3,
version = self.seat.version;
}
impl Object for WlKeyboard {}
@ -127,8 +126,5 @@ pub enum WlKeyboardError {
KeymapMemfd(#[source] OsError),
#[error("Could not copy the keymap")]
KeymapCopy(#[source] OsError),
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
}
efrom!(WlKeyboardError, ClientError);
efrom!(WlKeyboardError, MsgParserError);

View file

@ -6,7 +6,6 @@ use {
ifs::{wl_seat::WlSeat, wl_surface::WlSurfaceError},
leaks::Tracker,
object::{Object, Version},
utils::buffd::{MsgParser, MsgParserError},
wire::{wl_pointer::*, WlPointerId, WlSurfaceId},
},
std::{cell::Cell, rc::Rc},
@ -174,9 +173,12 @@ impl WlPointer {
value120,
})
}
}
fn set_cursor(&self, parser: MsgParser<'_, '_>) -> Result<(), WlPointerError> {
let req: SetCursor = self.seat.client.parse(self, parser)?;
impl WlPointerRequestHandler for WlPointer {
type Error = WlPointerError;
fn set_cursor(&self, req: SetCursor, _slf: &Rc<Self>) -> Result<(), Self::Error> {
if !self.seat.client.valid_serial(req.serial) {
log::warn!("Client tried to set_cursor with an invalid serial");
return Ok(());
@ -213,8 +215,7 @@ impl WlPointer {
Ok(())
}
fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), WlPointerError> {
let _req: Release = self.seat.client.parse(self, parser)?;
fn release(&self, _req: Release, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.seat.pointers.remove(&self.id);
self.seat.client.remove_obj(self)?;
Ok(())
@ -223,9 +224,7 @@ impl WlPointer {
object_base! {
self = WlPointer;
SET_CURSOR => set_cursor,
RELEASE => release if self.seat.version >= 3,
version = self.seat.version;
}
impl Object for WlPointer {}
@ -236,11 +235,8 @@ dedicated_add_obj!(WlPointer, WlPointerId, pointers);
pub enum WlPointerError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
WlSurfaceError(Box<WlSurfaceError>),
}
efrom!(WlPointerError, ClientError);
efrom!(WlPointerError, MsgParserError);
efrom!(WlPointerError, WlSurfaceError);

View file

@ -4,7 +4,6 @@ use {
ifs::wl_seat::WlSeat,
leaks::Tracker,
object::Object,
utils::buffd::{MsgParser, MsgParserError},
wire::{wl_touch::*, WlTouchId},
},
std::rc::Rc,
@ -40,9 +39,12 @@ impl WlTouch {
tracker: Default::default(),
}
}
}
fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), WlTouchError> {
let _req: Release = self.seat.client.parse(self, parser)?;
impl WlTouchRequestHandler for WlTouch {
type Error = WlTouchError;
fn release(&self, _req: Release, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.seat.client.remove_obj(self)?;
Ok(())
}
@ -50,8 +52,7 @@ impl WlTouch {
object_base! {
self = WlTouch;
RELEASE => release if self.seat.version >= 3,
version = self.seat.version;
}
impl Object for WlTouch {}
@ -62,8 +63,5 @@ simple_add_obj!(WlTouch);
pub enum WlTouchError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
}
efrom!(WlTouchError, ClientError);
efrom!(WlTouchError, MsgParserError);

View file

@ -13,10 +13,7 @@ use {
leaks::Tracker,
object::{Object, Version},
rect::Region,
utils::{
buffd::{MsgParser, MsgParserError},
clonecell::CloneCell,
},
utils::clonecell::CloneCell,
wire::{
zwp_pointer_constraints_v1::*, WlPointerId, WlRegionId, WlSurfaceId,
ZwpPointerConstraintsV1Id,
@ -38,6 +35,7 @@ pub struct ZwpPointerConstraintsV1 {
pub id: ZwpPointerConstraintsV1Id,
pub client: Rc<Client>,
pub tracker: Tracker<Self>,
pub version: Version,
}
#[derive(Copy, Clone, Eq, PartialEq)]
@ -154,12 +152,13 @@ impl ZwpPointerConstraintsV1Global {
self: Rc<Self>,
id: ZwpPointerConstraintsV1Id,
client: &Rc<Client>,
_version: Version,
version: Version,
) -> Result<(), ZwpPointerConstraintsV1Error> {
let cs = Rc::new(ZwpPointerConstraintsV1 {
id,
client: client.clone(),
tracker: Default::default(),
version,
});
track!(client, cs);
client.add_client_obj(&cs)?;
@ -168,12 +167,6 @@ impl ZwpPointerConstraintsV1Global {
}
impl ZwpPointerConstraintsV1 {
fn destroy(&self, msg: MsgParser<'_, '_>) -> Result<(), ZwpPointerConstraintsV1Error> {
let _req: Destroy = self.client.parse(self, msg)?;
self.client.remove_obj(self)?;
Ok(())
}
fn create_constraint(
&self,
ty: ConstraintType,
@ -209,9 +202,17 @@ impl ZwpPointerConstraintsV1 {
ty,
}))
}
}
fn lock_pointer(&self, msg: MsgParser<'_, '_>) -> Result<(), ZwpPointerConstraintsV1Error> {
let req: LockPointer = self.client.parse(self, msg)?;
impl ZwpPointerConstraintsV1RequestHandler for ZwpPointerConstraintsV1 {
type Error = ZwpPointerConstraintsV1Error;
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client.remove_obj(self)?;
Ok(())
}
fn lock_pointer(&self, req: LockPointer, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let constraint = self.create_constraint(
ConstraintType::Lock,
req.pointer,
@ -223,6 +224,7 @@ impl ZwpPointerConstraintsV1 {
id: req.id,
tracker: Default::default(),
constraint,
version: self.version,
});
self.client.add_client_obj(&lp)?;
lp.constraint.owner.set(Some(lp.clone()));
@ -234,8 +236,7 @@ impl ZwpPointerConstraintsV1 {
Ok(())
}
fn confine_pointer(&self, msg: MsgParser<'_, '_>) -> Result<(), ZwpPointerConstraintsV1Error> {
let req: ConfinePointer = self.client.parse(self, msg)?;
fn confine_pointer(&self, req: ConfinePointer, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let constraint = self.create_constraint(
ConstraintType::Confine,
req.pointer,
@ -247,6 +248,7 @@ impl ZwpPointerConstraintsV1 {
id: req.id,
tracker: Default::default(),
constraint,
version: self.version,
});
self.client.add_client_obj(&lp)?;
lp.constraint.owner.set(Some(lp.clone()));
@ -279,10 +281,7 @@ simple_add_global!(ZwpPointerConstraintsV1Global);
object_base! {
self = ZwpPointerConstraintsV1;
DESTROY => destroy,
LOCK_POINTER => lock_pointer,
CONFINE_POINTER => confine_pointer,
version = self.version;
}
impl Object for ZwpPointerConstraintsV1 {}
@ -293,12 +292,9 @@ simple_add_obj!(ZwpPointerConstraintsV1);
pub enum ZwpPointerConstraintsV1Error {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error("The surface already has a constraint attached for the seat")]
AlreadyConstrained,
#[error("The constraint lifetime {0} is unknown")]
UnknownLifetime(u32),
}
efrom!(ZwpPointerConstraintsV1Error, ClientError);
efrom!(ZwpPointerConstraintsV1Error, MsgParserError);

View file

@ -5,8 +5,7 @@ use {
ConstraintOwner, SeatConstraint, ZwpPointerConstraintsV1Error,
},
leaks::Tracker,
object::Object,
utils::buffd::{MsgParser, MsgParserError},
object::{Object, Version},
wire::{zwp_confined_pointer_v1::*, ZwpConfinedPointerV1Id},
},
std::rc::Rc,
@ -17,18 +16,19 @@ pub struct ZwpConfinedPointerV1 {
pub id: ZwpConfinedPointerV1Id,
pub tracker: Tracker<Self>,
pub constraint: Rc<SeatConstraint>,
pub version: Version,
}
impl ZwpConfinedPointerV1 {
fn destroy(&self, msg: MsgParser<'_, '_>) -> Result<(), ZwpConfinedPointerV1Error> {
let _req: Destroy = self.constraint.client.parse(self, msg)?;
impl ZwpConfinedPointerV1RequestHandler for ZwpConfinedPointerV1 {
type Error = ZwpConfinedPointerV1Error;
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.constraint.detach();
self.constraint.client.remove_obj(self)?;
Ok(())
}
fn set_region(&self, msg: MsgParser<'_, '_>) -> Result<(), ZwpConfinedPointerV1Error> {
let req: SetRegion = self.constraint.client.parse(self, msg)?;
fn set_region(&self, req: SetRegion, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.constraint.set_region(req.region)?;
Ok(())
}
@ -48,9 +48,7 @@ impl ConstraintOwner for ZwpConfinedPointerV1 {
object_base! {
self = ZwpConfinedPointerV1;
DESTROY => destroy,
SET_REGION => set_region,
version = self.version;
}
impl Object for ZwpConfinedPointerV1 {
@ -65,10 +63,7 @@ simple_add_obj!(ZwpConfinedPointerV1);
pub enum ZwpConfinedPointerV1Error {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
ZwpPointerConstraintsV1Error(#[from] ZwpPointerConstraintsV1Error),
}
efrom!(ZwpConfinedPointerV1Error, ClientError);
efrom!(ZwpConfinedPointerV1Error, MsgParserError);

View file

@ -5,8 +5,7 @@ use {
ConstraintOwner, SeatConstraint, ZwpPointerConstraintsV1Error,
},
leaks::Tracker,
object::Object,
utils::buffd::{MsgParser, MsgParserError},
object::{Object, Version},
wire::{zwp_locked_pointer_v1::*, ZwpLockedPointerV1Id},
},
std::rc::Rc,
@ -17,11 +16,13 @@ pub struct ZwpLockedPointerV1 {
pub id: ZwpLockedPointerV1Id,
pub tracker: Tracker<Self>,
pub constraint: Rc<SeatConstraint>,
pub version: Version,
}
impl ZwpLockedPointerV1 {
fn destroy(&self, msg: MsgParser<'_, '_>) -> Result<(), ZwpLockedPointerV1Error> {
let _req: Destroy = self.constraint.client.parse(self, msg)?;
impl ZwpLockedPointerV1RequestHandler for ZwpLockedPointerV1 {
type Error = ZwpLockedPointerV1Error;
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.constraint.detach();
self.constraint.client.remove_obj(self)?;
Ok(())
@ -29,14 +30,13 @@ impl ZwpLockedPointerV1 {
fn set_cursor_position_hint(
&self,
msg: MsgParser<'_, '_>,
) -> Result<(), ZwpLockedPointerV1Error> {
let _req: SetCursorPositionHint = self.constraint.client.parse(self, msg)?;
_req: SetCursorPositionHint,
_slf: &Rc<Self>,
) -> Result<(), Self::Error> {
Ok(())
}
fn set_region(&self, msg: MsgParser<'_, '_>) -> Result<(), ZwpLockedPointerV1Error> {
let req: SetRegion = self.constraint.client.parse(self, msg)?;
fn set_region(&self, req: SetRegion, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.constraint.set_region(req.region)?;
Ok(())
}
@ -54,10 +54,7 @@ impl ConstraintOwner for ZwpLockedPointerV1 {
object_base! {
self = ZwpLockedPointerV1;
DESTROY => destroy,
SET_CURSOR_POSITION_HINT => set_cursor_position_hint,
SET_REGION => set_region,
version = self.version;
}
impl Object for ZwpLockedPointerV1 {
@ -72,10 +69,7 @@ simple_add_obj!(ZwpLockedPointerV1);
pub enum ZwpLockedPointerV1Error {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
ZwpPointerConstraintsV1Error(#[from] ZwpPointerConstraintsV1Error),
}
efrom!(ZwpLockedPointerV1Error, ClientError);
efrom!(ZwpLockedPointerV1Error, MsgParserError);

View file

@ -5,7 +5,6 @@ use {
ifs::wl_seat::zwp_relative_pointer_v1::ZwpRelativePointerV1,
leaks::Tracker,
object::{Object, Version},
utils::buffd::{MsgParser, MsgParserError},
wire::{zwp_relative_pointer_manager_v1::*, ZwpRelativePointerManagerV1Id},
},
std::rc::Rc,
@ -20,6 +19,7 @@ pub struct ZwpRelativePointerManagerV1 {
pub id: ZwpRelativePointerManagerV1Id,
pub client: Rc<Client>,
pub tracker: Tracker<Self>,
pub version: Version,
}
impl ZwpRelativePointerManagerV1Global {
@ -31,12 +31,13 @@ impl ZwpRelativePointerManagerV1Global {
self: Rc<Self>,
id: ZwpRelativePointerManagerV1Id,
client: &Rc<Client>,
_version: Version,
version: Version,
) -> Result<(), ZwpRelativePointerManagerV1Error> {
let obj = Rc::new(ZwpRelativePointerManagerV1 {
id,
client: client.clone(),
tracker: Default::default(),
version,
});
track!(client, obj);
client.add_client_obj(&obj)?;
@ -62,24 +63,26 @@ impl Global for ZwpRelativePointerManagerV1Global {
simple_add_global!(ZwpRelativePointerManagerV1Global);
impl ZwpRelativePointerManagerV1 {
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwpRelativePointerManagerV1Error> {
let _req: Destroy = self.client.parse(self, parser)?;
impl ZwpRelativePointerManagerV1RequestHandler for ZwpRelativePointerManagerV1 {
type Error = ZwpRelativePointerManagerV1Error;
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client.remove_obj(self)?;
Ok(())
}
fn get_relative_pointer(
&self,
parser: MsgParser<'_, '_>,
) -> Result<(), ZwpRelativePointerManagerV1Error> {
let req: GetRelativePointer = self.client.parse(self, parser)?;
req: GetRelativePointer,
_slf: &Rc<Self>,
) -> Result<(), Self::Error> {
let pointer = self.client.lookup(req.pointer)?;
let rp = Rc::new(ZwpRelativePointerV1 {
id: req.id,
client: self.client.clone(),
seat: pointer.seat.clone(),
tracker: Default::default(),
version: self.version,
});
track!(self.client, rp);
self.client.add_client_obj(&rp)?;
@ -90,9 +93,7 @@ impl ZwpRelativePointerManagerV1 {
object_base! {
self = ZwpRelativePointerManagerV1;
DESTROY => destroy,
GET_RELATIVE_POINTER => get_relative_pointer,
version = self.version;
}
impl Object for ZwpRelativePointerManagerV1 {}
@ -101,10 +102,7 @@ simple_add_obj!(ZwpRelativePointerManagerV1);
#[derive(Debug, Error)]
pub enum ZwpRelativePointerManagerV1Error {
#[error("Parsing failed")]
MsgParserError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(ZwpRelativePointerManagerV1Error, MsgParserError);
efrom!(ZwpRelativePointerManagerV1Error, ClientError);

View file

@ -4,8 +4,7 @@ use {
fixed::Fixed,
ifs::wl_seat::WlSeat,
leaks::Tracker,
object::Object,
utils::buffd::{MsgParser, MsgParserError},
object::{Object, Version},
wire::{zwp_relative_pointer_v1::*, ZwpRelativePointerV1Id},
},
std::rc::Rc,
@ -17,6 +16,7 @@ pub struct ZwpRelativePointerV1 {
pub client: Rc<Client>,
pub seat: Rc<WlSeat>,
pub tracker: Tracker<Self>,
pub version: Version,
}
impl ZwpRelativePointerV1 {
@ -38,9 +38,12 @@ impl ZwpRelativePointerV1 {
dy_unaccelerated,
});
}
}
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwpRelativePointerV1Error> {
let _req: Destroy = self.client.parse(self, parser)?;
impl ZwpRelativePointerV1RequestHandler for ZwpRelativePointerV1 {
type Error = ZwpRelativePointerV1Error;
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.seat.relative_pointers.remove(&self.id);
self.client.remove_obj(self)?;
Ok(())
@ -49,8 +52,7 @@ impl ZwpRelativePointerV1 {
object_base! {
self = ZwpRelativePointerV1;
DESTROY => destroy,
version = self.version;
}
impl Object for ZwpRelativePointerV1 {}
@ -61,8 +63,5 @@ simple_add_obj!(ZwpRelativePointerV1);
pub enum ZwpRelativePointerV1Error {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Parsing failed")]
MsgParserError(Box<MsgParserError>),
}
efrom!(ZwpRelativePointerV1Error, ClientError);
efrom!(ZwpRelativePointerV1Error, MsgParserError);