From 96038f49bc60d2efc0847fa5f6c91f1e972d984c Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 6 Feb 2022 20:12:09 +0100 Subject: [PATCH] autocommit 2022-02-06 20:12:09 CET --- build/wire.rs | 58 +++++-------------- src/client/mod.rs | 2 +- src/ifs/wl_data_offer.rs | 8 +-- src/ifs/wl_data_source.rs | 6 +- src/ifs/wl_display.rs | 10 ++-- src/ifs/wl_drm.rs | 4 +- src/ifs/wl_output.rs | 6 +- src/ifs/wl_registry.rs | 6 +- src/ifs/wl_seat.rs | 7 +-- src/ifs/wl_seat/handling.rs | 2 +- src/ifs/wl_seat/wl_keyboard.rs | 4 +- src/ifs/wl_surface/xdg_surface.rs | 4 +- .../wl_surface/xdg_surface/xdg_toplevel.rs | 9 +-- src/ifs/xdg_positioner.rs | 6 +- src/ifs/xdg_wm_base.rs | 2 +- src/ifs/zwp_primary_selection_offer_v1.rs | 6 +- src/ifs/zwp_primary_selection_source_v1.rs | 6 +- src/utils/buffd/buf_out.rs | 4 -- 18 files changed, 60 insertions(+), 90 deletions(-) diff --git a/build/wire.rs b/build/wire.rs index 392967e2..75f8a2fc 100644 --- a/build/wire.rs +++ b/build/wire.rs @@ -491,61 +491,41 @@ fn to_camel(s: &BStr) -> BString { res.into() } -fn write_type(f: &mut W, ty: &Type, role: TypeRole) -> Result<()> { +fn write_type(f: &mut W, ty: &Type) -> Result<()> { match ty { Type::Id(id) => write!(f, "{}Id", id)?, Type::U32 => write!(f, "u32")?, Type::I32 => write!(f, "i32")?, - Type::Str if role == TypeRole::In => write!(f, "&'a str")?, - Type::Str => write!(f, "String")?, - Type::BStr if role == TypeRole::In => write!(f, "&'a BStr")?, - Type::BStr => write!(f, "BString")?, + Type::Str => write!(f, "&'a str")?, + Type::BStr => write!(f, "&'a BStr")?, Type::Fixed => write!(f, "Fixed")?, Type::Fd => write!(f, "Rc")?, - Type::Array(n) if role == TypeRole::In => { + Type::Array(n) => { write!(f, "&'a [")?; - write_type(f, n, role)?; + write_type(f, n)?; write!(f, "]")?; }, - Type::Array(n) => { - write!(f, "Vec<")?; - write_type(f, n, role)?; - write!(f, ">")?; - } Type::Pod(p) => f.write_all(p.as_bytes())?, } Ok(()) } -fn write_field(f: &mut W, field: &Field, role: TypeRole) -> Result<()> { +fn write_field(f: &mut W, field: &Field) -> Result<()> { write!(f, " pub {}: ", field.name)?; - write_type(f, &field.ty.val, role)?; + write_type(f, &field.ty.val)?; writeln!(f, ",")?; Ok(()) } -#[derive(Copy, Clone, Eq, PartialEq)] -enum TypeRole { - Unified, - In, - Out, -} - -fn write_message_type(f: &mut W, obj: &BStr, message: &Message, role: TypeRole) -> Result<()> { - let suffix = match role { - TypeRole::Unified => "", - TypeRole::In => "In", - TypeRole::Out => "Out", - }; - let needs_lifetime = role == TypeRole::In; +fn write_message_type(f: &mut W, obj: &BStr, message: &Message, needs_lifetime: bool) -> Result<()> { let lifetime = if needs_lifetime { "<'a>" } else { "" }; - writeln!(f, " pub struct {}{}{} {{", message.camel_name, suffix, lifetime)?; + writeln!(f, " pub struct {}{} {{", message.camel_name, lifetime)?; writeln!(f, " pub self_id: {}Id,", obj)?; for field in &message.fields { - write_field(f, &field.val, role)?; + write_field(f, &field.val)?; } writeln!(f, " }}")?; - writeln!(f, " impl{} std::fmt::Debug for {}{}{} {{", lifetime, message.camel_name, suffix, lifetime)?; + writeln!(f, " impl{} std::fmt::Debug for {}{} {{", lifetime, message.camel_name, lifetime)?; writeln!(f, " fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {{")?; write!(f, r#" write!(fmt, "{}("#, message.name)?; for (i, field) in message.fields.iter().enumerate() { @@ -577,19 +557,14 @@ fn write_message(f: &mut W, obj: &BStr, message: &Message) -> Result<( let uppercase = uppercase.as_bstr(); writeln!(f)?; writeln!(f, " pub const {}: u32 = {};", uppercase, message.id.val)?; - if has_reference_type { - write_message_type(f, obj, message, TypeRole::In)?; - write_message_type(f, obj, message, TypeRole::Out)?; - } else { - write_message_type(f, obj, message, TypeRole::Unified)?; - } + write_message_type(f, obj, message, has_reference_type)?; let lifetime = if has_reference_type { "<'a>"} else {""}; let parser = if message.fields.len() > 0 { "parser" } else { "_parser" }; - writeln!(f, " impl<'a> RequestParser<'a> for {}{}{} {{", message.camel_name, if has_reference_type { "In" } else { "" }, lifetime)?; + writeln!(f, " impl<'a> RequestParser<'a> for {}{} {{", message.camel_name, lifetime)?; writeln!(f, " fn parse({}: &mut MsgParser<'_, 'a>) -> Result {{", parser)?; writeln!(f, " Ok(Self {{")?; writeln!(f, " self_id: {}Id::NONE,", obj)?; @@ -610,7 +585,7 @@ fn write_message(f: &mut W, obj: &BStr, message: &Message) -> Result<( writeln!(f, " }})")?; writeln!(f, " }}")?; writeln!(f, " }}")?; - writeln!(f, " impl EventFormatter for {}{} {{", message.camel_name, if has_reference_type { "Out" } else { "" })?; + writeln!(f, " impl{} EventFormatter for {}{} {{", lifetime, message.camel_name, lifetime)?; writeln!(f, " fn format(self, fmt: &mut MsgFormatter<'_>) {{")?; writeln!(f, " fmt.header(self.self_id, {});", uppercase)?; fn write_fmt_expr(f: &mut W, prefix: &str, ty: &Type, access: &str) -> Result<()> { @@ -625,8 +600,7 @@ fn write_message(f: &mut W, obj: &BStr, message: &Message) -> Result<( Type::Pod(..) => "binary", }; let rf = match ty { - Type::Str | Type::BStr | Type::Pod(..) => "&", - Type::Array(..) => "&*", + Type::Pod(..) => "&", _ => "", }; writeln!(f, " {}fmt.{}({}{});", prefix, p, rf, access)?; @@ -673,7 +647,7 @@ pub fn main() -> Result<()> { let mut f = open("wire.rs")?; writeln!(f, "use std::rc::Rc;")?; writeln!(f, "use uapi::OwnedFd;")?; - writeln!(f, "use bstr::{{BStr, BString}};")?; + writeln!(f, "use bstr::BStr;")?; writeln!(f, "use crate::fixed::Fixed;")?; writeln!(f, "use crate::client::{{EventFormatter, RequestParser}};")?; writeln!(f, "use crate::object::ObjectId;")?; diff --git a/src/client/mod.rs b/src/client/mod.rs index 4c0b0ad7..b64c929d 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -258,7 +258,7 @@ impl Client { } } - pub fn protocol_error(&self, obj: &dyn Object, code: u32, message: String) { + pub fn protocol_error(&self, obj: &dyn Object, code: u32, message: &str) { if let Ok(d) = self.display() { d.send_error(obj.id(), code, message); } diff --git a/src/ifs/wl_data_offer.rs b/src/ifs/wl_data_offer.rs index a827b0e7..52aff0b7 100644 --- a/src/ifs/wl_data_offer.rs +++ b/src/ifs/wl_data_offer.rs @@ -76,19 +76,19 @@ impl WlDataOffer { } pub fn send_offer(self: &Rc, mime_type: &str) { - self.client.event(OfferOut { + self.client.event(Offer { self_id: self.id, - mime_type: mime_type.to_string(), + mime_type, }) } fn accept(&self, parser: MsgParser<'_, '_>) -> Result<(), AcceptError> { - let _req: AcceptIn = self.client.parse(self, parser)?; + let _req: Accept = self.client.parse(self, parser)?; Ok(()) } fn receive(&self, parser: MsgParser<'_, '_>) -> Result<(), ReceiveError> { - let req: ReceiveIn = self.client.parse(self, parser)?; + let req: Receive = self.client.parse(self, parser)?; if let Some(src) = self.source.get() { src.send_send(req.mime_type, req.fd); src.client.flush(); diff --git a/src/ifs/wl_data_source.rs b/src/ifs/wl_data_source.rs index a3014ef4..ee335fa7 100644 --- a/src/ifs/wl_data_source.rs +++ b/src/ifs/wl_data_source.rs @@ -94,15 +94,15 @@ impl WlDataSource { } pub fn send_send(&self, mime_type: &str, fd: Rc) { - self.client.event(SendOut { + self.client.event(Send { self_id: self.id, - mime_type: mime_type.to_string(), + mime_type, fd, }) } fn offer(&self, parser: MsgParser<'_, '_>) -> Result<(), OfferError> { - let req: OfferIn = self.client.parse(self, parser)?; + let req: Offer = self.client.parse(self, parser)?; if self .mime_types .borrow_mut() diff --git a/src/ifs/wl_display.rs b/src/ifs/wl_display.rs index d754e05b..e199322f 100644 --- a/src/ifs/wl_display.rs +++ b/src/ifs/wl_display.rs @@ -54,9 +54,9 @@ impl WlDisplay { &self, object_id: O, code: u32, - message: String, + message: &str, ) { - self.client.event(ErrorOut { + self.client.event(Error { self_id: self.id, object_id: object_id.into(), code, @@ -72,16 +72,16 @@ impl WlDisplay { obj.interface().name(), request ); - self.send_error(id, INVALID_METHOD, msg) + self.send_error(id, INVALID_METHOD, &msg) } pub fn send_invalid_object(self: &Rc, id: ObjectId) { let msg = format!("Object {} does not exist", id,); - self.send_error(id, INVALID_OBJECT, msg) + self.send_error(id, INVALID_OBJECT, &msg) } pub fn send_implementation_error(self: &Rc, msg: String) { - self.send_error(WL_DISPLAY_ID, IMPLEMENTATION, msg) + self.send_error(WL_DISPLAY_ID, IMPLEMENTATION, &msg) } pub fn send_delete_id(self: &Rc, id: ObjectId) { diff --git a/src/ifs/wl_drm.rs b/src/ifs/wl_drm.rs index e7a6f367..ebe81852 100644 --- a/src/ifs/wl_drm.rs +++ b/src/ifs/wl_drm.rs @@ -64,9 +64,9 @@ pub struct WlDrm { impl WlDrm { fn send_device(self: &Rc, device: &Rc) { - self.client.event(DeviceOut { + self.client.event(Device { self_id: self.id, - name: device.as_bytes().as_bstr().to_owned(), + name: device.as_bytes().as_bstr(), }) } diff --git a/src/ifs/wl_output.rs b/src/ifs/wl_output.rs index d47799e9..b9bba3ec 100644 --- a/src/ifs/wl_output.rs +++ b/src/ifs/wl_output.rs @@ -150,15 +150,15 @@ pub const SEND_SCALE_SINCE: u32 = 2; impl WlOutput { fn send_geometry(&self) { - let event = GeometryOut { + let event = Geometry { self_id: self.id, x: 0, y: 0, physical_width: self.global.width.get() as _, physical_height: self.global.height.get() as _, subpixel: SP_UNKNOWN, - make: "i4".to_string(), - model: "i4".to_string(), + make: "i4", + model: "i4", transform: TF_NORMAL, }; self.client.event(event); diff --git a/src/ifs/wl_registry.rs b/src/ifs/wl_registry.rs index b63280ae..c9d260c6 100644 --- a/src/ifs/wl_registry.rs +++ b/src/ifs/wl_registry.rs @@ -23,10 +23,10 @@ impl WlRegistry { } pub fn send_global(self: &Rc, global: &Rc) { - self.client.event(GlobalOut { + self.client.event(crate::wire::wl_registry::Global { self_id: self.id, name: global.name().raw(), - interface: global.interface().name().to_string(), + interface: global.interface().name(), version: global.version(), }) } @@ -39,7 +39,7 @@ impl WlRegistry { } fn bind(&self, parser: MsgParser<'_, '_>) -> Result<(), BindError> { - let bind: BindIn = self.client.parse(self, parser)?; + let bind: Bind = self.client.parse(self, parser)?; let global = self.client.state.globals.get(GlobalName::from_raw(bind.name))?; if global.interface().name() != bind.interface { return Err(BindError::InvalidInterface(InterfaceError { diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index 5ef1ccd0..e6f80928 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -35,7 +35,6 @@ pub use handling::NodeSeatState; use std::cell::{Cell, RefCell}; use std::collections::hash_map::Entry; use std::io::Write; -use std::ops::Deref; use std::rc::Rc; use thiserror::Error; use uapi::{c, OwnedFd}; @@ -312,10 +311,10 @@ impl WlSeat { }) } - fn send_name(self: &Rc, name: &Rc) { - self.client.event(NameOut { + fn send_name(self: &Rc, name: &str) { + self.client.event(Name { self_id: self.id, - name: name.deref().clone(), + name, }) } diff --git a/src/ifs/wl_seat/handling.rs b/src/ifs/wl_seat/handling.rs index 4ba4c2ac..7561ae5b 100644 --- a/src/ifs/wl_seat/handling.rs +++ b/src/ifs/wl_seat/handling.rs @@ -229,7 +229,7 @@ impl WlSeatGlobal { let pressed_keys: Vec<_> = self.pressed_keys.borrow().iter().copied().collect(); let serial = self.serial.fetch_add(1); self.surface_kb_event(0, &surface, |k| { - k.send_enter(serial, surface.id, pressed_keys.clone()) + k.send_enter(serial, surface.id, &pressed_keys) }); let ModifierState { mods_depressed, diff --git a/src/ifs/wl_seat/wl_keyboard.rs b/src/ifs/wl_seat/wl_keyboard.rs index 4de4a294..17d153a6 100644 --- a/src/ifs/wl_seat/wl_keyboard.rs +++ b/src/ifs/wl_seat/wl_keyboard.rs @@ -75,9 +75,9 @@ impl WlKeyboard { self: &Rc, serial: u32, surface: WlSurfaceId, - keys: Vec, + keys: &[u32], ) { - self.seat.client.event(EnterOut { + self.seat.client.event(Enter { self_id: self.id, serial, surface, diff --git a/src/ifs/wl_surface/xdg_surface.rs b/src/ifs/wl_surface/xdg_surface.rs index 7cb693fe..657be892 100644 --- a/src/ifs/wl_surface/xdg_surface.rs +++ b/src/ifs/wl_surface/xdg_surface.rs @@ -228,7 +228,7 @@ impl XdgSurface { self.surface.client.protocol_error( &**self, ALREADY_CONSTRUCTED, - format!( + &format!( "wl_surface {} already has an assigned xdg_toplevel", self.surface.id ), @@ -253,7 +253,7 @@ impl XdgSurface { self.surface.client.protocol_error( &**self, ALREADY_CONSTRUCTED, - format!( + &format!( "wl_surface {} already has an assigned xdg_popup", self.surface.id ), diff --git a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs index 2957c640..5a8edde8 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs @@ -150,11 +150,12 @@ impl XdgToplevel { } fn send_configure(&self, width: i32, height: i32) { - self.xdg.surface.client.event(ConfigureOut { + let states: Vec<_> = self.states.borrow().iter().copied().collect(); + self.xdg.surface.client.event(Configure { self_id: self.id, width, height, - states: self.states.borrow().iter().copied().collect(), + states: &states, }) } @@ -185,12 +186,12 @@ impl XdgToplevel { } fn set_title(&self, parser: MsgParser<'_, '_>) -> Result<(), SetTitleError> { - let _req: SetTitleIn = self.xdg.surface.client.parse(self, parser)?; + let _req: SetTitle = self.xdg.surface.client.parse(self, parser)?; Ok(()) } fn set_app_id(&self, parser: MsgParser<'_, '_>) -> Result<(), SetAppIdError> { - let req: SetAppIdIn = self.xdg.surface.client.parse(self, parser)?; + let req: SetAppId = self.xdg.surface.client.parse(self, parser)?; self.bugs.set(bugs::get(req.app_id)); Ok(()) } diff --git a/src/ifs/xdg_positioner.rs b/src/ifs/xdg_positioner.rs index 0b438594..04041804 100644 --- a/src/ifs/xdg_positioner.rs +++ b/src/ifs/xdg_positioner.rs @@ -166,7 +166,7 @@ impl XdgPositioner { self.client.protocol_error( self, INVALID_INPUT, - format!("Cannot set a non-positive size"), + &format!("Cannot set a non-positive size"), ); return Err(SetSizeError::NonPositiveSize); } @@ -182,7 +182,7 @@ impl XdgPositioner { self.client.protocol_error( self, INVALID_INPUT, - format!("Cannot set an anchor rect with negative size"), + &format!("Cannot set an anchor rect with negative size"), ); return Err(SetAnchorRectError::NegativeAnchorRect); } @@ -248,7 +248,7 @@ impl XdgPositioner { self.client.protocol_error( self, INVALID_INPUT, - format!("Cannot set a negative parent size"), + &format!("Cannot set a negative parent size"), ); return Err(SetParentSizeError::NegativeParentSize); } diff --git a/src/ifs/xdg_wm_base.rs b/src/ifs/xdg_wm_base.rs index 2eebef23..e3eec8dc 100644 --- a/src/ifs/xdg_wm_base.rs +++ b/src/ifs/xdg_wm_base.rs @@ -64,7 +64,7 @@ impl XdgWmBase { self.client.protocol_error( self, DEFUNCT_SURFACES, - format!( + &format!( "Cannot destroy xdg_wm_base object {} before destroying its surfaces", self.id ), diff --git a/src/ifs/zwp_primary_selection_offer_v1.rs b/src/ifs/zwp_primary_selection_offer_v1.rs index 84e84706..131b7b10 100644 --- a/src/ifs/zwp_primary_selection_offer_v1.rs +++ b/src/ifs/zwp_primary_selection_offer_v1.rs @@ -56,14 +56,14 @@ impl ZwpPrimarySelectionOfferV1 { } pub fn send_offer(self: &Rc, mime_type: &str) { - self.client.event(OfferOut { + self.client.event(Offer { self_id: self.id, - mime_type: mime_type.to_string(), + mime_type, }) } fn receive(&self, parser: MsgParser<'_, '_>) -> Result<(), ReceiveError> { - let req: ReceiveIn = self.client.parse(self, parser)?; + let req: Receive = self.client.parse(self, parser)?; if let Some(src) = self.source.get() { src.send_send(req.mime_type, req.fd); src.client.flush(); diff --git a/src/ifs/zwp_primary_selection_source_v1.rs b/src/ifs/zwp_primary_selection_source_v1.rs index 79162068..0c55937e 100644 --- a/src/ifs/zwp_primary_selection_source_v1.rs +++ b/src/ifs/zwp_primary_selection_source_v1.rs @@ -73,15 +73,15 @@ impl ZwpPrimarySelectionSourceV1 { } pub fn send_send(&self, mime_type: &str, fd: Rc) { - self.client.event(SendOut { + self.client.event(Send { self_id: self.id, - mime_type: mime_type.to_string(), + mime_type, fd, }) } fn offer(&self, parser: MsgParser<'_, '_>) -> Result<(), OfferError> { - let req: OfferIn = self.client.parse(self, parser)?; + let req: Offer = self.client.parse(self, parser)?; if self .mime_types .borrow_mut() diff --git a/src/utils/buffd/buf_out.rs b/src/utils/buffd/buf_out.rs index d833f3b0..ec339b73 100644 --- a/src/utils/buffd/buf_out.rs +++ b/src/utils/buffd/buf_out.rs @@ -47,10 +47,6 @@ impl OutBuffer { pub fn is_full(&self) -> bool { self.write_pos > BUF_SIZE } - - pub fn len(&self) -> usize { - self.write_pos - } } const LIMIT_PENDING: usize = 10;