diff --git a/build/tokens.rs b/build/tokens.rs index a3c5987e..67be37fc 100644 --- a/build/tokens.rs +++ b/build/tokens.rs @@ -1,6 +1,6 @@ use { anyhow::{bail, Context, Result}, - bstr::{BStr, BString, ByteSlice}, + bstr::{BString, ByteSlice}, }; #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -54,14 +54,14 @@ pub struct Token<'a> { #[derive(Debug, Eq, PartialEq)] pub enum TokenKind<'a> { - Ident(&'a BStr), + Ident(&'a str), Num(u32), Tree { delim: TreeDelim, body: Vec>, }, Symbol(Symbol), - String(BString), + String(String), } impl TokenKind<'_> { @@ -148,7 +148,7 @@ impl<'a> Tokenizer<'a> { { c.pos += 1; } - TokenKind::Ident(c.s[b_pos..c.pos].as_bstr()) + TokenKind::Ident(c.s[b_pos..c.pos].as_bstr().to_str()?) } b'0'..=b'9' => { c.pos -= 1; @@ -201,7 +201,7 @@ impl<'a> Tokenizer<'a> { bail!("Unterminated string in line {}", self.line); } c.pos += 1; - TokenKind::String(res.into()) + TokenKind::String(BString::from(res).to_string()) } _ => bail!("Unexpected byte {:?} in line {}", b as char, self.line), }; diff --git a/build/wire.rs b/build/wire.rs index f6d1979e..330d2500 100644 --- a/build/wire.rs +++ b/build/wire.rs @@ -330,6 +330,9 @@ impl<'a> Parser<'a> { }); let safe_name = match name { "move" => "move_", + "type" => "type_", + "drop" => "drop_", + "id" => "id_", _ => name, }; Ok(Lined { @@ -717,18 +720,50 @@ fn write_message(f: &mut W, obj: &str, message: &Message) -> Result<() Ok(()) } +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +enum RequestHandlerDirection { + Request, + Event, +} + fn write_request_handler( f: &mut W, camel_obj_name: &str, - messages: &ParseResult, + messages: &[Lined], + direction: RequestHandlerDirection, ) -> Result<()> { + let snake_direction; + let camel_direction; + let parent; + let parser; + let error; + let param; writeln!(f)?; + match direction { + RequestHandlerDirection::Request => { + snake_direction = "request"; + camel_direction = "Request"; + parent = "crate::object::Object"; + parser = "crate::client::Client"; + error = "crate::client::ClientError"; + param = "req"; + } + RequestHandlerDirection::Event => { + snake_direction = "event"; + camel_direction = "Event"; + parent = "crate::wl_usr::usr_object::UsrObject"; + parser = "crate::wl_usr::UsrCon"; + error = "crate::wl_usr::UsrConError"; + param = "ev"; + writeln!(f, " #[allow(dead_code)]")?; + } + } writeln!( f, - " pub trait {camel_obj_name}RequestHandler: crate::object::Object + Sized {{" + " pub trait {camel_obj_name}{camel_direction}Handler: {parent} + Sized {{" )?; writeln!(f, " type Error: std::error::Error;")?; - for message in &messages.requests { + for message in messages { let msg = &message.val; let lt = match msg.has_reference_type { true => "<'_>", @@ -737,34 +772,31 @@ fn write_request_handler( writeln!(f)?; writeln!( f, - " fn {}(&self, req: {}{lt}, _slf: &Rc) -> Result<(), Self::Error>;", + " fn {}(&self, {param}: {}{lt}, _slf: &Rc) -> Result<(), Self::Error>;", msg.safe_name, msg.camel_name )?; } writeln!(f)?; writeln!(f, " #[inline(always)]")?; - writeln!(f, " fn handle_request_impl(")?; + writeln!(f, " fn handle_{snake_direction}_impl(")?; writeln!(f, " self: Rc,")?; - writeln!(f, " client: &crate::client::Client,")?; + writeln!(f, " client: &{parser},")?; writeln!(f, " req: u32,")?; writeln!( f, " parser: crate::utils::buffd::MsgParser<'_, '_>," )?; - writeln!(f, " ) -> Result<(), crate::client::ClientError> {{")?; - if messages.requests.is_empty() { + writeln!(f, " ) -> Result<(), {error}> {{")?; + if messages.is_empty() { writeln!(f, " #![allow(unused_variables)]")?; - writeln!( - f, - " Err(crate::client::ClientError::InvalidMethod)" - )?; + writeln!(f, " Err({error}::InvalidMethod)")?; } else { writeln!(f, " let method;")?; writeln!( f, " let error: Box = match req {{" )?; - for message in &messages.requests { + for message in messages { let msg = &message.val; write!(f, " {} ", msg.id)?; if let Some(since) = msg.attribs.since { @@ -793,13 +825,10 @@ fn write_request_handler( } writeln!( f, - " _ => return Err(crate::client::ClientError::InvalidMethod)," + " _ => return Err({error}::InvalidMethod)," )?; writeln!(f, " }};")?; - writeln!( - f, - " Err(crate::client::ClientError::MethodError {{" - )?; + writeln!(f, " Err({error}::MethodError {{")?; writeln!(f, " interface: {camel_obj_name},")?; writeln!(f, " method,")?; writeln!(f, " error,")?; @@ -832,7 +861,18 @@ fn write_file(f: &mut W, file: &DirEntry) -> Result<()> { for message in messages.requests.iter().chain(messages.events.iter()) { write_message(f, &camel_obj_name, &message.val)?; } - write_request_handler(f, &camel_obj_name, &messages)?; + write_request_handler( + f, + &camel_obj_name, + &messages.requests, + RequestHandlerDirection::Request, + )?; + write_request_handler( + f, + &camel_obj_name, + &messages.events, + RequestHandlerDirection::Event, + )?; writeln!(f, "}}")?; Ok(()) } diff --git a/build/wire_dbus.rs b/build/wire_dbus.rs index 0336ce06..5a1de8bf 100644 --- a/build/wire_dbus.rs +++ b/build/wire_dbus.rs @@ -35,26 +35,26 @@ enum Type { #[derive(Debug)] struct Field { - name: BString, + name: String, ty: Type, } #[derive(Debug)] struct Function { - name: BString, + name: String, in_fields: Vec, out_fields: Vec, } #[derive(Debug)] struct Property { - name: BString, + name: String, ty: Type, } #[derive(Debug)] struct Signal { - name: BString, + name: String, fields: Vec, } @@ -181,7 +181,7 @@ impl<'a> Parser<'a> { res.with_context(|| format!("While parsing field starting at line {}", line)) } - fn expect_ident(&mut self) -> Result<(u32, &'a BStr)> { + fn expect_ident(&mut self) -> Result<(u32, &'a str)> { self.not_eof()?; let token = &self.tokens[self.pos]; self.pos += 1; @@ -468,7 +468,7 @@ fn write_type2(f: &mut W, lt: &str, ty: &Type) -> Result<()> { fn write_message( f: &mut W, el: &Element, - msg_name: &BStr, + msg_name: &str, name: &str, indent: &str, fields: &[Field], @@ -614,7 +614,7 @@ fn write_signal(f: &mut W, element: &Element, sig: &Signal, indent: &s write_message( f, element, - sig.name.as_bstr(), + &sig.name, &name, indent, &sig.fields, @@ -640,7 +640,7 @@ fn write_function( write_message( f, element, - fun.name.as_bstr(), + &fun.name, &in_name, indent, &fun.in_fields, @@ -650,7 +650,7 @@ fn write_function( write_message( f, element, - fun.name.as_bstr(), + &fun.name, &out_name, indent, &fun.out_fields, diff --git a/build/wire_xcon.rs b/build/wire_xcon.rs index f4a82486..fa180efe 100644 --- a/build/wire_xcon.rs +++ b/build/wire_xcon.rs @@ -4,7 +4,7 @@ use { tokens::{tokenize, Symbol, Token, TokenKind, TreeDelim}, }, anyhow::{bail, Context, Result}, - bstr::{BStr, BString, ByteSlice}, + bstr::ByteSlice, std::{cell::Cell, collections::HashMap, io::Write, mem, os::unix::ffi::OsStrExt, rc::Rc}, }; @@ -70,7 +70,7 @@ impl<'a> Parser<'a> { Ok(()) } - fn parse_extension(&mut self, line: u32) -> Result { + fn parse_extension(&mut self, line: u32) -> Result { let res: Result<_> = (|| { let (_, name) = self.expect_string()?; Ok(name.to_owned()) @@ -208,7 +208,7 @@ impl<'a> Parser<'a> { res.with_context(|| format!("While parsing bitmask starting at line {}", line)) } - fn parse_struct_body(&mut self, name: &BStr) -> Result { + fn parse_struct_body(&mut self, name: &str) -> Result { let mut fields = vec![]; while !self.eof() { fields.push(self.parse_field()?); @@ -272,7 +272,7 @@ impl<'a> Parser<'a> { } } - fn expect_ident(&mut self) -> Result<(u32, &'a BStr)> { + fn expect_ident(&mut self) -> Result<(u32, &'a str)> { self.not_eof()?; let token = &self.tokens[self.pos]; self.pos += 1; @@ -286,7 +286,7 @@ impl<'a> Parser<'a> { } } - fn expect_string(&mut self) -> Result<(u32, &'a BString)> { + fn expect_string(&mut self) -> Result<(u32, &'a String)> { self.not_eof()?; let token = &self.tokens[self.pos]; self.pos += 1; @@ -459,7 +459,7 @@ impl<'a> Parser<'a> { Ok(name) } - fn parse_field_name_expr(&mut self) -> Result { + fn parse_field_name_expr(&mut self) -> Result { let (_, tree) = self.expect_tree(TreeDelim::Paren)?; let mut parser = Parser::new(tree); let (_, name) = parser.expect_ident()?; @@ -560,7 +560,7 @@ fn needs_lifetime(ty: &Type, protocols: &Protocols) -> Result { Type::U64 => false, Type::Fd => false, Type::List(_, _) => true, - Type::Named(n) => named_needs_lt(n.as_bstr(), protocols)?, + Type::Named(n) => named_needs_lt(n, protocols)?, Type::String(_) => true, Type::Bitmask(_, _) => false, Type::Enum(n, _) => needs_lifetime(n, protocols)?, @@ -568,7 +568,7 @@ fn needs_lifetime(ty: &Type, protocols: &Protocols) -> Result { Ok(res) } -fn named_needs_lt(name: &BStr, protocols: &Protocols) -> Result { +fn named_needs_lt(name: &str, protocols: &Protocols) -> Result { let s = match protocols.types_by_name.get(name) { Some(s) => s, _ => bail!("Struct {} referenced but not defined", name), @@ -640,14 +640,14 @@ fn type_has_fds(ty: &Type, protocols: &Protocols) -> Result { Type::String(_) => false, Type::Fd => true, Type::List(ty, _) => return type_has_fds(ty, protocols), - Type::Named(n) => return named_has_fds(n.as_bstr(), protocols), + Type::Named(n) => return named_has_fds(n, protocols), Type::Bitmask(_, _) => false, Type::Enum(n, _) => return type_has_fds(n, protocols), }; Ok(res) } -fn named_has_fds(s: &BStr, protocols: &Protocols) -> Result { +fn named_has_fds(s: &str, protocols: &Protocols) -> Result { let s = match protocols.types_by_name.get(s) { Some(s) => s, _ => bail!("Struct {} referenced but not defined", s), @@ -698,19 +698,19 @@ enum Type { Fd, String(Expr), List(Box, Option), - Bitmask(BString, Expr), + Bitmask(String, Expr), Enum(Box, Expr), - Named(BString), + Named(String), } #[derive(Debug, Clone)] enum Expr { It, - Field(BString), - Len(BString), + Field(String), + Len(String), Literal(u32), - Bitmask(BString), - Variant(BString), + Bitmask(String), + Variant(String), Sum(Box), Mul(Box, Box), Map(Box, Box), @@ -722,7 +722,7 @@ enum Expr { #[derive(Debug, Clone)] struct RealField { - name: BString, + name: String, ty: Type, value: Option, } @@ -738,7 +738,7 @@ enum Field { #[derive(Debug)] struct Struct { - name: BString, + name: String, fields: Vec, needs_lt: Cell>, has_fds: Cell>, @@ -746,27 +746,27 @@ struct Struct { #[derive(Debug)] struct BitmaskVariant { - name: BString, + name: String, ty: Type, bit: u32, } #[derive(Debug)] struct Bitmask { - name: BString, + name: String, variants: Vec, } #[derive(Debug)] struct EnumVariant { - name: BString, + name: String, ty: Type, value: u32, } #[derive(Debug)] struct Enum { - name: BString, + name: String, variants: Vec, } @@ -780,9 +780,9 @@ struct Event { #[derive(Debug)] struct EventCopy { - name: BString, + name: String, opcode: u32, - original: BString, + original: String, } #[derive(Debug)] @@ -795,7 +795,7 @@ struct Request { #[derive(Debug)] struct Protocol { - extension: Option, + extension: Option, structs: Vec, requests: Vec, bitmasks: Vec, @@ -806,8 +806,8 @@ struct Protocol { #[derive(Debug)] struct Extension { - name: BString, - ident: BString, + name: String, + ident: String, } #[derive(Debug)] @@ -824,8 +824,8 @@ struct Protocols { bitmasks: Vec>, enums: Vec>, requests: Vec, - types_by_name: HashMap, - events_by_name: HashMap>, + types_by_name: HashMap, + events_by_name: HashMap>, events: Vec>, eventcopies: Vec, } @@ -869,7 +869,7 @@ fn write_type(f: &mut F, ty: &Type, protocols: &Protocols) -> Result<( return Ok(()); } Type::Named(n) => { - let lt = if named_needs_lt(n.as_bstr(), protocols)? { + let lt = if named_needs_lt(n, protocols)? { "<'a>" } else { "" @@ -944,7 +944,7 @@ enum StructUsecase<'a> { fn format_xevent( f: &mut F, - name: &BStr, + name: &str, s: &Struct, opcode: u32, protocols: &Protocols, @@ -965,18 +965,11 @@ fn format_xevent( fn format_event(f: &mut F, s: &Event, protocols: &Protocols) -> Result<()> { format_struct(f, &s.data, protocols, &StructUsecase::Event { xge: s.xge })?; - format_xevent( - f, - s.data.name.as_bstr(), - &s.data, - s.opcode, - protocols, - s.ext_idx, - ) + format_xevent(f, &s.data.name, &s.data, s.opcode, protocols, s.ext_idx) } fn format_eventcopy(f: &mut F, s: &EventCopy, protocols: &Protocols) -> Result<()> { - let original = match protocols.events_by_name.get(s.original.as_bstr()) { + let original = match protocols.events_by_name.get(&s.original) { Some(o) => o, _ => bail!("Event {} referenced but not defined", s.original), }; @@ -992,7 +985,7 @@ fn format_eventcopy(f: &mut F, s: &EventCopy, protocols: &Protocols) - )?; format_xevent( f, - s.name.as_bstr(), + &s.name, &original.data, s.opcode, protocols, @@ -1591,16 +1584,13 @@ pub fn main() -> Result<()> { } protocols.eventcopies.extend(protocol.eventcopies); if let Some(ext) = protocol.extension { - let mut ident = vec![]; - for c in ext.as_bytes() { - if matches!(*c, b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9') { - ident.push(*c); + let mut ident = String::new(); + for c in ext.chars() { + if matches!(c, 'a'..='z' | 'A'..='Z' | '0'..='9') { + ident.push(c); } } - protocols.extensions.push(Extension { - name: ext, - ident: ident.into(), - }); + protocols.extensions.push(Extension { name: ext, ident }); } } diff --git a/src/macros.rs b/src/macros.rs index e9327d7b..015dcbbe 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -12,39 +12,26 @@ macro_rules! efrom { } macro_rules! usr_object_base { - ($oname:ident, $iname:ident; $($code:ident => $f:ident,)*) => { + ($self:ident = $oname:ident = $iname:ident; version = $version:expr;) => { impl crate::wl_usr::usr_object::UsrObjectBase for $oname { - fn id(&self) -> crate::object::ObjectId { - self.id.into() + fn id(&$self) -> crate::object::ObjectId { + $self.id.into() + } + + fn version(&$self) -> crate::object::Version { + $version } - #[allow(unused_variables, unreachable_code)] fn handle_event( - self: std::rc::Rc, + $self: std::rc::Rc, + con: &crate::wl_usr::UsrCon, event: u32, parser: crate::utils::buffd::MsgParser<'_, '_>, - ) -> Result<(), crate::wl_usr::usr_object::UsrObjectError> { - let res: std::result::Result<(), _> = match event { - $( - $code => $oname::$f(&self, parser).map_err(|e| crate::wl_usr::usr_object::UsrObjectErrorType::EventError { - event: stringify!($f), - error: Box::new(e), - }), - )* - _ => Err(crate::wl_usr::usr_object::UsrObjectErrorType::UnknownEventError { - event, - }), - }; - if let Err(e) = res { - return Err(crate::wl_usr::usr_object::UsrObjectError { - interface: crate::wire::$iname, - ty: e, - }); - } - Ok(()) + ) -> Result<(), crate::wl_usr::UsrConError> { + $self.handle_event_impl(con, event, parser) } - fn interface(&self) -> crate::object::Interface { + fn interface(&$self) -> crate::object::Interface { crate::wire::$iname } } diff --git a/src/portal.rs b/src/portal.rs index 0caacc7f..fdea28c4 100644 --- a/src/portal.rs +++ b/src/portal.rs @@ -14,7 +14,7 @@ use { forker::ForkerError, io_uring::IoUring, logger::Logger, - pipewire::pw_con::{PwCon, PwConHolder, PwConOwner}, + pipewire::pw_con::{PwConHolder, PwConOwner}, portal::{ ptl_display::{watch_displays, PortalDisplay, PortalDisplayId}, ptl_render_ctx::PortalRenderCtx, @@ -181,9 +181,10 @@ async fn run_async( } }; let pw_con = match PwConHolder::new(&eng, &ring).await { - Ok(p) => p, + Ok(p) => Some(p), Err(e) => { - fatal!("Could not connect to pipewire: {}", ErrorFmt(e)); + log::error!("Could not connect to pipewire: {}", ErrorFmt(e)); + None } }; let state = Rc::new(PortalState { @@ -191,7 +192,6 @@ async fn run_async( ring, eng, wheel, - pw_con: pw_con.con.clone(), displays: Default::default(), dbus, screencasts: Default::default(), @@ -199,15 +199,19 @@ async fn run_async( render_ctxs: Default::default(), dma_buf_ids: Default::default(), }); + if let Some(pw_con) = &pw_con { + pw_con.con.owner.set(Some(state.clone())); + } let _root = { let obj = state .dbus .add_object("/org/freedesktop/portal/desktop") .unwrap(); - add_screencast_dbus_members(&state, &obj); + if let Some(pw_con) = &pw_con { + add_screencast_dbus_members(&state, &pw_con.con, &obj); + } obj }; - state.pw_con.owner.set(Some(state.clone())); watch_displays(state.clone()).await; } @@ -281,7 +285,6 @@ struct PortalState { ring: Rc, eng: Rc, wheel: Rc, - pw_con: Rc, displays: CopyHashMap>, dbus: Rc, screencasts: CopyHashMap>, diff --git a/src/portal/ptl_display.rs b/src/portal/ptl_display.rs index 0e4c4b34..51255c0d 100644 --- a/src/portal/ptl_display.rs +++ b/src/portal/ptl_display.rs @@ -2,6 +2,7 @@ use { crate::{ gfx_apis::create_gfx_context, ifs::wl_seat::POINTER, + object::Version, portal::{ ptl_render_ctx::PortalRenderCtx, ptl_screencast::ScreencastSession, ptr_gui::WindowData, PortalState, @@ -213,6 +214,7 @@ impl UsrWlRegistryOwner for PortalDisplay { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: Version(version.min(5)), }); self.con.add_object(ls.clone()); self.registry.request_bind(name, version, ls.deref()); @@ -301,6 +303,7 @@ fn finish_display_connect(dpy: Rc) { con: dpy.con.clone(), owner: Default::default(), caps: Default::default(), + version: Version(version.min(4)), }); dpy.con.add_object(jc.clone()); dpy.registry.request_bind(name, version, jc.deref()); @@ -309,6 +312,7 @@ fn finish_display_connect(dpy: Rc) { let ls = Rc::new(UsrWpFractionalScaleManager { id: dpy.con.id(), con: dpy.con.clone(), + version: Version(version.min(1)), }); dpy.con.add_object(ls.clone()); dpy.registry.request_bind(name, version, ls.deref()); @@ -317,6 +321,7 @@ fn finish_display_connect(dpy: Rc) { let ls = Rc::new(UsrWlrLayerShell { id: dpy.con.id(), con: dpy.con.clone(), + version: Version(version.min(5)), }); dpy.con.add_object(ls.clone()); dpy.registry.request_bind(name, version, ls.deref()); @@ -325,6 +330,7 @@ fn finish_display_connect(dpy: Rc) { let ls = Rc::new(UsrWpViewporter { id: dpy.con.id(), con: dpy.con.clone(), + version: Version(version.min(1)), }); dpy.con.add_object(ls.clone()); dpy.registry.request_bind(name, version, ls.deref()); @@ -333,6 +339,7 @@ fn finish_display_connect(dpy: Rc) { let ls = Rc::new(UsrWlCompositor { id: dpy.con.id(), con: dpy.con.clone(), + version: Version(version.min(6)), }); dpy.con.add_object(ls.clone()); dpy.registry.request_bind(name, version, ls.deref()); @@ -342,6 +349,7 @@ fn finish_display_connect(dpy: Rc) { id: dpy.con.id(), con: dpy.con.clone(), owner: Default::default(), + version: Version(version.min(5)), }); dpy.con.add_object(ls.clone()); dpy.registry.request_bind(name, version, ls.deref()); @@ -410,6 +418,7 @@ fn add_seat(dpy: &Rc, name: u32, version: u32) { id: dpy.con.id(), con: dpy.con.clone(), owner: Default::default(), + version: Version(version.min(9)), }); dpy.con.add_object(wl.clone()); dpy.registry.request_bind(name, version, wl.deref()); @@ -433,6 +442,7 @@ fn add_output(dpy: &Rc, name: u32, version: u32) { id: dpy.con.id(), con: dpy.con.clone(), owner: Default::default(), + version: Version(version.min(4)), }); dpy.con.add_object(wl.clone()); dpy.registry.request_bind(name, version, wl.deref()); diff --git a/src/portal/ptl_screencast.rs b/src/portal/ptl_screencast.rs index f49e1581..6b096cf1 100644 --- a/src/portal/ptl_screencast.rs +++ b/src/portal/ptl_screencast.rs @@ -4,6 +4,7 @@ use { crate::{ dbus::{prelude::Variant, DbusObject, DictEntry, DynamicType, PendingReply}, pipewire::{ + pw_con::PwCon, pw_ifs::pw_client_node::{ PwClientNode, PwClientNodeBufferConfig, PwClientNodeOwner, PwClientNodePort, PwClientNodePortSupportedFormats, SUPPORTED_META_VIDEO_CROP, @@ -56,6 +57,7 @@ shared_ids!(ScreencastSessionId); pub struct ScreencastSession { _id: ScreencastSessionId, state: Rc, + pw_con: Rc, pub app: String, session_obj: DbusObject, pub phase: CloneCell, @@ -234,7 +236,7 @@ impl PwClientNodeOwner for StartedScreencast { impl SelectingScreencastCore { pub fn starting(&self, dpy: &Rc, target: ScreencastTarget) { - let node = dpy.state.pw_con.create_client_node(&[ + let node = self.session.pw_con.create_client_node(&[ ("media.class".to_string(), "Video/Source".to_string()), ("node.name".to_string(), "jay-desktop-portal".to_string()), ("node.driver".to_string(), "true".to_string()), @@ -462,11 +464,16 @@ impl UsrJayScreencastOwner for StartedScreencast { } } -pub(super) fn add_screencast_dbus_members(state_: &Rc, object: &DbusObject) { +pub(super) fn add_screencast_dbus_members( + state_: &Rc, + pw_con: &Rc, + object: &DbusObject, +) { use org::freedesktop::impl_::portal::screen_cast::*; let state = state_.clone(); + let pw_con = pw_con.clone(); object.add_method::(move |req, pr| { - dbus_create_session(&state, req, pr); + dbus_create_session(&state, &pw_con, req, pr); }); let state = state_.clone(); object.add_method::(move |req, pr| { @@ -483,6 +490,7 @@ pub(super) fn add_screencast_dbus_members(state_: &Rc, object: &Dbu fn dbus_create_session( state: &Rc, + pw_con: &Rc, req: CreateSession, reply: PendingReply>, ) { @@ -501,6 +509,7 @@ fn dbus_create_session( let session = Rc::new(ScreencastSession { _id: state.id(), state: state.clone(), + pw_con: pw_con.clone(), app: req.app_id.to_string(), session_obj: obj, phase: CloneCell::new(ScreencastPhase::Init), diff --git a/src/rect.rs b/src/rect.rs index 1426df12..a721e6da 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -128,13 +128,13 @@ impl Rect { if self.raw.x1 > x { dx = self.raw.x1 - x; } else if self.raw.x2 < x { - dx = x - self.raw.x1; + dx = x - self.raw.x2; } let mut dy = 0; if self.raw.y1 > y { dy = self.raw.y1 - y; } else if self.raw.y2 < y { - dy = y - self.raw.y1; + dy = y - self.raw.y2; } dx * dx + dy * dy } diff --git a/src/wl_usr.rs b/src/wl_usr.rs index d6e05635..1fb88500 100644 --- a/src/wl_usr.rs +++ b/src/wl_usr.rs @@ -6,7 +6,7 @@ use { async_engine::{AsyncEngine, SpawnedFuture}, client::{EventFormatter, RequestParser, MIN_SERVER_ID}, io_uring::{IoUring, IoUringError}, - object::{ObjectId, WL_DISPLAY_ID}, + object::{Interface, ObjectId, Version, WL_DISPLAY_ID}, utils::{ asyncevent::AsyncEvent, bitfield::Bitfield, @@ -29,12 +29,13 @@ use { usr_wl_callback::UsrWlCallback, usr_wl_display::UsrWlDisplay, usr_wl_registry::UsrWlRegistry, }, - usr_object::{UsrObject, UsrObjectError}, + usr_object::UsrObject, }, }, std::{ cell::{Cell, RefCell}, collections::VecDeque, + error::Error, mem, rc::Rc, }, @@ -60,10 +61,17 @@ pub enum UsrConError { Read(#[source] BufFdError), #[error("Could not write to the compositor")] Write(#[source] BufFdError), - #[error(transparent)] - UsrObjectError(#[from] UsrObjectError), #[error("Server sent an event for object {0} that does not exist")] MissingObject(ObjectId), + #[error("Could not process a `{}.{}` event", .interface.name(), .method)] + MethodError { + interface: Interface, + method: &'static str, + #[source] + error: Box, + }, + #[error("Client tried to invoke a non-existent method")] + InvalidMethod, } pub struct UsrCon { @@ -133,6 +141,7 @@ impl UsrCon { Some(Rc::new(UsrWlDisplay { id: WL_DISPLAY_ID, con: slf.clone(), + version: Version(1), })), ); slf.incoming.set(Some( @@ -198,6 +207,7 @@ impl UsrCon { id: self.id(), con: self.clone(), owner: Default::default(), + version: Version(1), }); self.request(wl_display::GetRegistry { self_id: WL_DISPLAY_ID, @@ -352,7 +362,7 @@ impl Incoming { if let Some(obj) = self.con.objects.get(&obj_id) { if let Some(obj) = obj { let parser = MsgParser::new(&mut self.buf, &self.data); - obj.handle_event(event, parser)?; + obj.handle_event(&self.con, event, parser)?; } } else if obj_id.raw() < MIN_SERVER_ID { return Err(UsrConError::MissingObject(obj_id)); diff --git a/src/wl_usr/usr_ifs/usr_jay_compositor.rs b/src/wl_usr/usr_ifs/usr_jay_compositor.rs index 6c560573..4c89cb91 100644 --- a/src/wl_usr/usr_ifs/usr_jay_compositor.rs +++ b/src/wl_usr/usr_ifs/usr_jay_compositor.rs @@ -1,10 +1,8 @@ use { crate::{ ifs::jay_compositor::Cap, - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{jay_compositor::*, JayCompositorId}, wl_usr::{ usr_ifs::{ @@ -19,7 +17,7 @@ use { UsrCon, }, }, - std::{cell::Cell, rc::Rc}, + std::{cell::Cell, convert::Infallible, rc::Rc}, }; pub struct UsrJayCompositor { @@ -27,6 +25,7 @@ pub struct UsrJayCompositor { pub con: Rc, pub owner: CloneCell>>, pub caps: UsrJayCompositorCaps, + pub version: Version, } #[derive(Default)] @@ -51,6 +50,7 @@ impl UsrJayCompositor { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.request(GetRenderCtx { self_id: self.id, @@ -65,6 +65,7 @@ impl UsrJayCompositor { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: self.version, pending_buffers: Default::default(), pending_planes: Default::default(), pending_config: Default::default(), @@ -82,6 +83,7 @@ impl UsrJayCompositor { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.request(GetOutput { self_id: self.id, @@ -98,6 +100,7 @@ impl UsrJayCompositor { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.request(WatchWorkspaces { self_id: self.id, @@ -111,6 +114,7 @@ impl UsrJayCompositor { let jp = Rc::new(UsrJayPointer { id: self.con.id(), con: self.con.clone(), + version: self.version, }); self.con.add_object(jp.clone()); self.con.request(GetPointer { @@ -126,6 +130,7 @@ impl UsrJayCompositor { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.request(SelectToplevel { self_id: self.id, @@ -141,6 +146,7 @@ impl UsrJayCompositor { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.request(SelectWorkspace { self_id: self.id, @@ -150,25 +156,26 @@ impl UsrJayCompositor { self.con.add_object(sc.clone()); sc } +} - fn client_id(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: ClientId = self.con.parse(self, parser)?; +impl JayCompositorEventHandler for UsrJayCompositor { + type Error = Infallible; + + fn client_id(&self, ev: ClientId, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.client_id(ev); } Ok(()) } - fn seat(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Seat = self.con.parse(self, parser)?; + fn seat(&self, ev: Seat<'_>, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.seat(ev); } Ok(()) } - fn capabilities(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Capabilities = self.con.parse(self, parser)?; + fn capabilities(&self, ev: Capabilities<'_>, _slf: &Rc) -> Result<(), Self::Error> { for &cap in ev.cap { match cap { Cap::NONE => {} @@ -182,11 +189,8 @@ impl UsrJayCompositor { } usr_object_base! { - UsrJayCompositor, JayCompositor; - - CLIENT_ID => client_id, - SEAT => seat, - CAPABILITIES => capabilities, + self = UsrJayCompositor = JayCompositor; + version = self.version; } impl UsrObject for UsrJayCompositor { diff --git a/src/wl_usr/usr_ifs/usr_jay_output.rs b/src/wl_usr/usr_ifs/usr_jay_output.rs index 953d007d..186927a6 100644 --- a/src/wl_usr/usr_ifs/usr_jay_output.rs +++ b/src/wl_usr/usr_ifs/usr_jay_output.rs @@ -1,19 +1,18 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{jay_output::*, JayOutputId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrJayOutput { pub id: JayOutputId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrJayOutputOwner { @@ -24,17 +23,21 @@ pub trait UsrJayOutputOwner { fn destroyed(&self) {} } -impl UsrJayOutput { - fn linear_id(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: LinearId = self.con.parse(self, parser)?; +impl JayOutputEventHandler for UsrJayOutput { + type Error = Infallible; + + fn linear_id(&self, ev: LinearId, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.linear_id(&ev); } Ok(()) } - fn destroyed(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Destroyed = self.con.parse(self, parser)?; + fn unused(&self, _ev: Unused, _slf: &Rc) -> Result<(), Self::Error> { + unimplemented!(); + } + + fn destroyed(&self, _ev: Destroyed, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.destroyed(); } @@ -43,10 +46,8 @@ impl UsrJayOutput { } usr_object_base! { - UsrJayOutput, JayOutput; - - LINEAR_ID => linear_id, - DESTROYED => destroyed, + self = UsrJayOutput = JayOutput; + version = self.version; } impl UsrObject for UsrJayOutput { diff --git a/src/wl_usr/usr_ifs/usr_jay_pointer.rs b/src/wl_usr/usr_ifs/usr_jay_pointer.rs index 8e0316a0..1013ddc2 100644 --- a/src/wl_usr/usr_ifs/usr_jay_pointer.rs +++ b/src/wl_usr/usr_ifs/usr_jay_pointer.rs @@ -1,15 +1,17 @@ use { crate::{ cursor::KnownCursor, + object::Version, wire::{jay_pointer::*, JayPointerId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrJayPointer { pub id: JayPointerId, pub con: Rc, + pub version: Version, } impl UsrJayPointer { @@ -21,8 +23,13 @@ impl UsrJayPointer { } } +impl JayPointerEventHandler for UsrJayPointer { + type Error = Infallible; +} + usr_object_base! { - UsrJayPointer, JayPointer; + self = UsrJayPointer = JayPointer; + version = self.version; } impl UsrObject for UsrJayPointer { diff --git a/src/wl_usr/usr_ifs/usr_jay_render_ctx.rs b/src/wl_usr/usr_ifs/usr_jay_render_ctx.rs index 54688164..fafb3fdc 100644 --- a/src/wl_usr/usr_ifs/usr_jay_render_ctx.rs +++ b/src/wl_usr/usr_ifs/usr_jay_render_ctx.rs @@ -1,13 +1,11 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{jay_render_ctx::*, JayRenderCtxId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, uapi::OwnedFd, }; @@ -15,6 +13,7 @@ pub struct UsrJayRenderCtx { pub id: JayRenderCtxId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrJayRenderCtxOwner { @@ -24,17 +23,17 @@ pub trait UsrJayRenderCtxOwner { } } -impl UsrJayRenderCtx { - fn no_device(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: NoDevice = self.con.parse(self, parser)?; +impl JayRenderCtxEventHandler for UsrJayRenderCtx { + type Error = Infallible; + + fn no_device(&self, _ev: NoDevice, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.no_device(); } Ok(()) } - fn device(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Device = self.con.parse(self, parser)?; + fn device(&self, ev: Device, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.device(ev.fd); } @@ -43,10 +42,8 @@ impl UsrJayRenderCtx { } usr_object_base! { - UsrJayRenderCtx, JayRenderCtx; - - NO_DEVICE => no_device, - DEVICE => device, + self = UsrJayRenderCtx = JayRenderCtx; + version = self.version; } impl UsrObject for UsrJayRenderCtx { diff --git a/src/wl_usr/usr_ifs/usr_jay_screencast.rs b/src/wl_usr/usr_ifs/usr_jay_screencast.rs index a68d2072..8925b7a2 100644 --- a/src/wl_usr/usr_ifs/usr_jay_screencast.rs +++ b/src/wl_usr/usr_ifs/usr_jay_screencast.rs @@ -1,10 +1,8 @@ use { crate::{ format::formats, - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, video::dmabuf::{DmaBuf, DmaBufPlane, PlaneVec}, wire::{jay_screencast::*, JayScreencastId}, wl_usr::{ @@ -24,6 +22,7 @@ pub struct UsrJayScreencast { pub id: JayScreencastId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, pub pending_buffers: RefCell>, pub pending_planes: RefCell>, @@ -117,9 +116,12 @@ impl UsrJayScreencast { idx: idx as _, }); } +} - fn plane(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Plane = self.con.parse(self, parser)?; +impl JayScreencastEventHandler for UsrJayScreencast { + type Error = UsrJayScreencastError; + + fn plane(&self, ev: Plane, _slf: &Rc) -> Result<(), Self::Error> { self.pending_planes.borrow_mut().push(DmaBufPlane { offset: ev.offset, stride: ev.stride, @@ -128,8 +130,7 @@ impl UsrJayScreencast { Ok(()) } - fn buffer(&self, parser: MsgParser<'_, '_>) -> Result<(), UsrJayScreencastError> { - let ev: Buffer = self.con.parse(self, parser)?; + fn buffer(&self, ev: Buffer, _slf: &Rc) -> Result<(), Self::Error> { let format = match formats().get(&ev.format) { Some(f) => f, _ => return Err(UsrJayScreencastError::UnknownFormat(ev.format)), @@ -145,8 +146,7 @@ impl UsrJayScreencast { Ok(()) } - fn buffers_done(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: BuffersDone = self.con.parse(self, parser)?; + fn buffers_done(&self, ev: BuffersDone, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.buffers(mem::take(self.pending_buffers.borrow_mut().deref_mut())); } @@ -157,65 +157,68 @@ impl UsrJayScreencast { Ok(()) } - fn ready(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Ready = self.con.parse(self, parser)?; + fn ready(&self, ev: Ready, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.ready(&ev); } Ok(()) } - fn destroyed(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Destroyed = self.con.parse(self, parser)?; + fn destroyed(&self, _ev: Destroyed, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.destroyed(); } Ok(()) } - fn missed_frame(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: MissedFrame = self.con.parse(self, parser)?; + fn missed_frame(&self, _ev: MissedFrame, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.missed_frame(); } Ok(()) } - fn config_output(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: ConfigOutput = self.con.parse(self, parser)?; + fn config_output(&self, ev: ConfigOutput, _slf: &Rc) -> Result<(), Self::Error> { self.pending_config.borrow_mut().output = Some(ev.linear_id); Ok(()) } - fn config_allow_all_workspaces(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: ConfigAllowAllWorkspaces = self.con.parse(self, parser)?; + fn config_allow_all_workspaces( + &self, + ev: ConfigAllowAllWorkspaces, + _slf: &Rc, + ) -> Result<(), Self::Error> { self.pending_config.borrow_mut().show_all = ev.allow_all != 0; Ok(()) } - fn config_use_linear_buffers(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: ConfigUseLinearBuffers = self.con.parse(self, parser)?; - self.pending_config.borrow_mut().use_linear_buffers = ev.use_linear != 0; + fn config_allow_workspace( + &self, + ev: ConfigAllowWorkspace, + _slf: &Rc, + ) -> Result<(), Self::Error> { + self.pending_config + .borrow_mut() + .allowed_workspaces + .push(ev.linear_id); Ok(()) } - fn config_running(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: ConfigRunning = self.con.parse(self, parser)?; - self.pending_config.borrow_mut().running = ev.running != 0; + fn config_use_linear_buffers( + &self, + ev: ConfigUseLinearBuffers, + _slf: &Rc, + ) -> Result<(), Self::Error> { + self.pending_config.borrow_mut().use_linear_buffers = ev.use_linear != 0; Ok(()) } - fn config_allow_workspace(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: ConfigAllowWorkspace = self.con.parse(self, parser)?; - self.pending_config - .borrow_mut() - .allowed_workspaces - .push(ev.linear_id); + fn config_running(&self, ev: ConfigRunning, _slf: &Rc) -> Result<(), Self::Error> { + self.pending_config.borrow_mut().running = ev.running != 0; Ok(()) } - fn config_done(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: ConfigDone = self.con.parse(self, parser)?; + fn config_done(&self, ev: ConfigDone, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.config(mem::take(self.pending_config.borrow_mut().deref_mut())); } @@ -228,20 +231,8 @@ impl UsrJayScreencast { } usr_object_base! { - UsrJayScreencast, JayScreencast; - - PLANE => plane, - BUFFER => buffer, - BUFFERS_DONE => buffers_done, - READY => ready, - DESTROYED => destroyed, - MISSED_FRAME => missed_frame, - CONFIG_OUTPUT => config_output, - CONFIG_ALLOW_ALL_WORKSPACES => config_allow_all_workspaces, - CONFIG_ALLOW_WORKSPACE => config_allow_workspace, - CONFIG_USE_LINEAR_BUFFERS => config_use_linear_buffers, - CONFIG_RUNNING => config_running, - CONFIG_DONE => config_done, + self = UsrJayScreencast = JayScreencast; + version = self.version; } impl UsrObject for UsrJayScreencast { @@ -256,8 +247,6 @@ impl UsrObject for UsrJayScreencast { #[derive(Debug, Error)] pub enum UsrJayScreencastError { - #[error("Parsing failed")] - MsgParserError(#[from] MsgParserError), #[error("The server sent an unknown format {0}")] UnknownFormat(u32), } diff --git a/src/wl_usr/usr_ifs/usr_jay_select_toplevel.rs b/src/wl_usr/usr_ifs/usr_jay_select_toplevel.rs index b108796b..381d59fe 100644 --- a/src/wl_usr/usr_ifs/usr_jay_select_toplevel.rs +++ b/src/wl_usr/usr_ifs/usr_jay_select_toplevel.rs @@ -1,29 +1,28 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{jay_select_toplevel::*, JaySelectToplevelId}, wl_usr::{usr_ifs::usr_jay_toplevel::UsrJayToplevel, usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, - thiserror::Error, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrJaySelectToplevel { pub id: JaySelectToplevelId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrJaySelectToplevelOwner { fn done(&self, toplevel: Option>); } -impl UsrJaySelectToplevel { - fn done(&self, parser: MsgParser<'_, '_>) -> Result<(), UsrJaySelectToplevelError> { - let ev: Done = self.con.parse(self, parser)?; +impl JaySelectToplevelEventHandler for UsrJaySelectToplevel { + type Error = Infallible; + + fn done(&self, ev: Done, _slf: &Rc) -> Result<(), Self::Error> { let tl = if ev.id.is_none() { None } else { @@ -31,6 +30,7 @@ impl UsrJaySelectToplevel { id: ev.id, con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.add_object(tl.clone()); Some(tl) @@ -49,9 +49,8 @@ impl UsrJaySelectToplevel { } usr_object_base! { - UsrJaySelectToplevel, JaySelectToplevel; - - DONE => done, + self = UsrJaySelectToplevel = JaySelectToplevel; + version = self.version; } impl UsrObject for UsrJaySelectToplevel { @@ -63,9 +62,3 @@ impl UsrObject for UsrJaySelectToplevel { self.owner.take(); } } - -#[derive(Debug, Error)] -pub enum UsrJaySelectToplevelError { - #[error("Parsing failed")] - MsgParserError(#[from] MsgParserError), -} diff --git a/src/wl_usr/usr_ifs/usr_jay_select_workspace.rs b/src/wl_usr/usr_ifs/usr_jay_select_workspace.rs index 189890cd..07153faa 100644 --- a/src/wl_usr/usr_ifs/usr_jay_select_workspace.rs +++ b/src/wl_usr/usr_ifs/usr_jay_select_workspace.rs @@ -1,29 +1,28 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{jay_select_workspace::*, JaySelectWorkspaceId}, wl_usr::{usr_ifs::usr_jay_workspace::UsrJayWorkspace, usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, - thiserror::Error, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrJaySelectWorkspace { pub id: JaySelectWorkspaceId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrJaySelectWorkspaceOwner { fn done(&self, output: u32, ws: Option>); } -impl UsrJaySelectWorkspace { - fn cancelled(&self, parser: MsgParser<'_, '_>) -> Result<(), UsrJaySelectWorkspaceError> { - let _ev: Cancelled = self.con.parse(self, parser)?; +impl JaySelectWorkspaceEventHandler for UsrJaySelectWorkspace { + type Error = Infallible; + + fn cancelled(&self, _ev: Cancelled, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.done(0, None); } @@ -31,12 +30,12 @@ impl UsrJaySelectWorkspace { Ok(()) } - fn selected(&self, parser: MsgParser<'_, '_>) -> Result<(), UsrJaySelectWorkspaceError> { - let ev: Selected = self.con.parse(self, parser)?; + fn selected(&self, ev: Selected, _slf: &Rc) -> Result<(), Self::Error> { let tl = Rc::new(UsrJayWorkspace { id: ev.id, con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.add_object(tl.clone()); match self.owner.get() { @@ -49,10 +48,8 @@ impl UsrJaySelectWorkspace { } usr_object_base! { - UsrJaySelectWorkspace, JaySelectWorkspace; - - CANCELLED => cancelled, - SELECTED => selected, + self = UsrJaySelectWorkspace = JaySelectWorkspace; + version = self.version; } impl UsrObject for UsrJaySelectWorkspace { @@ -64,9 +61,3 @@ impl UsrObject for UsrJaySelectWorkspace { self.owner.take(); } } - -#[derive(Debug, Error)] -pub enum UsrJaySelectWorkspaceError { - #[error("Parsing failed")] - MsgParserError(#[from] MsgParserError), -} diff --git a/src/wl_usr/usr_ifs/usr_jay_toplevel.rs b/src/wl_usr/usr_ifs/usr_jay_toplevel.rs index ffc82f70..e1a31604 100644 --- a/src/wl_usr/usr_ifs/usr_jay_toplevel.rs +++ b/src/wl_usr/usr_ifs/usr_jay_toplevel.rs @@ -1,28 +1,28 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{jay_toplevel::*, JayToplevelId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrJayToplevel { pub id: JayToplevelId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrJayToplevelOwner { fn destroyed(&self) {} } -impl UsrJayToplevel { - fn destroyed(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Destroyed = self.con.parse(self, parser)?; +impl JayToplevelEventHandler for UsrJayToplevel { + type Error = Infallible; + + fn destroyed(&self, _ev: Destroyed, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.destroyed(); } @@ -31,9 +31,8 @@ impl UsrJayToplevel { } usr_object_base! { - UsrJayToplevel, JayToplevel; - - DESTROYED => destroyed, + self = UsrJayToplevel = JayToplevel; + version = self.version; } impl UsrObject for UsrJayToplevel { diff --git a/src/wl_usr/usr_ifs/usr_jay_workspace.rs b/src/wl_usr/usr_ifs/usr_jay_workspace.rs index 290692ca..d3d183a3 100644 --- a/src/wl_usr/usr_ifs/usr_jay_workspace.rs +++ b/src/wl_usr/usr_ifs/usr_jay_workspace.rs @@ -1,19 +1,18 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{jay_workspace::*, JayWorkspaceId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrJayWorkspace { pub id: JayWorkspaceId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrJayWorkspaceOwner { @@ -38,49 +37,45 @@ pub trait UsrJayWorkspaceOwner { } } -impl UsrJayWorkspace { - fn linear_id(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: LinearId = self.con.parse(self, parser)?; +impl JayWorkspaceEventHandler for UsrJayWorkspace { + type Error = Infallible; + + fn linear_id(&self, ev: LinearId, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.linear_id(&ev); } Ok(()) } - fn name(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Name = self.con.parse(self, parser)?; + fn name(&self, ev: Name<'_>, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.name(&ev); } Ok(()) } - fn destroyed(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Destroyed = self.con.parse(self, parser)?; + fn destroyed(&self, _ev: Destroyed, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.destroyed(); } Ok(()) } - fn done(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Done = self.con.parse(self, parser)?; + fn done(&self, _ev: Done, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.done(); } Ok(()) } - fn output(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Output = self.con.parse(self, parser)?; + fn output(&self, ev: Output, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.output(&ev); } Ok(()) } - fn visible(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Visible = self.con.parse(self, parser)?; + fn visible(&self, ev: Visible, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.visible(ev.visible != 0); } @@ -89,14 +84,8 @@ impl UsrJayWorkspace { } usr_object_base! { - UsrJayWorkspace, JayWorkspace; - - LINEAR_ID => linear_id, - NAME => name, - DESTROYED => destroyed, - DONE => done, - OUTPUT => output, - VISIBLE => visible, + self = UsrJayWorkspace = JayWorkspace; + version = self.version; } impl UsrObject for UsrJayWorkspace { diff --git a/src/wl_usr/usr_ifs/usr_jay_workspace_watcher.rs b/src/wl_usr/usr_ifs/usr_jay_workspace_watcher.rs index 16466c53..495de4f0 100644 --- a/src/wl_usr/usr_ifs/usr_jay_workspace_watcher.rs +++ b/src/wl_usr/usr_ifs/usr_jay_workspace_watcher.rs @@ -1,19 +1,18 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{jay_workspace_watcher::*, JayWorkspaceWatcherId}, wl_usr::{usr_ifs::usr_jay_workspace::UsrJayWorkspace, usr_object::UsrObject, UsrCon}, }, - std::{ops::Deref, rc::Rc}, + std::{convert::Infallible, ops::Deref, rc::Rc}, }; pub struct UsrJayWorkspaceWatcher { pub id: JayWorkspaceWatcherId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrJayWorkspaceWatcherOwner { @@ -23,13 +22,15 @@ pub trait UsrJayWorkspaceWatcherOwner { } } -impl UsrJayWorkspaceWatcher { - fn new(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: New = self.con.parse(self, parser)?; +impl JayWorkspaceWatcherEventHandler for UsrJayWorkspaceWatcher { + type Error = Infallible; + + fn new(&self, ev: New, _slf: &Rc) -> Result<(), Self::Error> { let jw = Rc::new(UsrJayWorkspace { id: ev.id, con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.add_object(jw.clone()); if let Some(owner) = self.owner.get() { @@ -42,9 +43,8 @@ impl UsrJayWorkspaceWatcher { } usr_object_base! { - UsrJayWorkspaceWatcher, JayWorkspaceWatcher; - - NEW => new, + self = UsrJayWorkspaceWatcher = JayWorkspaceWatcher; + version = self.version; } impl UsrObject for UsrJayWorkspaceWatcher { diff --git a/src/wl_usr/usr_ifs/usr_linux_buffer_params.rs b/src/wl_usr/usr_ifs/usr_linux_buffer_params.rs index 7501f3fd..3b7d699d 100644 --- a/src/wl_usr/usr_ifs/usr_linux_buffer_params.rs +++ b/src/wl_usr/usr_ifs/usr_linux_buffer_params.rs @@ -1,20 +1,19 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, video::dmabuf::DmaBuf, wire::{zwp_linux_buffer_params_v1::*, ZwpLinuxBufferParamsV1Id}, wl_usr::{usr_ifs::usr_wl_buffer::UsrWlBuffer, usr_object::UsrObject, UsrCon}, }, - std::{ops::Deref, rc::Rc}, + std::{convert::Infallible, ops::Deref, rc::Rc}, }; pub struct UsrLinuxBufferParams { pub id: ZwpLinuxBufferParamsV1Id, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrLinuxBufferParamsOwner { @@ -46,13 +45,17 @@ impl UsrLinuxBufferParams { flags: 0, }); } +} + +impl ZwpLinuxBufferParamsV1EventHandler for UsrLinuxBufferParams { + type Error = Infallible; - fn created(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Created = self.con.parse(self, parser)?; + fn created(&self, ev: Created, _slf: &Rc) -> Result<(), Self::Error> { let buffer = Rc::new(UsrWlBuffer { id: ev.buffer, con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.add_object(buffer.clone()); if let Some(owner) = self.owner.get() { @@ -63,8 +66,7 @@ impl UsrLinuxBufferParams { Ok(()) } - fn failed(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Failed = self.con.parse(self, parser)?; + fn failed(&self, _ev: Failed, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.failed(); } @@ -73,10 +75,8 @@ impl UsrLinuxBufferParams { } usr_object_base! { - UsrLinuxBufferParams, ZwpLinuxBufferParamsV1; - - CREATED => created, - FAILED => failed, + self = UsrLinuxBufferParams = ZwpLinuxBufferParamsV1; + version = self.version; } impl UsrObject for UsrLinuxBufferParams { diff --git a/src/wl_usr/usr_ifs/usr_linux_dmabuf.rs b/src/wl_usr/usr_ifs/usr_linux_dmabuf.rs index 4c8de584..4ccc4869 100644 --- a/src/wl_usr/usr_ifs/usr_linux_dmabuf.rs +++ b/src/wl_usr/usr_ifs/usr_linux_dmabuf.rs @@ -1,10 +1,8 @@ use { crate::{ format::{formats, Format}, - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{ zwp_linux_dmabuf_v1::{self, *}, ZwpLinuxDmabufV1Id, @@ -13,13 +11,14 @@ use { usr_ifs::usr_linux_buffer_params::UsrLinuxBufferParams, usr_object::UsrObject, UsrCon, }, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrLinuxDmabuf { pub id: ZwpLinuxDmabufV1Id, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrLinuxDmabufOwner { @@ -35,6 +34,7 @@ impl UsrLinuxDmabuf { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.request(CreateParams { self_id: self.id, @@ -43,14 +43,16 @@ impl UsrLinuxDmabuf { self.con.add_object(params.clone()); params } +} - fn format(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: zwp_linux_dmabuf_v1::Format = self.con.parse(self, parser)?; +impl ZwpLinuxDmabufV1EventHandler for UsrLinuxDmabuf { + type Error = Infallible; + + fn format(&self, _ev: zwp_linux_dmabuf_v1::Format, _slf: &Rc) -> Result<(), Self::Error> { Ok(()) } - fn modifier(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Modifier = self.con.parse(self, parser)?; + fn modifier(&self, ev: Modifier, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { if let Some(format) = formats().get(&ev.format) { owner.modifier( @@ -64,10 +66,8 @@ impl UsrLinuxDmabuf { } usr_object_base! { - UsrLinuxDmabuf, ZwpLinuxDmabufV1; - - FORMAT => format, - MODIFIER => modifier, + self = UsrLinuxDmabuf = ZwpLinuxDmabufV1; + version = self.version; } impl UsrObject for UsrLinuxDmabuf { diff --git a/src/wl_usr/usr_ifs/usr_wl_buffer.rs b/src/wl_usr/usr_ifs/usr_wl_buffer.rs index 7e045676..4acd8768 100644 --- a/src/wl_usr/usr_ifs/usr_wl_buffer.rs +++ b/src/wl_usr/usr_ifs/usr_wl_buffer.rs @@ -1,28 +1,28 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{wl_buffer::*, WlBufferId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWlBuffer { pub id: WlBufferId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrWlBufferOwner { fn release(&self) {} } -impl UsrWlBuffer { - fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Release = self.con.parse(self, parser)?; +impl WlBufferEventHandler for UsrWlBuffer { + type Error = Infallible; + + fn release(&self, _ev: Release, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.release(); } @@ -31,9 +31,8 @@ impl UsrWlBuffer { } usr_object_base! { - UsrWlBuffer, WlBuffer; - - RELEASE => release, + self = UsrWlBuffer = WlBuffer; + version = self.version; } impl UsrObject for UsrWlBuffer { diff --git a/src/wl_usr/usr_ifs/usr_wl_callback.rs b/src/wl_usr/usr_ifs/usr_wl_callback.rs index 9a839dd4..b0663bcd 100644 --- a/src/wl_usr/usr_ifs/usr_wl_callback.rs +++ b/src/wl_usr/usr_ifs/usr_wl_callback.rs @@ -1,16 +1,17 @@ use { crate::{ - utils::buffd::{MsgParser, MsgParserError}, + object::Version, wire::{wl_callback::*, WlCallbackId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::{cell::Cell, rc::Rc}, + std::{cell::Cell, convert::Infallible, rc::Rc}, }; pub struct UsrWlCallback { pub id: WlCallbackId, pub con: Rc, pub handler: Cell>>, + pub version: Version, } impl UsrWlCallback { @@ -22,11 +23,15 @@ impl UsrWlCallback { id: con.id(), con: con.clone(), handler: Cell::new(Some(Box::new(handler))), + version: Version(1), } } +} + +impl WlCallbackEventHandler for UsrWlCallback { + type Error = Infallible; - fn done(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Done = self.con.parse(self, parser)?; + fn done(&self, _ev: Done, _slf: &Rc) -> Result<(), Self::Error> { if let Some(handler) = self.handler.take() { handler(); } @@ -36,9 +41,8 @@ impl UsrWlCallback { } usr_object_base! { - UsrWlCallback, WlCallback; - - DONE => done, + self = UsrWlCallback = WlCallback; + version = self.version; } impl UsrObject for UsrWlCallback { diff --git a/src/wl_usr/usr_ifs/usr_wl_compositor.rs b/src/wl_usr/usr_ifs/usr_wl_compositor.rs index e813994c..e9d9be87 100644 --- a/src/wl_usr/usr_ifs/usr_wl_compositor.rs +++ b/src/wl_usr/usr_ifs/usr_wl_compositor.rs @@ -1,14 +1,19 @@ use { crate::{ - wire::{wl_compositor::CreateSurface, WlCompositorId}, + object::Version, + wire::{ + wl_compositor::{CreateSurface, WlCompositorEventHandler}, + WlCompositorId, + }, wl_usr::{usr_ifs::usr_wl_surface::UsrWlSurface, usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWlCompositor { pub id: WlCompositorId, pub con: Rc, + pub version: Version, } impl UsrWlCompositor { @@ -16,6 +21,7 @@ impl UsrWlCompositor { let sfc = Rc::new(UsrWlSurface { id: self.con.id(), con: self.con.clone(), + version: self.version, }); self.con.request(CreateSurface { self_id: self.id, @@ -26,8 +32,13 @@ impl UsrWlCompositor { } } +impl WlCompositorEventHandler for UsrWlCompositor { + type Error = Infallible; +} + usr_object_base! { - UsrWlCompositor, WlCompositor; + self = UsrWlCompositor = WlCompositor; + version = self.version; } impl UsrObject for UsrWlCompositor { diff --git a/src/wl_usr/usr_ifs/usr_wl_display.rs b/src/wl_usr/usr_ifs/usr_wl_display.rs index 282dd5ad..2b4bca47 100644 --- a/src/wl_usr/usr_ifs/usr_wl_display.rs +++ b/src/wl_usr/usr_ifs/usr_wl_display.rs @@ -1,6 +1,6 @@ use { crate::{ - utils::buffd::{MsgParser, MsgParserError}, + object::Version, wire::{wl_display::*, WlDisplayId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, @@ -10,16 +10,17 @@ use { pub struct UsrWlDisplay { pub id: WlDisplayId, pub con: Rc, + pub version: Version, } -impl UsrWlDisplay { - fn error(&self, parser: MsgParser<'_, '_>) -> Result<(), UsrWlDisplayError> { - let ev: Error = self.con.parse(self, parser)?; +impl WlDisplayEventHandler for UsrWlDisplay { + type Error = UsrWlDisplayError; + + fn error(&self, ev: Error<'_>, _slf: &Rc) -> Result<(), Self::Error> { Err(UsrWlDisplayError::ServerError(ev.message.to_owned())) } - fn delete_id(&self, parser: MsgParser<'_, '_>) -> Result<(), UsrWlDisplayError> { - let ev: DeleteId = self.con.parse(self, parser)?; + fn delete_id(&self, ev: DeleteId, _slf: &Rc) -> Result<(), Self::Error> { self.con.release_id(ev.id); Ok(()) } @@ -29,15 +30,11 @@ impl UsrWlDisplay { pub enum UsrWlDisplayError { #[error("The server emitted an error: {0}")] ServerError(String), - #[error(transparent)] - MsgParserError(#[from] MsgParserError), } usr_object_base! { - UsrWlDisplay, WlDisplay; - - ERROR => error, - DELETE_ID => delete_id, + self = UsrWlDisplay = WlDisplay; + version = self.version; } impl UsrObject for UsrWlDisplay { diff --git a/src/wl_usr/usr_ifs/usr_wl_output.rs b/src/wl_usr/usr_ifs/usr_wl_output.rs index a90dafa9..c5ad9f60 100644 --- a/src/wl_usr/usr_ifs/usr_wl_output.rs +++ b/src/wl_usr/usr_ifs/usr_wl_output.rs @@ -1,19 +1,18 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{wl_output::*, WlOutputId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWlOutput { pub id: WlOutputId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrWlOutputOwner { @@ -40,49 +39,45 @@ pub trait UsrWlOutputOwner { } } -impl UsrWlOutput { - fn geometry(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Geometry = self.con.parse(self, parser)?; +impl WlOutputEventHandler for UsrWlOutput { + type Error = Infallible; + + fn geometry(&self, ev: Geometry<'_>, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.geometry(&ev); } Ok(()) } - fn mode(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Mode = self.con.parse(self, parser)?; + fn mode(&self, ev: Mode, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.mode(&ev); } Ok(()) } - fn done(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Done = self.con.parse(self, parser)?; + fn done(&self, _ev: Done, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.done(); } Ok(()) } - fn scale(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Scale = self.con.parse(self, parser)?; + fn scale(&self, ev: Scale, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.scale(&ev); } Ok(()) } - fn name(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Name = self.con.parse(self, parser)?; + fn name(&self, ev: Name<'_>, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.name(&ev); } Ok(()) } - fn description(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Description = self.con.parse(self, parser)?; + fn description(&self, ev: Description<'_>, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.description(&ev); } @@ -91,14 +86,8 @@ impl UsrWlOutput { } usr_object_base! { - UsrWlOutput, WlOutput; - - GEOMETRY => geometry, - MODE => mode, - DONE => done, - SCALE => scale, - NAME => name, - DESCRIPTION => description, + self = UsrWlOutput = WlOutput; + version = self.version; } impl UsrObject for UsrWlOutput { diff --git a/src/wl_usr/usr_ifs/usr_wl_pointer.rs b/src/wl_usr/usr_ifs/usr_wl_pointer.rs index d082d2bc..78851633 100644 --- a/src/wl_usr/usr_ifs/usr_wl_pointer.rs +++ b/src/wl_usr/usr_ifs/usr_wl_pointer.rs @@ -1,14 +1,12 @@ use { crate::{ ifs::wl_seat::wl_pointer::PendingScroll, - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{wl_pointer::*, WlPointerId}, wl_usr::{usr_ifs::usr_wl_surface::UsrWlSurface, usr_object::UsrObject, UsrCon}, }, - std::{cell::Cell, rc::Rc}, + std::{cell::Cell, convert::Infallible, rc::Rc}, }; pub struct UsrWlPointer { @@ -17,6 +15,7 @@ pub struct UsrWlPointer { pub owner: CloneCell>>, pub any_scroll_events: Cell, pub pending_scroll: PendingScroll, + pub version: Version, } pub trait UsrWlPointerOwner { @@ -52,41 +51,40 @@ impl UsrWlPointer { hotspot_y: hot_y, }); } +} + +impl WlPointerEventHandler for UsrWlPointer { + type Error = Infallible; - fn enter(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Enter = self.con.parse(self, parser)?; + fn enter(&self, ev: Enter, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.enter(&ev); } Ok(()) } - fn leave(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Leave = self.con.parse(self, parser)?; + fn leave(&self, ev: Leave, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.leave(&ev); } Ok(()) } - fn motion(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Motion = self.con.parse(self, parser)?; + fn motion(&self, ev: Motion, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.motion(&ev); } Ok(()) } - fn button(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Button = self.con.parse(self, parser)?; + fn button(&self, ev: Button, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.button(&ev); } Ok(()) } - fn axis(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Axis = self.con.parse(self, parser)?; + fn axis(&self, ev: Axis, _slf: &Rc) -> Result<(), Self::Error> { self.pending_scroll.time_usec.set(ev.time as u64 * 1000); if ev.axis < 2 { self.pending_scroll.px[ev.axis as usize].set(Some(ev.value)); @@ -95,8 +93,7 @@ impl UsrWlPointer { Ok(()) } - fn frame(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Frame = self.con.parse(self, parser)?; + fn frame(&self, _ev: Frame, _slf: &Rc) -> Result<(), Self::Error> { if self.any_scroll_events.take() { let pe = self.pending_scroll.take(); if let Some(owner) = self.owner.get() { @@ -106,15 +103,13 @@ impl UsrWlPointer { Ok(()) } - fn axis_source(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: AxisSource = self.con.parse(self, parser)?; + fn axis_source(&self, ev: AxisSource, _slf: &Rc) -> Result<(), Self::Error> { self.pending_scroll.source.set(Some(ev.axis_source)); self.any_scroll_events.set(true); Ok(()) } - fn axis_stop(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: AxisStop = self.con.parse(self, parser)?; + fn axis_stop(&self, ev: AxisStop, _slf: &Rc) -> Result<(), Self::Error> { self.pending_scroll.time_usec.set(ev.time as u64 * 1000); if ev.axis < 2 { self.pending_scroll.stop[ev.axis as usize].set(true); @@ -123,35 +118,31 @@ impl UsrWlPointer { Ok(()) } - fn axis_discrete(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: AxisDiscrete = self.con.parse(self, parser)?; + fn axis_discrete(&self, _ev: AxisDiscrete, _slf: &Rc) -> Result<(), Self::Error> { self.any_scroll_events.set(true); Ok(()) } - fn axis_value120(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: AxisValue120 = self.con.parse(self, parser)?; + fn axis_value120(&self, ev: AxisValue120, _slf: &Rc) -> Result<(), Self::Error> { if ev.axis < 2 { self.pending_scroll.v120[ev.axis as usize].set(Some(ev.value120)); } self.any_scroll_events.set(true); Ok(()) } + + fn axis_relative_direction( + &self, + _ev: AxisRelativeDirection, + _slf: &Rc, + ) -> Result<(), Self::Error> { + Ok(()) + } } usr_object_base! { - UsrWlPointer, WlPointer; - - ENTER => enter, - LEAVE => leave, - MOTION => motion, - BUTTON => button, - AXIS => axis, - FRAME => frame, - AXIS_SOURCE => axis_source, - AXIS_STOP => axis_stop, - AXIS_DISCRETE => axis_discrete, - AXIS_VALUE120 => axis_value120, + self = UsrWlPointer = WlPointer; + version = self.version; } impl UsrObject for UsrWlPointer { diff --git a/src/wl_usr/usr_ifs/usr_wl_registry.rs b/src/wl_usr/usr_ifs/usr_wl_registry.rs index acfe7bc8..011c97ab 100644 --- a/src/wl_usr/usr_ifs/usr_wl_registry.rs +++ b/src/wl_usr/usr_ifs/usr_wl_registry.rs @@ -1,19 +1,18 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{wl_registry::*, WlRegistryId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWlRegistry { pub id: WlRegistryId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrWlRegistryOwner { @@ -38,17 +37,19 @@ impl UsrWlRegistry { id: obj.id(), }); } +} + +impl WlRegistryEventHandler for UsrWlRegistry { + type Error = Infallible; - fn global(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Global = self.con.parse(self, parser)?; + fn global(&self, ev: Global<'_>, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.global(ev.name, ev.interface, ev.version); } Ok(()) } - fn global_remove(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: GlobalRemove = self.con.parse(self, parser)?; + fn global_remove(&self, ev: GlobalRemove, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.global_remove(ev.name); } @@ -57,10 +58,8 @@ impl UsrWlRegistry { } usr_object_base! { - UsrWlRegistry, WlRegistry; - - GLOBAL => global, - GLOBAL_REMOVE => global_remove, + self = UsrWlRegistry = WlRegistry; + version = self.version; } impl UsrObject for UsrWlRegistry { diff --git a/src/wl_usr/usr_ifs/usr_wl_seat.rs b/src/wl_usr/usr_ifs/usr_wl_seat.rs index 5f0c89bf..602eb820 100644 --- a/src/wl_usr/usr_ifs/usr_wl_seat.rs +++ b/src/wl_usr/usr_ifs/usr_wl_seat.rs @@ -1,19 +1,18 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{wl_seat::*, WlSeatId}, wl_usr::{usr_ifs::usr_wl_pointer::UsrWlPointer, usr_object::UsrObject, UsrCon}, }, - std::{cell::Cell, rc::Rc}, + std::{cell::Cell, convert::Infallible, rc::Rc}, }; pub struct UsrWlSeat { pub id: WlSeatId, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrWlSeatOwner { @@ -34,6 +33,7 @@ impl UsrWlSeat { owner: Default::default(), any_scroll_events: Cell::new(false), pending_scroll: Default::default(), + version: self.version, }); self.con.add_object(ptr.clone()); self.con.request(GetPointer { @@ -42,17 +42,19 @@ impl UsrWlSeat { }); ptr } +} + +impl WlSeatEventHandler for UsrWlSeat { + type Error = Infallible; - fn capabilities(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Capabilities = self.con.parse(self, parser)?; + fn capabilities(&self, ev: Capabilities, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.capabilities(ev.capabilities); } Ok(()) } - fn name(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Name = self.con.parse(self, parser)?; + fn name(&self, ev: Name<'_>, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.name(ev.name); } @@ -61,10 +63,8 @@ impl UsrWlSeat { } usr_object_base! { - UsrWlSeat, WlSeat; - - CAPABILITIES => capabilities, - NAME => name, + self = UsrWlSeat = WlSeat; + version = self.version; } impl UsrObject for UsrWlSeat { diff --git a/src/wl_usr/usr_ifs/usr_wl_shm.rs b/src/wl_usr/usr_ifs/usr_wl_shm.rs index e2aa1ddb..d608b39f 100644 --- a/src/wl_usr/usr_ifs/usr_wl_shm.rs +++ b/src/wl_usr/usr_ifs/usr_wl_shm.rs @@ -1,14 +1,12 @@ use { crate::{ format::{formats, map_wayland_format_id}, - utils::{ - buffd::{MsgParser, MsgParserError}, - copyhashmap::CopyHashMap, - }, + object::Version, + utils::copyhashmap::CopyHashMap, wire::{wl_shm::*, WlShmId}, wl_usr::{usr_ifs::usr_wl_shm_pool::UsrWlShmPool, usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, uapi::OwnedFd, }; @@ -16,6 +14,7 @@ pub struct UsrWlShm { pub id: WlShmId, pub con: Rc, pub formats: CopyHashMap, + pub version: Version, } impl UsrWlShm { @@ -24,6 +23,7 @@ impl UsrWlShm { let pool = Rc::new(UsrWlShmPool { id: self.con.id(), con: self.con.clone(), + version: self.version, }); self.con.request(CreatePool { self_id: self.id, @@ -34,9 +34,12 @@ impl UsrWlShm { self.con.add_object(pool.clone()); pool } +} + +impl WlShmEventHandler for UsrWlShm { + type Error = Infallible; - fn format(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Format = self.con.parse(self, parser)?; + fn format(&self, ev: Format, _slf: &Rc) -> Result<(), Self::Error> { let format = map_wayland_format_id(ev.format); if let Some(format) = formats().get(&format) { self.formats.set(format.drm, *format); @@ -46,9 +49,8 @@ impl UsrWlShm { } usr_object_base! { - UsrWlShm, WlShm; - - FORMAT => format, + self = UsrWlShm = WlShm; + version = self.version; } impl UsrObject for UsrWlShm { diff --git a/src/wl_usr/usr_ifs/usr_wl_shm_pool.rs b/src/wl_usr/usr_ifs/usr_wl_shm_pool.rs index 6aa7fd39..47ec5176 100644 --- a/src/wl_usr/usr_ifs/usr_wl_shm_pool.rs +++ b/src/wl_usr/usr_ifs/usr_wl_shm_pool.rs @@ -1,14 +1,16 @@ use { crate::{ + object::Version, wire::{wl_shm_pool::*, WlShmPoolId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWlShmPool { pub id: WlShmPoolId, pub con: Rc, + pub version: Version, } impl UsrWlShmPool { @@ -21,8 +23,13 @@ impl UsrWlShmPool { } } +impl WlShmPoolEventHandler for UsrWlShmPool { + type Error = Infallible; +} + usr_object_base! { - UsrWlShmPool, WlShmPool; + self = UsrWlShmPool = WlShmPool; + version = self.version; } impl UsrObject for UsrWlShmPool { diff --git a/src/wl_usr/usr_ifs/usr_wl_surface.rs b/src/wl_usr/usr_ifs/usr_wl_surface.rs index c8b3874d..3a3fc616 100644 --- a/src/wl_usr/usr_ifs/usr_wl_surface.rs +++ b/src/wl_usr/usr_ifs/usr_wl_surface.rs @@ -1,6 +1,6 @@ use { crate::{ - utils::buffd::{MsgParser, MsgParserError}, + object::Version, wire::{wl_surface::*, WlSurfaceId}, wl_usr::{ usr_ifs::{usr_wl_buffer::UsrWlBuffer, usr_wl_callback::UsrWlCallback}, @@ -8,12 +8,13 @@ use { UsrCon, }, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWlSurface { pub id: WlSurfaceId, pub con: Rc, + pub version: Version, } impl UsrWlSurface { @@ -41,35 +42,39 @@ impl UsrWlSurface { pub fn commit(&self) { self.con.request(Commit { self_id: self.id }); } +} + +impl WlSurfaceEventHandler for UsrWlSurface { + type Error = Infallible; - fn enter(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Enter = self.con.parse(self, parser)?; + fn enter(&self, _ev: Enter, _slf: &Rc) -> Result<(), Self::Error> { Ok(()) } - fn leave(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Leave = self.con.parse(self, parser)?; + fn leave(&self, _ev: Leave, _slf: &Rc) -> Result<(), Self::Error> { Ok(()) } - fn preferred_buffer_scale(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: PreferredBufferScale = self.con.parse(self, parser)?; + fn preferred_buffer_scale( + &self, + _ev: PreferredBufferScale, + _slf: &Rc, + ) -> Result<(), Self::Error> { Ok(()) } - fn preferred_buffer_transform(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: PreferredBufferTransform = self.con.parse(self, parser)?; + fn preferred_buffer_transform( + &self, + _ev: PreferredBufferTransform, + _slf: &Rc, + ) -> Result<(), Self::Error> { Ok(()) } } usr_object_base! { - UsrWlSurface, WlSurface; - - ENTER => enter, - LEAVE => leave, - PREFERRED_BUFFER_SCALE => preferred_buffer_scale, - PREFERRED_BUFFER_TRANSFORM => preferred_buffer_transform, + self = UsrWlSurface = WlSurface; + version = self.version; } impl UsrObject for UsrWlSurface { diff --git a/src/wl_usr/usr_ifs/usr_wlr_layer_shell.rs b/src/wl_usr/usr_ifs/usr_wlr_layer_shell.rs index c95660c4..05dca20c 100644 --- a/src/wl_usr/usr_ifs/usr_wlr_layer_shell.rs +++ b/src/wl_usr/usr_ifs/usr_wlr_layer_shell.rs @@ -1,5 +1,6 @@ use { crate::{ + object::Version, wire::{zwlr_layer_shell_v1::*, ZwlrLayerShellV1Id}, wl_usr::{ usr_ifs::{ @@ -10,12 +11,13 @@ use { UsrCon, }, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWlrLayerShell { pub id: ZwlrLayerShellV1Id, pub con: Rc, + pub version: Version, } impl UsrWlrLayerShell { @@ -29,6 +31,7 @@ impl UsrWlrLayerShell { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.add_object(sfc.clone()); self.con.request(GetLayerSurface { @@ -43,8 +46,13 @@ impl UsrWlrLayerShell { } } +impl ZwlrLayerShellV1EventHandler for UsrWlrLayerShell { + type Error = Infallible; +} + usr_object_base! { - UsrWlrLayerShell, ZwlrLayerShellV1; + self = UsrWlrLayerShell = ZwlrLayerShellV1; + version = self.version; } impl UsrObject for UsrWlrLayerShell { diff --git a/src/wl_usr/usr_ifs/usr_wlr_layer_surface.rs b/src/wl_usr/usr_ifs/usr_wlr_layer_surface.rs index c2d5f33a..c5bdb125 100644 --- a/src/wl_usr/usr_ifs/usr_wlr_layer_surface.rs +++ b/src/wl_usr/usr_ifs/usr_wlr_layer_surface.rs @@ -1,19 +1,18 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{zwlr_layer_surface_v1::*, ZwlrLayerSurfaceV1Id}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWlrLayerSurface { pub id: ZwlrLayerSurfaceV1Id, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrWlrLayerSurfaceOwner { @@ -48,9 +47,12 @@ impl UsrWlrLayerSurface { layer, }); } +} + +impl ZwlrLayerSurfaceV1EventHandler for UsrWlrLayerSurface { + type Error = Infallible; - fn configure(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Configure = self.con.parse(self, parser)?; + fn configure(&self, ev: Configure, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.configure(&ev); } @@ -61,8 +63,7 @@ impl UsrWlrLayerSurface { Ok(()) } - fn closed(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Closed = self.con.parse(self, parser)?; + fn closed(&self, _ev: Closed, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.closed(); } @@ -71,10 +72,8 @@ impl UsrWlrLayerSurface { } usr_object_base! { - UsrWlrLayerSurface, ZwlrLayerSurfaceV1; - - CONFIGURE => configure, - CLOSED => closed, + self = UsrWlrLayerSurface = ZwlrLayerSurfaceV1; + version = self.version; } impl UsrObject for UsrWlrLayerSurface { diff --git a/src/wl_usr/usr_ifs/usr_wp_fractional_scale.rs b/src/wl_usr/usr_ifs/usr_wp_fractional_scale.rs index e704bd2d..aead1783 100644 --- a/src/wl_usr/usr_ifs/usr_wp_fractional_scale.rs +++ b/src/wl_usr/usr_ifs/usr_wp_fractional_scale.rs @@ -1,19 +1,18 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{wp_fractional_scale_v1::*, WpFractionalScaleV1Id}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWpFractionalScale { pub id: WpFractionalScaleV1Id, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrWpFractionalScaleOwner { @@ -22,9 +21,10 @@ pub trait UsrWpFractionalScaleOwner { } } -impl UsrWpFractionalScale { - fn preferred_scale(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: PreferredScale = self.con.parse(self, parser)?; +impl WpFractionalScaleV1EventHandler for UsrWpFractionalScale { + type Error = Infallible; + + fn preferred_scale(&self, ev: PreferredScale, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.preferred_scale(&ev); } @@ -33,9 +33,8 @@ impl UsrWpFractionalScale { } usr_object_base! { - UsrWpFractionalScale, WpFractionalScaleV1; - - PREFERRED_SCALE => preferred_scale, + self = UsrWpFractionalScale = WpFractionalScaleV1; + version = self.version; } impl UsrObject for UsrWpFractionalScale { diff --git a/src/wl_usr/usr_ifs/usr_wp_fractional_scale_manager.rs b/src/wl_usr/usr_ifs/usr_wp_fractional_scale_manager.rs index 553587b0..c5d2ed11 100644 --- a/src/wl_usr/usr_ifs/usr_wp_fractional_scale_manager.rs +++ b/src/wl_usr/usr_ifs/usr_wp_fractional_scale_manager.rs @@ -1,5 +1,6 @@ use { crate::{ + object::Version, wire::{wp_fractional_scale_manager_v1::*, WpFractionalScaleManagerV1Id}, wl_usr::{ usr_ifs::{ @@ -9,12 +10,13 @@ use { UsrCon, }, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWpFractionalScaleManager { pub id: WpFractionalScaleManagerV1Id, pub con: Rc, + pub version: Version, } impl UsrWpFractionalScaleManager { @@ -23,6 +25,7 @@ impl UsrWpFractionalScaleManager { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.add_object(fs.clone()); self.con.request(GetFractionalScale { @@ -34,8 +37,13 @@ impl UsrWpFractionalScaleManager { } } +impl WpFractionalScaleManagerV1EventHandler for UsrWpFractionalScaleManager { + type Error = Infallible; +} + usr_object_base! { - UsrWpFractionalScaleManager, WpFractionalScaleManagerV1; + self = UsrWpFractionalScaleManager = WpFractionalScaleManagerV1; + version = self.version; } impl UsrObject for UsrWpFractionalScaleManager { diff --git a/src/wl_usr/usr_ifs/usr_wp_viewport.rs b/src/wl_usr/usr_ifs/usr_wp_viewport.rs index 64964078..22fda7ba 100644 --- a/src/wl_usr/usr_ifs/usr_wp_viewport.rs +++ b/src/wl_usr/usr_ifs/usr_wp_viewport.rs @@ -1,15 +1,17 @@ use { crate::{ fixed::Fixed, + object::Version, wire::{wp_viewport::*, WpViewportId}, wl_usr::{usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWpViewport { pub id: WpViewportId, pub con: Rc, + pub version: Version, } impl UsrWpViewport { @@ -33,8 +35,13 @@ impl UsrWpViewport { } } +impl WpViewportEventHandler for UsrWpViewport { + type Error = Infallible; +} + usr_object_base! { - UsrWpViewport, WpViewport; + self = UsrWpViewport = WpViewport; + version = self.version; } impl UsrObject for UsrWpViewport { diff --git a/src/wl_usr/usr_ifs/usr_wp_viewporter.rs b/src/wl_usr/usr_ifs/usr_wp_viewporter.rs index 0f3e224e..aecc2f03 100644 --- a/src/wl_usr/usr_ifs/usr_wp_viewporter.rs +++ b/src/wl_usr/usr_ifs/usr_wp_viewporter.rs @@ -1,5 +1,6 @@ use { crate::{ + object::Version, wire::{wp_viewporter::*, WpViewporterId}, wl_usr::{ usr_ifs::{usr_wl_surface::UsrWlSurface, usr_wp_viewport::UsrWpViewport}, @@ -7,12 +8,13 @@ use { UsrCon, }, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrWpViewporter { pub id: WpViewporterId, pub con: Rc, + pub version: Version, } impl UsrWpViewporter { @@ -20,6 +22,7 @@ impl UsrWpViewporter { let wv = Rc::new(UsrWpViewport { id: self.con.id(), con: self.con.clone(), + version: self.version, }); self.con.add_object(wv.clone()); self.con.request(GetViewport { @@ -31,8 +34,13 @@ impl UsrWpViewporter { } } +impl WpViewporterEventHandler for UsrWpViewporter { + type Error = Infallible; +} + usr_object_base! { - UsrWpViewporter, WpViewporter; + self = UsrWpViewporter = WpViewporter; + version = self.version; } impl UsrObject for UsrWpViewporter { diff --git a/src/wl_usr/usr_ifs/usr_zwlr_screencopy_frame.rs b/src/wl_usr/usr_ifs/usr_zwlr_screencopy_frame.rs index d5cb19a9..329d0624 100644 --- a/src/wl_usr/usr_ifs/usr_zwlr_screencopy_frame.rs +++ b/src/wl_usr/usr_ifs/usr_zwlr_screencopy_frame.rs @@ -1,19 +1,18 @@ use { crate::{ - utils::{ - buffd::{MsgParser, MsgParserError}, - clonecell::CloneCell, - }, + object::Version, + utils::clonecell::CloneCell, wire::{zwlr_screencopy_frame_v1::*, ZwlrScreencopyFrameV1Id}, wl_usr::{usr_ifs::usr_wl_buffer::UsrWlBuffer, usr_object::UsrObject, UsrCon}, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; pub struct UsrZwlrScreencopyFrame { pub id: ZwlrScreencopyFrameV1Id, pub con: Rc, pub owner: CloneCell>>, + pub version: Version, } pub trait UsrZwlrScreencopyFrameOwner { @@ -58,57 +57,54 @@ impl UsrZwlrScreencopyFrame { buffer: buffer.id, }); } +} + +impl ZwlrScreencopyFrameV1EventHandler for UsrZwlrScreencopyFrame { + type Error = Infallible; - fn buffer(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Buffer = self.con.parse(self, parser)?; + fn buffer(&self, ev: Buffer, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.buffer(&ev); } Ok(()) } - fn flags(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Flags = self.con.parse(self, parser)?; + fn flags(&self, ev: Flags, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.flags(&ev); } Ok(()) } - fn ready(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Ready = self.con.parse(self, parser)?; + fn ready(&self, ev: Ready, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.ready(&ev); } Ok(()) } - fn failed(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: Failed = self.con.parse(self, parser)?; + fn failed(&self, _ev: Failed, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.failed(); } Ok(()) } - fn damage(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: Damage = self.con.parse(self, parser)?; + fn damage(&self, ev: Damage, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.damage(&ev); } Ok(()) } - fn linux_dmabuf(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let ev: LinuxDmabuf = self.con.parse(self, parser)?; + fn linux_dmabuf(&self, ev: LinuxDmabuf, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.linux_dmabuf(&ev); } Ok(()) } - fn buffer_done(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> { - let _ev: BufferDone = self.con.parse(self, parser)?; + fn buffer_done(&self, _ev: BufferDone, _slf: &Rc) -> Result<(), Self::Error> { if let Some(owner) = self.owner.get() { owner.buffer_done(); } @@ -117,15 +113,8 @@ impl UsrZwlrScreencopyFrame { } usr_object_base! { - UsrZwlrScreencopyFrame, ZwlrScreencopyFrameV1; - - BUFFER => buffer, - FLAGS => flags, - READY => ready, - FAILED => failed, - DAMAGE => damage, - LINUX_DMABUF => linux_dmabuf, - BUFFER_DONE => buffer_done, + self = UsrZwlrScreencopyFrame = ZwlrScreencopyFrameV1; + version = self.version; } impl UsrObject for UsrZwlrScreencopyFrame { diff --git a/src/wl_usr/usr_ifs/usr_zwlr_screencopy_manager.rs b/src/wl_usr/usr_ifs/usr_zwlr_screencopy_manager.rs index e38ddd99..fe1228e3 100644 --- a/src/wl_usr/usr_ifs/usr_zwlr_screencopy_manager.rs +++ b/src/wl_usr/usr_ifs/usr_zwlr_screencopy_manager.rs @@ -1,5 +1,6 @@ use { crate::{ + object::Version, wire::{zwlr_screencopy_manager_v1::*, ZwlrScreencopyManagerV1Id}, wl_usr::{ usr_ifs::{ @@ -9,11 +10,13 @@ use { UsrCon, }, }, - std::rc::Rc, + std::{convert::Infallible, rc::Rc}, }; + pub struct UsrZwlrScreencopyManager { pub id: ZwlrScreencopyManagerV1Id, pub con: Rc, + pub version: Version, } impl UsrZwlrScreencopyManager { @@ -23,6 +26,7 @@ impl UsrZwlrScreencopyManager { id: self.con.id(), con: self.con.clone(), owner: Default::default(), + version: self.version, }); self.con.request(CaptureOutput { self_id: self.id, @@ -35,8 +39,13 @@ impl UsrZwlrScreencopyManager { } } +impl ZwlrScreencopyManagerV1EventHandler for UsrZwlrScreencopyManager { + type Error = Infallible; +} + usr_object_base! { - UsrZwlrScreencopyManager, ZwlrScreencopyManagerV1; + self = UsrZwlrScreencopyManager = ZwlrScreencopyManagerV1; + version = self.version; } impl UsrObject for UsrZwlrScreencopyManager { diff --git a/src/wl_usr/usr_object.rs b/src/wl_usr/usr_object.rs index 23a126d2..a2cb572a 100644 --- a/src/wl_usr/usr_object.rs +++ b/src/wl_usr/usr_object.rs @@ -1,40 +1,22 @@ use { crate::{ - object::{Interface, ObjectId}, + object::{Interface, ObjectId, Version}, utils::buffd::MsgParser, + wl_usr::{UsrCon, UsrConError}, }, std::rc::Rc, - thiserror::Error, }; -#[derive(Debug, Error)] -pub enum UsrObjectErrorType { - #[error("Could not process a `{event}` event")] - EventError { - event: &'static str, - #[source] - error: Box, - }, - #[error("Unknown event {event}")] - UnknownEventError { event: u32 }, -} - -#[derive(Debug, Error)] -#[error("An error occurred in a `{}`", .interface.name())] -pub struct UsrObjectError { - pub interface: Interface, - #[source] - pub ty: UsrObjectErrorType, -} - pub trait UsrObjectBase { fn id(&self) -> ObjectId; fn handle_event( self: Rc, + con: &UsrCon, event: u32, parser: MsgParser<'_, '_>, - ) -> Result<(), UsrObjectError>; + ) -> Result<(), UsrConError>; fn interface(&self) -> Interface; + fn version(&self) -> Version; } pub trait UsrObject: UsrObjectBase + 'static { diff --git a/wire/wl_data_offer.txt b/wire/wl_data_offer.txt index 9170585f..92dc40e1 100644 --- a/wire/wl_data_offer.txt +++ b/wire/wl_data_offer.txt @@ -27,10 +27,10 @@ event offer { mime_type: str, } -event source_actions { +event source_actions (since = 3) { source_actions: u32, } -event action { +event action (since = 3) { dnd_action: u32, } diff --git a/wire/wl_data_source.txt b/wire/wl_data_source.txt index 4dea03b1..870da7a1 100644 --- a/wire/wl_data_source.txt +++ b/wire/wl_data_source.txt @@ -27,14 +27,14 @@ event cancelled { } -event dnd_drop_performed { +event dnd_drop_performed (since = 3) { } -event dnd_finished { +event dnd_finished (since = 3) { } -event action { +event action (since = 3) { dnd_action: u32, } diff --git a/wire/wl_keyboard.txt b/wire/wl_keyboard.txt index eeb62f7b..2ad3264f 100644 --- a/wire/wl_keyboard.txt +++ b/wire/wl_keyboard.txt @@ -38,7 +38,7 @@ event modifiers { group: u32, } -event repeat_info { +event repeat_info (since = 4) { rate: i32, delay: i32, } diff --git a/wire/wl_output.txt b/wire/wl_output.txt index 06b154bf..b09c6f2a 100644 --- a/wire/wl_output.txt +++ b/wire/wl_output.txt @@ -24,18 +24,18 @@ event mode { refresh : i32, } -event done { +event done (since = 2) { } -event scale { +event scale (since = 2) { factor: i32, } -event name { +event name (since = 4) { name: str, } -event description { +event description (since = 4) { description: str, } diff --git a/wire/wl_pointer.txt b/wire/wl_pointer.txt index 33aeabf3..c1c038a9 100644 --- a/wire/wl_pointer.txt +++ b/wire/wl_pointer.txt @@ -44,30 +44,30 @@ event axis { value: fixed, } -event frame { +event frame (since = 5) { } -event axis_source { +event axis_source (since = 5) { axis_source: u32, } -event axis_stop { +event axis_stop (since = 5) { time: u32, axis: u32, } -event axis_discrete { +event axis_discrete (since = 5) { axis: u32, discrete: i32, } -event axis_value120 { +event axis_value120 (since = 8) { axis: u32, value120: i32, } -event axis_relative_direction { +event axis_relative_direction (since = 9) { axis: u32, direction: u32, } diff --git a/wire/wl_seat.txt b/wire/wl_seat.txt index f3036720..b3b314a5 100644 --- a/wire/wl_seat.txt +++ b/wire/wl_seat.txt @@ -21,6 +21,6 @@ event capabilities { capabilities: u32, } -event name { +event name (since = 2) { name: str, } diff --git a/wire/wl_surface.txt b/wire/wl_surface.txt index 219b098f..9d3bad32 100644 --- a/wire/wl_surface.txt +++ b/wire/wl_surface.txt @@ -61,10 +61,10 @@ event leave { output: id(wl_output), } -event preferred_buffer_scale { +event preferred_buffer_scale (since = 6) { factor: i32, } -event preferred_buffer_transform { +event preferred_buffer_transform (since = 6) { transform: u32, } diff --git a/wire/wl_touch.txt b/wire/wl_touch.txt index a5a21c3f..d88f4600 100644 --- a/wire/wl_touch.txt +++ b/wire/wl_touch.txt @@ -36,13 +36,13 @@ event cancel { } -event shape { +event shape (since = 6) { id: i32, major: fixed, minor: fixed, } -event orientation { +event orientation (since = 6) { id: i32, orientation: fixed, } diff --git a/wire/xdg_popup.txt b/wire/xdg_popup.txt index a703e617..a6506d96 100644 --- a/wire/xdg_popup.txt +++ b/wire/xdg_popup.txt @@ -25,6 +25,6 @@ event popup_done { } -event repositioned { +event repositioned (since = 3) { token: u32, } diff --git a/wire/xdg_toplevel.txt b/wire/xdg_toplevel.txt index 4a746478..d9a2ab52 100644 --- a/wire/xdg_toplevel.txt +++ b/wire/xdg_toplevel.txt @@ -68,11 +68,11 @@ event configure { event close { } -event configure_bounds { +event configure_bounds (since = 4) { width: i32, height: i32, } -event wm_capabilities { +event wm_capabilities (since = 5) { capabilities: array(u32), } diff --git a/wire/zwp_linux_dmabuf_v1.txt b/wire/zwp_linux_dmabuf_v1.txt index 3faf9431..9b6e9052 100644 --- a/wire/zwp_linux_dmabuf_v1.txt +++ b/wire/zwp_linux_dmabuf_v1.txt @@ -21,7 +21,7 @@ event format { format: u32, } -event modifier { +event modifier (since = 3) { format: u32, modifier_hi: u32, modifier_lo: u32, diff --git a/wire/zwp_pointer_gesture_hold_v1.txt b/wire/zwp_pointer_gesture_hold_v1.txt index 14c9cd11..a8df1216 100644 --- a/wire/zwp_pointer_gesture_hold_v1.txt +++ b/wire/zwp_pointer_gesture_hold_v1.txt @@ -2,14 +2,14 @@ request destroy (since = 3) { } -event begin { +event begin (since = 3) { serial: u32, time: u32, surface: id(wl_surface), fingers: u32, } -event end { +event end (since = 3) { serial: u32, time: u32, cancelled: i32, diff --git a/wire/zxdg_output_v1.txt b/wire/zxdg_output_v1.txt index e3f09af5..5374427f 100644 --- a/wire/zxdg_output_v1.txt +++ b/wire/zxdg_output_v1.txt @@ -16,10 +16,10 @@ event logical_size { event done { } -event name { +event name (since = 2) { name: str, } -event description { +event description (since = 2) { description: str, }