From c92346324bce31c59d54a595f4391f263b5dc037 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 6 Feb 2022 03:46:03 +0100 Subject: [PATCH] autocommit 2022-02-06 03:46:03 CET --- Cargo.toml | 5 + build/build.rs | 29 + build.rs => build/enums.rs | 27 +- build/wire.rs | 665 ++++++++++++++++++ src/client/mod.rs | 6 +- src/ifs/org_kde_kwin_server_decoration/mod.rs | 10 +- .../org_kde_kwin_server_decoration/types.rs | 46 -- .../mod.rs | 9 +- .../types.rs | 36 - src/ifs/wl_buffer/mod.rs | 11 +- src/ifs/wl_buffer/types.rs | 29 - src/ifs/wl_callback/mod.rs | 7 +- src/ifs/wl_callback/types.rs | 17 - src/ifs/wl_compositor/types.rs | 32 - src/ifs/wl_data_device/mod.rs | 18 +- src/ifs/wl_data_device/types.rs | 194 ----- src/ifs/wl_data_device_manager/mod.rs | 6 +- src/ifs/wl_data_device_manager/types.rs | 34 - src/ifs/wl_data_offer/mod.rs | 21 +- src/ifs/wl_data_offer/types.rs | 146 ---- src/ifs/wl_data_source/mod.rs | 26 +- src/ifs/wl_data_source/types.rs | 157 ----- src/ifs/wl_display/mod.rs | 23 +- src/ifs/wl_display/types.rs | 77 -- src/ifs/wl_drm/mod.rs | 23 +- src/ifs/wl_drm/types.rs | 163 ----- src/ifs/wl_output/mod.rs | 16 +- src/ifs/wl_output/types.rs | 110 --- src/ifs/wl_region/mod.rs | 7 +- src/ifs/wl_region/types.rs | 64 -- src/ifs/wl_registry/mod.rs | 20 +- src/ifs/wl_registry/types.rs | 75 +- src/ifs/wl_seat/handling.rs | 6 +- src/ifs/wl_seat/mod.rs | 20 +- src/ifs/wl_seat/types.rs | 97 --- src/ifs/wl_seat/wl_keyboard/mod.rs | 33 +- src/ifs/wl_seat/wl_keyboard/types.rs | 174 ----- src/ifs/wl_seat/wl_pointer/mod.rs | 34 +- src/ifs/wl_seat/wl_pointer/types.rs | 262 ------- src/main.rs | 1 + src/object.rs | 3 +- src/utils/buffd/parser.rs | 29 +- src/wire.rs | 1 + wire/org_kde_kwin_server_decoration.txt | 15 + ...org_kde_kwin_server_decoration_manager.txt | 12 + wire/wl_buffer.txt | 11 + wire/wl_callback.txt | 5 + wire/wl_compositor.txt | 9 + wire/wl_data_device.txt | 49 ++ wire/wl_data_device_manager.txt | 10 + wire/wl_data_offer.txt | 36 + wire/wl_data_source.txt | 40 ++ wire/wl_display.txt | 21 + wire/wl_drm.txt | 60 ++ wire/wl_keyboard.txt | 44 ++ wire/wl_output.txt | 41 ++ wire/wl_pointer.txt | 63 ++ wire/wl_region.txt | 19 + wire/wl_registry.txt | 20 + wire/wl_seat.txt | 26 + 60 files changed, 1292 insertions(+), 1958 deletions(-) create mode 100644 build/build.rs rename build.rs => build/enums.rs (91%) create mode 100644 build/wire.rs create mode 100644 src/wire.rs create mode 100644 wire/org_kde_kwin_server_decoration.txt create mode 100644 wire/org_kde_kwin_server_decoration_manager.txt create mode 100644 wire/wl_buffer.txt create mode 100644 wire/wl_callback.txt create mode 100644 wire/wl_compositor.txt create mode 100644 wire/wl_data_device.txt create mode 100644 wire/wl_data_device_manager.txt create mode 100644 wire/wl_data_offer.txt create mode 100644 wire/wl_data_source.txt create mode 100644 wire/wl_display.txt create mode 100644 wire/wl_drm.txt create mode 100644 wire/wl_keyboard.txt create mode 100644 wire/wl_output.txt create mode 100644 wire/wl_pointer.txt create mode 100644 wire/wl_region.txt create mode 100644 wire/wl_registry.txt create mode 100644 wire/wl_seat.txt diff --git a/Cargo.toml b/Cargo.toml index 32d70b4f..e784c551 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "i4" version = "0.1.0" edition = "2021" +build = "build/build.rs" [profile.release] panic = "abort" @@ -34,3 +35,7 @@ byteorder = "1.4.3" [build-dependencies] repc = "0.1.1" anyhow = "1.0.52" +bstr = "0.2.17" + +[profile.dev.build-override] +opt-level = 3 diff --git a/build/build.rs b/build/build.rs new file mode 100644 index 00000000..0740197a --- /dev/null +++ b/build/build.rs @@ -0,0 +1,29 @@ +use std::fs::{File, OpenOptions}; +use std::{env, io}; +use std::io::BufWriter; +use std::path::PathBuf; + +mod enums; +mod wire; + +fn open(s: &str) -> io::Result> { + let mut path = PathBuf::from(env::var("OUT_DIR").unwrap()); + path.push(s); + Ok(BufWriter::new( + OpenOptions::new() + .create(true) + .write(true) + .truncate(true) + .open(path)?, + )) +} + + +fn main() -> anyhow::Result<()> { + wire::main()?; + + enums::main()?; + + println!("cargo:rerun-if-changed=build.rs"); + Ok(()) +} diff --git a/build.rs b/build/enums.rs similarity index 91% rename from build.rs rename to build/enums.rs index 30a98a6e..5b024aec 100644 --- a/build.rs +++ b/build/enums.rs @@ -1,34 +1,20 @@ +use std::env; use repc::layout::{Type, TypeVariant}; use std::fmt::Write as FmtWrite; -use std::fs::{File, OpenOptions}; -use std::io::BufWriter; use std::io::Write; -use std::path::PathBuf; -use std::{env, io}; +use crate::open; #[allow(unused_macros)] #[macro_use] -#[path = "src/macros.rs"] +#[path = "../src/macros.rs"] mod macros; -#[path = "src/pixman/consts.rs"] +#[path = "../src/pixman/consts.rs"] mod pixman; -#[path = "src/xkbcommon/consts.rs"] +#[path = "../src/xkbcommon/consts.rs"] mod xkbcommon; -fn open(s: &str) -> io::Result> { - let mut path = PathBuf::from(env::var("OUT_DIR").unwrap()); - path.push(s); - Ok(BufWriter::new( - OpenOptions::new() - .create(true) - .write(true) - .truncate(true) - .open(path)?, - )) -} - fn get_target() -> repc::Target { let rustc_target = env::var("TARGET").unwrap(); repc::TARGET_MAP @@ -206,7 +192,7 @@ fn write_egl_procs(f: &mut W) -> anyhow::Result<()> { Ok(()) } -fn main() -> anyhow::Result<()> { +pub fn main() -> anyhow::Result<()> { let mut f = open("pixman_tys.rs")?; write_ty(&mut f, pixman::FORMATS, "PixmanFormat")?; write_ty(&mut f, pixman::OPS, "PixmanOp")?; @@ -230,6 +216,5 @@ fn main() -> anyhow::Result<()> { let mut f = open("egl_procs.rs")?; write_egl_procs(&mut f)?; - println!("cargo:rerun-if-changed=build.rs"); Ok(()) } diff --git a/build/wire.rs b/build/wire.rs new file mode 100644 index 00000000..dada398d --- /dev/null +++ b/build/wire.rs @@ -0,0 +1,665 @@ +use std::fs::DirEntry; +use std::os::unix::ffi::OsStrExt; +use anyhow::{bail, Context, Result}; +use bstr::{BStr, BString, ByteSlice}; +use crate::open; +use std::io::Write; + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +enum TreeDelim { + Paren, + Brace, +} + +impl TreeDelim { + fn opening(self) -> u8 { + match self { + TreeDelim::Paren => b'(', + TreeDelim::Brace => b'{', + } + } + + fn closing(self) -> u8 { + match self { + TreeDelim::Paren => b')', + TreeDelim::Brace => b'}', + } + } +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +enum Symbol { + Comma, + Colon, + Equals, +} + +impl Symbol { + fn name(self) -> &'static str { + match self { + Symbol::Comma => "','", + Symbol::Colon => "':'", + Symbol::Equals => "'='", + } + } +} + +#[derive(Debug)] +struct Token<'a> { + line: u32, + kind: TokenKind<'a>, +} + +#[derive(Debug)] +enum TokenKind<'a> { + Ident(&'a BStr), + Num(u32), + Tree { + delim: TreeDelim, + body: Vec>, + }, + Symbol(Symbol), +} + +impl TokenKind<'_> { + fn name(&self) -> &str { + match self { + TokenKind::Ident(_) => "identifier", + TokenKind::Num(_) => "number", + TokenKind::Tree { delim, .. } => match delim { + TreeDelim::Paren => "'('-tree", + TreeDelim::Brace => "'{'-tree", + }, + TokenKind::Symbol(s) => s.name(), + } + } +} + +#[derive(Copy, Clone)] +struct Cursor<'a> { + pos: usize, + s: &'a [u8], +} + +impl Cursor<'_> { + fn eof(&self) -> bool { + self.pos >= self.s.len() + } +} + +fn tokenize<'a>(s: &'a [u8]) -> Result>> { + let mut tnz = Tokenizer { + line: 1, + cursor: Cursor { pos: 0, s }, + delim: None, + res: vec![], + }; + tnz.tokenize()?; + Ok(tnz.res) +} + +struct Tokenizer<'a> { + line: u32, + cursor: Cursor<'a>, + delim: Option, + res: Vec>, +} + +impl<'a> Tokenizer<'a> { + fn tokenize_one(&mut self) -> Result { + let c = &mut self.cursor; + while !c.eof() { + let b = c.s[c.pos]; + if matches!(b, b' ' | b'\n' | b'#') { + c.pos += 1; + if b == b'\n' { + self.line += 1; + } else if b == b'#' { + while !c.eof() { + c.pos += 1; + if c.s[c.pos - 1] == b'\n' { + self.line += 1; + break; + } + } + } + } else { + break; + } + } + if c.eof() { + if self.delim.is_some() { + bail!("Unexpected eof"); + } + return Ok(false); + } + let line = self.line; + let b = c.s[c.pos]; + let b_pos = c.pos; + c.pos += 1; + let kind = match b { + b'a'..=b'z' => { + while !c.eof() && matches!(c.s[c.pos], b'a'..=b'z' | b'_' | b'0'..=b'9') { + c.pos += 1; + } + TokenKind::Ident(c.s[b_pos..c.pos].as_bstr()) + } + b'0'..=b'9' => { + c.pos -= 1; + let mut num = 0; + while !c.eof() && matches!(c.s[c.pos], b'0'..=b'9') { + num = num * 10 + (c.s[c.pos] - b'0') as u32; + c.pos += 1; + } + TokenKind::Num(num) + } + b',' => TokenKind::Symbol(Symbol::Comma), + b'=' => TokenKind::Symbol(Symbol::Equals), + b':' => TokenKind::Symbol(Symbol::Colon), + b'(' => self.tokenize_tree(TreeDelim::Paren)?, + b'{' => self.tokenize_tree(TreeDelim::Brace)?, + c @ (b')' | b'}') => { + if self.delim.map(|d| d.closing()) != Some(c) { + bail!("Unexpected '{}' in line {}", c, self.line); + } + return Ok(false); + } + _ => bail!("Unexpected byte {:?} in line {}", b as char, self.line), + }; + self.res.push(Token { line, kind }); + Ok(true) + } + + fn tokenize(&mut self) -> Result<()> { + while self.tokenize_one()? { + // nothing + } + Ok(()) + } + + fn tokenize_tree(&mut self, delim: TreeDelim) -> Result> { + let mut tnz = Tokenizer { + line: self.line, + cursor: self.cursor, + delim: Some(delim), + res: vec![], + }; + tnz.tokenize().with_context(|| { + format!( + "While tokenizing {:?} block starting in line {}", + delim.opening() as char, + self.line + ) + })?; + self.cursor.pos = tnz.cursor.pos; + self.line = tnz.line; + Ok(TokenKind::Tree { + delim, + body: tnz.res, + }) + } +} + +#[derive(Debug)] +struct Lined { + #[allow(dead_code)] + line: u32, + val: T, +} + +#[derive(Debug)] +enum Type { + Id(BString), + U32, + I32, + Str, + BStr, + Fixed, + Fd, + Array(Box), +} + +#[derive(Debug)] +struct Field { + name: BString, + ty: Lined, +} + +#[derive(Debug)] +struct Message { + name: BString, + camel_name: BString, + id: Lined, + fields: Vec>, +} + +struct Parser<'a> { + pos: usize, + tokens: &'a [Token<'a>], +} + +impl<'a> Parser<'a> { + fn parse(&mut self) -> Result>> { + let mut res = vec![]; + while !self.eof() { + let (line, ty) = self.expect_ident()?; + match ty.as_bytes() { + b"msg" => res.push(self.parse_message()?), + _ => bail!("In line {}: Unexpected entry {:?}", line, ty), + } + } + Ok(res) + } + + fn eof(&self) -> bool { + self.pos == self.tokens.len() + } + + fn not_eof(&self) -> Result<()> { + if self.eof() { + bail!("Unexpected eof"); + } + Ok(()) + } + + fn yes_eof(&self) -> Result<()> { + if !self.eof() { + bail!( + "Unexpected trailing tokens in line {}", + self.tokens[self.pos].line + ); + } + Ok(()) + } + + fn parse_message(&mut self) -> Result> { + let (line, name) = self.expect_ident()?; + let res: Result<_> = (|| { + self.expect_symbol(Symbol::Equals)?; + let (num_line, val) = self.expect_number()?; + let (_, body) = self.expect_tree(TreeDelim::Brace)?; + let mut parser = Parser { + pos: 0, + tokens: body, + }; + let mut fields = vec!(); + while !parser.eof() { + fields.push(parser.parse_field()?); + } + Ok(Lined { + line, + val: Message { + name: name.to_owned(), + camel_name: to_camel(name), + id: Lined { line: num_line, val, }, + fields, + } + }) + })(); + res.with_context(|| format!("While parsing message starting at line {}", line)) + } + + fn parse_field(&mut self) -> Result> { + let (line, name) = self.expect_ident()?; + let res: Result<_> = (|| { + self.expect_symbol(Symbol::Colon)?; + let ty = self.parse_type()?; + if !self.eof() { + self.expect_symbol(Symbol::Comma)?; + } + Ok(Lined { + line, + val: Field { + name: name.to_owned(), + ty, + } + }) + })(); + res.with_context(|| format!("While parsing field starting at line {}", line)) + } + + fn expect_ident(&mut self) -> Result<(u32, &'a BStr)> { + self.not_eof()?; + let token = &self.tokens[self.pos]; + self.pos += 1; + match &token.kind { + TokenKind::Ident(id) => Ok((token.line, *id)), + k => bail!("In line {}: Expected identifier, found {}", token.line, k.name()), + } + } + + fn expect_number(&mut self) -> Result<(u32, u32)> { + self.not_eof()?; + let token = &self.tokens[self.pos]; + self.pos += 1; + match &token.kind { + TokenKind::Num(n) => Ok((token.line, *n)), + k => bail!("In line {}: Expected number, found {}", token.line, k.name()), + } + } + + fn expect_symbol(&mut self, symbol: Symbol) -> Result<()> { + self.not_eof()?; + let token = &self.tokens[self.pos]; + self.pos += 1; + match &token.kind { + TokenKind::Symbol(s) if *s == symbol => Ok(()), + k => bail!("In line {}: Expected {}, found {}", token.line, symbol.name(), k.name()), + } + } + + fn expect_tree_(&mut self) -> Result<(u32, TreeDelim, &'a [Token<'a>])> { + self.not_eof()?; + let token = &self.tokens[self.pos]; + self.pos += 1; + match &token.kind { + TokenKind::Tree { delim, body } => { + Ok((token.line, *delim, body)) + } + k => bail!("In line {}: Expected tree, found {}", token.line, k.name()), + } + } + + fn expect_tree(&mut self, exp_delim: TreeDelim) -> Result<(u32, &'a [Token<'a>])> { + let (line, delim, tokens) = self.expect_tree_()?; + if delim == exp_delim { + Ok((line, tokens)) + } else { + bail!("In line {}: Expected {:?}-delimited tree, found {:?}-delimited tree", line, exp_delim, delim.opening()) + } + } + + fn parse_type(&mut self) -> Result> { + self.not_eof()?; + let (line, ty) = self.expect_ident()?; + let ty = match ty.as_bytes() { + b"u32" => Type::U32, + b"i32" => Type::I32, + b"str" => Type::Str, + b"bstr" => Type::BStr, + b"fixed" => Type::Fixed, + b"fd" => Type::Fd, + b"array" => { + let (line, body) = self.expect_tree(TreeDelim::Paren)?; + let ty: Result<_> = (|| { + let mut parser = Parser { + pos: 0, + tokens: body, + }; + let ty = parser.parse_type()?; + parser.yes_eof()?; + match &ty.val { + Type::Id(_) => {} + Type::U32 => {} + Type::I32 => {} + Type::Fixed => {} + _ => { + bail!("Only numerical types can be array elements"); + } + } + Ok(ty) + })(); + let ty = ty.with_context(|| { + format!("While parsing array element type starting in line {}", line) + })?; + Type::Array(Box::new(ty.val)) + } + b"id" => { + let (_, body) = self.expect_tree(TreeDelim::Paren)?; + let ident: Result<_> = (|| { + let mut parser = Parser { + pos: 0, + tokens: body, + }; + let id = parser.expect_ident()?; + parser.yes_eof()?; + Ok(id) + })(); + let (_, ident) = ident.with_context(|| { + format!("While parsing identifier starting in line {}", line) + })?; + Type::Id(to_camel(ident)) + }, + _ => bail!("Unknown type {}", ty), + }; + Ok(Lined { + line, + val: ty, + }) + } +} + +fn parse_messages(s: &[u8]) -> Result>> { + let tokens = tokenize(s)?; + let mut parser = Parser { + pos: 0, + tokens: &tokens, + }; + parser.parse() +} + +fn to_camel(s: &BStr) -> BString { + let mut last_was_underscore = true; + let mut res = vec!(); + for mut b in s.as_bytes().iter().copied() { + if b == b'_' { + last_was_underscore = true; + } else { + if last_was_underscore { + b = b.to_ascii_uppercase() + } + res.push(b); + last_was_underscore = false; + } + } + res.into() +} + +fn write_type(f: &mut W, ty: &Type, role: TypeRole) -> 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::Fixed => write!(f, "Fixed")?, + Type::Fd => write!(f, "Rc")?, + Type::Array(n) if role == TypeRole::In => { + write!(f, "&'a [")?; + write_type(f, n, role)?; + write!(f, "]")?; + }, + Type::Array(n) => { + write!(f, "Vec<")?; + write_type(f, n, role)?; + write!(f, ">")?; + } + } + Ok(()) +} + +fn write_field(f: &mut W, field: &Field, role: TypeRole) -> Result<()> { + write!(f, " pub {}: ", field.name)?; + write_type(f, &field.ty.val, role)?; + 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; + let lifetime = if needs_lifetime { "<'a>" } else { "" }; + writeln!(f, " pub struct {}{}{} {{", message.camel_name, suffix, lifetime)?; + writeln!(f, " pub self_id: {}Id,", obj)?; + for field in &message.fields { + write_field(f, &field.val, role)?; + } + writeln!(f, " }}")?; + writeln!(f, " impl{} std::fmt::Debug for {}{}{} {{", lifetime, message.camel_name, suffix, 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() { + if i > 0 { + write!(f, ", ")?; + } + let formatter = match &field.val.ty.val { + Type::Str | Type::Fd | Type::Array(..) => "{:?}", + _ => "{}", + }; + write!(f, "{}: {}", field.val.name, formatter)?; + } + write!(f, r#")""#)?; + for field in &message.fields { + write!(f, ", self.{}", field.val.name)?; + } + writeln!(f, r")")?; + writeln!(f, " }}")?; + writeln!(f, " }}")?; + Ok(()) +} + +fn write_message(f: &mut W, obj: &BStr, message: &Message) -> Result<()> { + let has_reference_type = message.fields.iter().any(|f| match &f.val.ty.val { + Type::Str | Type::BStr | Type::Array(..) => true, + _ => false, + }); + let uppercase = message.name.to_ascii_uppercase(); + 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)?; + } + let lifetime = if has_reference_type { "<'a>"} else {""}; + writeln!(f, " impl<'a> RequestParser<'a> for {}{}{} {{", message.camel_name, if has_reference_type { "In" } else { "" }, lifetime)?; + writeln!(f, " fn parse(parser: &mut MsgParser<'_, 'a>) -> Result {{")?; + writeln!(f, " Ok(Self {{")?; + writeln!(f, " self_id: {}Id::NONE,", obj)?; + for field in &message.fields { + write!(f, " {}: ", field.val.name)?; + if let Type::Array(_) = &field.val.ty.val { + writeln!(f, "{{")?; + writeln!(f, " let array = parser.array()?;")?; + writeln!(f, " unsafe {{")?; + writeln!(f, " std::slice::from_raw_parts(array.as_ptr() as _, array.len() / 4)")?; + writeln!(f, " }}")?; + writeln!(f, " }},")?; + continue; + } + let p = match &field.val.ty.val { + Type::Id(_) => "object", + Type::U32 => "uint", + Type::I32 => "int", + Type::Str => "str", + Type::Fixed => "fixed", + Type::Fd => "fd", + Type::BStr => "bstr", + Type::Array(_) => unreachable!(), + }; + writeln!(f, "parser.{}()?,", p)?; + } + writeln!(f, " }})")?; + writeln!(f, " }}")?; + writeln!(f, " }}")?; + writeln!(f, " impl EventFormatter for {}{} {{", message.camel_name, if has_reference_type { "Out" } else { "" })?; + writeln!(f, " fn format(self: Box, 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<()> { + if let Type::Array(n) = &ty { + let new_prefix = format!(" {}", prefix); + writeln!(f, " {}fmt.array(|fmt| {{", prefix)?; + writeln!(f, " {} for el in {}.iter() {{", prefix, access)?; + write_fmt_expr(f, &new_prefix, n, "*el")?; + writeln!(f, " {} }}", prefix)?; + writeln!(f, " {}}});", prefix)?; + return Ok(()); + } + let p = match ty { + Type::Id(_) => "object", + Type::U32 => "uint", + Type::I32 => "int", + Type::Str | Type::BStr => "string", + Type::Fixed => "fixed", + Type::Fd => "fd", + Type::Array(..) => unreachable!(), + }; + let rf = match ty { + Type::Str | Type::BStr => "&", + _ => "", + }; + writeln!(f, " {}fmt.{}({}{});", prefix, p, rf, access)?; + Ok(()) + } + for field in &message.fields { + write_fmt_expr(f, "", &field.val.ty.val, &format!("self.{}", field.val.name))?; + } + writeln!(f, " }}")?; + writeln!(f, " fn id(&self) -> ObjectId {{")?; + writeln!(f, " self.self_id.into()")?; + writeln!(f, " }}")?; + writeln!(f, " fn interface(&self) -> crate::object::Interface {{")?; + writeln!(f, " crate::object::Interface::{}", obj)?; + writeln!(f, " }}")?; + writeln!(f, " }}")?; + Ok(()) +} + +fn write_file(f: &mut W, file: &DirEntry) -> Result<()> { + let file_name = file.file_name(); + let file_name = file_name.as_bytes().as_bstr(); + println!("cargo:rerun-if-changed=wire/{}", file_name); + let obj_name = file_name.split_str(".").next().unwrap().as_bstr(); + let camel_obj_name = to_camel(obj_name); + writeln!(f)?; + writeln!(f, "id!({}Id);", camel_obj_name)?; + let contents = std::fs::read(file.path())?; + let messages = parse_messages(&contents)?; + if messages.is_empty() { + return Ok(()); + } + writeln!(f)?; + writeln!(f, "pub mod {} {{", obj_name)?; + writeln!(f, " pub use super::*;")?; + for message in &messages { + write_message(f, camel_obj_name.as_bstr(), &message.val)?; + } + writeln!(f, "}}")?; + Ok(()) +} + +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 crate::fixed::Fixed;")?; + writeln!(f, "use crate::client::{{EventFormatter, RequestParser}};")?; + writeln!(f, "use crate::object::ObjectId;")?; + writeln!(f, "use crate::utils::buffd::{{MsgFormatter, MsgParser, MsgParserError}};")?; + println!("cargo:rerun-if-changed=wire"); + let mut files = vec!(); + for file in std::fs::read_dir("wire")? { + files.push(file?); + } + files.sort_by_key(|f| f.file_name()); + for file in files { + write_file(&mut f, &file).with_context(|| format!("While processing {}", file.path().display()))?; + } + Ok(()) +} diff --git a/src/client/mod.rs b/src/client/mod.rs index a4c132c9..6c5843a6 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -164,10 +164,8 @@ impl Drop for ClientHolder { pub trait EventFormatter: Debug { fn format(self: Box, fmt: &mut MsgFormatter<'_>); - fn obj(&self) -> &dyn Object; - fn should_log(&self) -> bool { - true - } + fn id(&self) -> ObjectId; + fn interface(&self) -> Interface; } pub type DynEventFormatter = Box; diff --git a/src/ifs/org_kde_kwin_server_decoration/mod.rs b/src/ifs/org_kde_kwin_server_decoration/mod.rs index c5ce9665..af0062ff 100644 --- a/src/ifs/org_kde_kwin_server_decoration/mod.rs +++ b/src/ifs/org_kde_kwin_server_decoration/mod.rs @@ -4,22 +4,16 @@ use crate::utils::buffd::MsgParser; use std::cell::Cell; use std::rc::Rc; pub use types::*; +use crate::wire::org_kde_kwin_server_decoration::*; mod types; -const RELEASE: u32 = 0; -const REQUEST_MODE: u32 = 1; - -const MODE: u32 = 0; - #[allow(dead_code)] const NONE: u32 = 0; #[allow(dead_code)] const CLIENT: u32 = 1; const SERVER: u32 = 2; -id!(OrgKdeKwinServerDecorationId); - pub struct OrgKdeKwinServerDecoration { id: OrgKdeKwinServerDecorationId, client: Rc, @@ -37,7 +31,7 @@ impl OrgKdeKwinServerDecoration { pub fn mode(self: &Rc, mode: u32) -> DynEventFormatter { Box::new(Mode { - obj: self.clone(), + self_id: self.id, mode, }) } diff --git a/src/ifs/org_kde_kwin_server_decoration/types.rs b/src/ifs/org_kde_kwin_server_decoration/types.rs index 3c8d4092..c0173833 100644 --- a/src/ifs/org_kde_kwin_server_decoration/types.rs +++ b/src/ifs/org_kde_kwin_server_decoration/types.rs @@ -38,49 +38,3 @@ pub enum RequestModeError { } efrom!(RequestModeError, ClientError); efrom!(RequestModeError, ParseError, MsgParserError); - -pub(super) struct Release; -impl RequestParser<'_> for Release { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Release { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "release()") - } -} - -pub(super) struct RequestMode { - pub mode: u32, -} -impl RequestParser<'_> for RequestMode { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - mode: parser.uint()?, - }) - } -} -impl Debug for RequestMode { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "request_mode(mode: {})", self.mode) - } -} - -pub(super) struct Mode { - pub obj: Rc, - pub mode: u32, -} -impl EventFormatter for Mode { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, MODE).uint(self.mode); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Mode { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "mode(mode: {})", self.mode) - } -} diff --git a/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs b/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs index 311bfe88..02e442e3 100644 --- a/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs +++ b/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs @@ -5,21 +5,16 @@ use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; +use crate::wire::org_kde_kwin_server_decoration_manager::*; mod types; -const CREATE: u32 = 0; - -const DEFAULT_MODE: u32 = 0; - #[allow(dead_code)] const NONE: u32 = 0; #[allow(dead_code)] const CLIENT: u32 = 1; const SERVER: u32 = 2; -id!(OrgKdeKwinServerDecorationManagerGlobalId); - pub struct OrgKdeKwinServerDecorationManagerGlobal { name: GlobalName, } @@ -72,7 +67,7 @@ pub struct OrgKdeKwinServerDecorationManager { impl OrgKdeKwinServerDecorationManager { fn default_mode(self: &Rc, mode: u32) -> DynEventFormatter { Box::new(DefaultMode { - obj: self.clone(), + self_id: self.id, mode, }) } diff --git a/src/ifs/org_kde_kwin_server_decoration_manager/types.rs b/src/ifs/org_kde_kwin_server_decoration_manager/types.rs index 0f888947..4a0c9b35 100644 --- a/src/ifs/org_kde_kwin_server_decoration_manager/types.rs +++ b/src/ifs/org_kde_kwin_server_decoration_manager/types.rs @@ -32,39 +32,3 @@ pub enum CreateError { } efrom!(CreateError, ClientError); efrom!(CreateError, ParseError, MsgParserError); - -pub(super) struct Create { - pub id: OrgKdeKwinServerDecorationId, - pub surface: WlSurfaceId, -} -impl RequestParser<'_> for Create { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - surface: parser.object()?, - }) - } -} -impl Debug for Create { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "create(id: {}, surface: {})", self.id, self.surface) - } -} - -pub(super) struct DefaultMode { - pub obj: Rc, - pub mode: u32, -} -impl EventFormatter for DefaultMode { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, DEFAULT_MODE).uint(self.mode); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for DefaultMode { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "default_mode(mode: {})", self.mode) - } -} diff --git a/src/ifs/wl_buffer/mod.rs b/src/ifs/wl_buffer/mod.rs index 8f04e3b5..53d1e43f 100644 --- a/src/ifs/wl_buffer/mod.rs +++ b/src/ifs/wl_buffer/mod.rs @@ -10,14 +10,9 @@ use crate::utils::buffd::MsgParser; use crate::utils::clonecell::CloneCell; use std::cell::Cell; use std::rc::Rc; +use crate::wire::wl_buffer::*; pub use types::*; -const DESTROY: u32 = 0; - -const RELEASE: u32 = 0; - -id!(WlBufferId); - pub enum WlBufferStorage { Shm { mem: ClientMemOffset, stride: i32 }, Dmabuf(Rc), @@ -122,8 +117,8 @@ impl WlBuffer { Ok(()) } - pub fn release(self: &Rc) -> DynEventFormatter { - Box::new(Release { obj: self.clone() }) + pub fn release(&self) -> DynEventFormatter { + Box::new(Release { self_id: self.id }) } } diff --git a/src/ifs/wl_buffer/types.rs b/src/ifs/wl_buffer/types.rs index a15ed764..f5ce7d60 100644 --- a/src/ifs/wl_buffer/types.rs +++ b/src/ifs/wl_buffer/types.rs @@ -33,32 +33,3 @@ pub enum DestroyError { } efrom!(DestroyError, ParseFailed, MsgParserError); efrom!(DestroyError, ClientError); - -pub(super) struct Destroy; -impl RequestParser<'_> for Destroy { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Destroy { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "destroy()") - } -} - -pub(super) struct Release { - pub obj: Rc, -} -impl EventFormatter for Release { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, RELEASE); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Release { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "release()") - } -} diff --git a/src/ifs/wl_callback/mod.rs b/src/ifs/wl_callback/mod.rs index 622a667a..458bc8e1 100644 --- a/src/ifs/wl_callback/mod.rs +++ b/src/ifs/wl_callback/mod.rs @@ -4,10 +4,7 @@ use crate::client::DynEventFormatter; use crate::object::Object; use std::rc::Rc; use types::*; - -const DONE: u32 = 0; - -id!(WlCallbackId); +use crate::wire::wl_callback::*; pub struct WlCallback { id: WlCallbackId, @@ -19,7 +16,7 @@ impl WlCallback { } pub fn done(self: &Rc) -> DynEventFormatter { - Box::new(Done { obj: self.clone() }) + Box::new(Done { self_id: self.id, callback_data: 0 }) } } diff --git a/src/ifs/wl_callback/types.rs b/src/ifs/wl_callback/types.rs index d4001978..518e26c4 100644 --- a/src/ifs/wl_callback/types.rs +++ b/src/ifs/wl_callback/types.rs @@ -8,20 +8,3 @@ use thiserror::Error; #[derive(Debug, Error)] pub enum WlCallbackError {} - -pub(super) struct Done { - pub obj: Rc, -} -impl EventFormatter for Done { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, DONE).uint(0); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Done { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "done(callback_data: 0)") - } -} diff --git a/src/ifs/wl_compositor/types.rs b/src/ifs/wl_compositor/types.rs index ebe9f78d..b8a35816 100644 --- a/src/ifs/wl_compositor/types.rs +++ b/src/ifs/wl_compositor/types.rs @@ -40,35 +40,3 @@ pub enum CreateRegionError { efrom!(CreateRegionError, ParseFailed, MsgParserError); efrom!(CreateRegionError, ClientError, ClientError); - -pub(super) struct CreateSurface { - pub id: WlSurfaceId, -} -impl RequestParser<'_> for CreateSurface { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - }) - } -} -impl Debug for CreateSurface { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "create_surface(id: {})", self.id) - } -} - -pub(super) struct CreateRegion { - pub id: WlRegionId, -} -impl RequestParser<'_> for CreateRegion { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - }) - } -} -impl Debug for CreateRegion { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "create_region(id: {})", self.id) - } -} diff --git a/src/ifs/wl_data_device/mod.rs b/src/ifs/wl_data_device/mod.rs index 1f7a6359..215bf2b1 100644 --- a/src/ifs/wl_data_device/mod.rs +++ b/src/ifs/wl_data_device/mod.rs @@ -8,23 +8,11 @@ use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; - -const START_DRAG: u32 = 0; -const SET_SELECTION: u32 = 1; -const RELEASE: u32 = 2; - -const DATA_OFFER: u32 = 0; -const ENTER: u32 = 1; -const LEAVE: u32 = 2; -const MOTION: u32 = 4; -const DROP: u32 = 5; -const SELECTION: u32 = 5; +use crate::wire::wl_data_device::*; #[allow(dead_code)] const ROLE: u32 = 0; -id!(WlDataDeviceId); - pub struct WlDataDevice { pub id: WlDataDeviceId, pub manager: Rc, @@ -42,14 +30,14 @@ impl WlDataDevice { pub fn data_offer(self: &Rc, id: WlDataOfferId) -> DynEventFormatter { Box::new(DataOffer { - obj: self.clone(), + self_id: self.id, id, }) } pub fn selection(self: &Rc, id: WlDataOfferId) -> DynEventFormatter { Box::new(Selection { - obj: self.clone(), + self_id: self.id, id, }) } diff --git a/src/ifs/wl_data_device/types.rs b/src/ifs/wl_data_device/types.rs index aa68c5c5..ef4f5349 100644 --- a/src/ifs/wl_data_device/types.rs +++ b/src/ifs/wl_data_device/types.rs @@ -55,197 +55,3 @@ pub enum ReleaseError { } efrom!(ReleaseError, ParseFailed, MsgParserError); efrom!(ReleaseError, ClientError); - -pub(super) struct StartDrag { - pub source: WlDataSourceId, - pub origin: WlSurfaceId, - pub icon: WlSurfaceId, - pub serial: u32, -} -impl RequestParser<'_> for StartDrag { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - source: parser.object()?, - origin: parser.object()?, - icon: parser.object()?, - serial: parser.uint()?, - }) - } -} -impl Debug for StartDrag { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "start_drag(source: {}, origin: {}, icon: {}, serial: {})", - self.source, self.origin, self.icon, self.serial - ) - } -} - -pub(super) struct SetSelection { - pub source: WlDataSourceId, - pub serial: u32, -} -impl RequestParser<'_> for SetSelection { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - source: parser.object()?, - serial: parser.uint()?, - }) - } -} -impl Debug for SetSelection { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "set_selection(source: {}, serial: {})", - self.source, self.serial, - ) - } -} - -pub(super) struct Release; -impl RequestParser<'_> for Release { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Release { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "release()") - } -} - -pub(super) struct DataOffer { - pub obj: Rc, - pub id: WlDataOfferId, -} -impl EventFormatter for DataOffer { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, DATA_OFFER).object(self.id); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for DataOffer { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "data_offer(id: {})", self.id) - } -} - -pub(super) struct Enter { - pub obj: Rc, - pub serial: u32, - pub surface: WlSurfaceId, - pub x: Fixed, - pub y: Fixed, - pub id: WlDataOfferId, -} -impl EventFormatter for Enter { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, ENTER) - .uint(self.serial) - .object(self.surface) - .fixed(self.x) - .fixed(self.y) - .object(self.id); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Enter { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "enter(serial: {}, surface: {}, x: {}, y: {}, id: {})", - self.serial, self.surface, self.x, self.y, self.id - ) - } -} - -pub(super) struct Leave { - pub obj: Rc, -} -impl EventFormatter for Leave { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, LEAVE); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Leave { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "leave()") - } -} - -pub(super) struct Motion { - pub obj: Rc, - pub time: u32, - pub x: Fixed, - pub y: Fixed, -} -impl EventFormatter for Motion { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, MOTION) - .uint(self.time) - .fixed(self.x) - .fixed(self.y); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Motion { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "motion(time: {}, x: {}, y: {})", - self.time, self.x, self.y - ) - } -} - -pub(super) struct Drop { - pub obj: Rc, -} -impl EventFormatter for Drop { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, DROP); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Drop { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "drop()") - } -} - -pub(super) struct Selection { - pub obj: Rc, - pub id: WlDataOfferId, -} -impl EventFormatter for Selection { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, SELECTION).object(self.id); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Selection { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "selection(id: {})", self.id) - } -} -// -// msgs! { -// WlDataDevice::Selection = 5 { -// id: id(WlDataOffer), -// } -// } diff --git a/src/ifs/wl_data_device_manager/mod.rs b/src/ifs/wl_data_device_manager/mod.rs index e27cffc4..37e980c0 100644 --- a/src/ifs/wl_data_device_manager/mod.rs +++ b/src/ifs/wl_data_device_manager/mod.rs @@ -8,9 +8,7 @@ use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; - -const CREATE_DATA_SOURCE: u32 = 0; -const GET_DATA_DEVICE: u32 = 1; +use crate::wire::wl_data_device_manager::*; #[allow(dead_code)] const DND_NONE: u32 = 0; @@ -21,8 +19,6 @@ const DND_MOVE: u32 = 2; #[allow(dead_code)] const DND_ASK: u32 = 4; -id!(WlDataDeviceManagerId); - pub struct WlDataDeviceManagerGlobal { name: GlobalName, } diff --git a/src/ifs/wl_data_device_manager/types.rs b/src/ifs/wl_data_device_manager/types.rs index afc595ab..c048f3b2 100644 --- a/src/ifs/wl_data_device_manager/types.rs +++ b/src/ifs/wl_data_device_manager/types.rs @@ -36,37 +36,3 @@ pub enum GetDataDeviceError { } efrom!(GetDataDeviceError, ParseFailed, MsgParserError); efrom!(GetDataDeviceError, ClientError); - -pub(super) struct CreateDataSource { - pub id: WlDataSourceId, -} -impl RequestParser<'_> for CreateDataSource { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - }) - } -} -impl Debug for CreateDataSource { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "create_data_source(id: {})", self.id) - } -} - -pub(super) struct GetDataDevice { - pub id: WlDataDeviceId, - pub seat: WlSeatId, -} -impl RequestParser<'_> for GetDataDevice { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - seat: parser.object()?, - }) - } -} -impl Debug for GetDataDevice { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "get_data_device(id: {}, seat: {})", self.id, self.seat,) - } -} diff --git a/src/ifs/wl_data_offer/mod.rs b/src/ifs/wl_data_offer/mod.rs index 8d83746d..49952bd1 100644 --- a/src/ifs/wl_data_offer/mod.rs +++ b/src/ifs/wl_data_offer/mod.rs @@ -9,16 +9,7 @@ use crate::utils::clonecell::CloneCell; use std::ops::Deref; use std::rc::Rc; pub use types::*; - -const ACCEPT: u32 = 0; -const RECEIVE: u32 = 1; -const DESTROY: u32 = 2; -const FINISH: u32 = 3; -const SET_ACTIONS: u32 = 4; - -const OFFER: u32 = 0; -const SOURCE_ACTIONS: u32 = 1; -const ACTION: u32 = 2; +use crate::wire::wl_data_offer::*; #[allow(dead_code)] const INVALID_FINISH: u32 = 0; @@ -29,8 +20,6 @@ const INVALID_ACTION: u32 = 2; #[allow(dead_code)] const INVALID_OFFER: u32 = 3; -id!(WlDataOfferId); - #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum DataOfferRole { Selection, @@ -79,19 +68,19 @@ impl WlDataOffer { } pub fn offer(self: &Rc, mime_type: &str) -> DynEventFormatter { - Box::new(Offer { - obj: self.clone(), + Box::new(OfferOut { + self_id: self.id, mime_type: mime_type.to_string(), }) } fn accept(&self, parser: MsgParser<'_, '_>) -> Result<(), AcceptError> { - let _req: Accept = self.client.parse(self, parser)?; + let _req: AcceptIn = self.client.parse(self, parser)?; Ok(()) } fn receive(&self, parser: MsgParser<'_, '_>) -> Result<(), ReceiveError> { - let req: Receive = self.client.parse(self, parser)?; + let req: ReceiveIn = self.client.parse(self, parser)?; if let Some(src) = self.source.get() { src.client.event(src.send(req.mime_type, req.fd)); src.client.flush(); diff --git a/src/ifs/wl_data_offer/types.rs b/src/ifs/wl_data_offer/types.rs index e2cbc817..e6cfcef8 100644 --- a/src/ifs/wl_data_offer/types.rs +++ b/src/ifs/wl_data_offer/types.rs @@ -74,149 +74,3 @@ pub enum SetActionsError { } efrom!(SetActionsError, ParseFailed, MsgParserError); efrom!(SetActionsError, ClientError); - -pub(super) struct Accept<'a> { - pub serial: u32, - pub mime_type: &'a BStr, -} -impl<'a> RequestParser<'a> for Accept<'a> { - fn parse(parser: &mut MsgParser<'_, 'a>) -> Result { - Ok(Self { - serial: parser.uint()?, - mime_type: parser.bstr()?, - }) - } -} -impl Debug for Accept<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "accept(serial: {}, mime_type: {:?})", - self.serial, self.mime_type - ) - } -} - -pub(super) struct Receive<'a> { - pub mime_type: &'a str, - pub fd: OwnedFd, -} -impl<'a> RequestParser<'a> for Receive<'a> { - fn parse(parser: &mut MsgParser<'_, 'a>) -> Result { - Ok(Self { - mime_type: parser.str()?, - fd: parser.fd()?, - }) - } -} -impl Debug for Receive<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "receive(mime_type: {:?}, fd: {})", - self.mime_type, - self.fd.raw() - ) - } -} - -pub(super) struct Destroy; -impl RequestParser<'_> for Destroy { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Destroy { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "destroy()") - } -} - -pub(super) struct Finish; -impl RequestParser<'_> for Finish { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Finish { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "finish()") - } -} - -pub(super) struct SetActions { - pub dnd_actions: u32, - pub preferred_action: u32, -} -impl<'a> RequestParser<'a> for SetActions { - fn parse(parser: &mut MsgParser<'_, 'a>) -> Result { - Ok(Self { - dnd_actions: parser.uint()?, - preferred_action: parser.uint()?, - }) - } -} -impl Debug for SetActions { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "set_actions(dnd_actions: {}, preferred_action: {})", - self.dnd_actions, self.preferred_action - ) - } -} - -pub(super) struct Offer { - pub obj: Rc, - pub mime_type: String, -} -impl EventFormatter for Offer { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, OFFER).string(&self.mime_type); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Offer { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "offer(mime_type: {:?})", self.mime_type) - } -} - -pub(super) struct SourceActions { - pub obj: Rc, - pub source_actions: u32, -} -impl EventFormatter for SourceActions { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, SOURCE_ACTIONS) - .uint(self.source_actions); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for SourceActions { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "source_actions(source_actions: {})", self.source_actions,) - } -} - -pub(super) struct Action { - pub obj: Rc, - pub dnd_action: u32, -} -impl EventFormatter for Action { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, ACTION).uint(self.dnd_action); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Action { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "action(dnd_action: {})", self.dnd_action,) - } -} diff --git a/src/ifs/wl_data_source/mod.rs b/src/ifs/wl_data_source/mod.rs index 5c0a1e70..9664e587 100644 --- a/src/ifs/wl_data_source/mod.rs +++ b/src/ifs/wl_data_source/mod.rs @@ -11,25 +11,13 @@ use std::cell::RefCell; use std::rc::Rc; pub use types::*; use uapi::OwnedFd; - -const OFFER: u32 = 0; -const DESTROY: u32 = 1; -const SET_ACTIONS: u32 = 2; - -const TARGET: u32 = 0; -const SEND: u32 = 1; -const CANCELLED: u32 = 2; -const DND_DROP_PERFORMED: u32 = 4; -const DND_FINISHED: u32 = 5; -const ACTION: u32 = 5; +use crate::wire::wl_data_source::*; #[allow(dead_code)] const INVALID_ACTION_MASK: u32 = 0; #[allow(dead_code)] const INVALID_SOURCE: u32 = 1; -id!(WlDataSourceId); - #[derive(Clone)] struct Attachment { seat: Rc, @@ -101,19 +89,19 @@ impl WlDataSource { } pub fn cancelled(self: &Rc) -> DynEventFormatter { - Box::new(Cancelled { obj: self.clone() }) + Box::new(Cancelled { self_id: self.id }) } - pub fn send(self: &Rc, mime_type: &str, fd: OwnedFd) -> DynEventFormatter { - Box::new(Send { - obj: self.clone(), + pub fn send(&self, mime_type: &str, fd: Rc) -> DynEventFormatter { + Box::new(SendOut { + self_id: self.id, mime_type: mime_type.to_string(), - fd: Rc::new(fd), + fd, }) } fn offer(&self, parser: MsgParser<'_, '_>) -> Result<(), OfferError> { - let req: Offer = self.client.parse(self, parser)?; + let req: OfferIn = self.client.parse(self, parser)?; if self .mime_types .borrow_mut() diff --git a/src/ifs/wl_data_source/types.rs b/src/ifs/wl_data_source/types.rs index 4ed88fae..c861481f 100644 --- a/src/ifs/wl_data_source/types.rs +++ b/src/ifs/wl_data_source/types.rs @@ -54,160 +54,3 @@ pub enum SetActionsError { } efrom!(SetActionsError, ParseFailed, MsgParserError); efrom!(SetActionsError, ClientError); - -pub(super) struct Offer<'a> { - pub mime_type: &'a str, -} -impl<'a> RequestParser<'a> for Offer<'a> { - fn parse(parser: &mut MsgParser<'_, 'a>) -> Result { - Ok(Self { - mime_type: parser.str()?, - }) - } -} -impl Debug for Offer<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "offer(mime_type: {:?})", self.mime_type) - } -} - -pub(super) struct Destroy; -impl RequestParser<'_> for Destroy { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Destroy { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "destroy()",) - } -} - -pub(super) struct SetActions { - pub actions: u32, -} -impl RequestParser<'_> for SetActions { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - actions: parser.uint()?, - }) - } -} -impl Debug for SetActions { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "set_actions(actions: {})", self.actions) - } -} - -pub(super) struct Target { - pub obj: Rc, - pub mime_type: BString, -} -impl EventFormatter for Target { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, TARGET).string(&self.mime_type); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Target { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "target(mime_type: {:?})", self.mime_type) - } -} - -pub(super) struct Send { - pub obj: Rc, - pub mime_type: String, - pub fd: Rc, -} -impl EventFormatter for Send { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, SEND) - .string(&self.mime_type) - .fd(self.fd); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Send { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "send(mime_type: {:?}, fd: {})", - self.mime_type, - self.fd.raw() - ) - } -} - -pub(super) struct Cancelled { - pub obj: Rc, -} -impl EventFormatter for Cancelled { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, CANCELLED); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Cancelled { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "cancelled()") - } -} - -pub(super) struct DndDropPerformed { - pub obj: Rc, -} -impl EventFormatter for DndDropPerformed { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, DND_DROP_PERFORMED); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for DndDropPerformed { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "dnd_drop_performed()") - } -} - -pub(super) struct DndFinished { - pub obj: Rc, -} -impl EventFormatter for DndFinished { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, DND_FINISHED); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for DndFinished { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "dnd_finished()") - } -} - -pub(super) struct Action { - pub obj: Rc, - pub dnd_action: u32, -} -impl EventFormatter for Action { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, ACTION).uint(self.dnd_action); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Action { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "action(dnd_action: {})", self.dnd_action) - } -} diff --git a/src/ifs/wl_display/mod.rs b/src/ifs/wl_display/mod.rs index d86f4304..d70b5885 100644 --- a/src/ifs/wl_display/mod.rs +++ b/src/ifs/wl_display/mod.rs @@ -7,12 +7,7 @@ use crate::object::{Object, ObjectId, WL_DISPLAY_ID}; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; - -const SYNC: u32 = 0; -const GET_REGISTRY: u32 = 1; - -const ERROR: u32 = 0; -const DELETE_ID: u32 = 1; +use crate::wire::wl_display::*; const INVALID_OBJECT: u32 = 0; const INVALID_METHOD: u32 = 1; @@ -21,7 +16,7 @@ const NO_MEMORY: u32 = 2; const IMPLEMENTATION: u32 = 3; pub struct WlDisplay { - id: ObjectId, + id: WlDisplayId, client: Rc, } @@ -53,15 +48,15 @@ impl WlDisplay { Ok(()) } - pub fn error( + pub fn error>( self: &Rc, - object_id: ObjectId, + object_id: O, code: u32, message: String, ) -> DynEventFormatter { - Box::new(Error { - obj: self.clone(), - object_id, + Box::new(ErrorOut { + self_id: self.id, + object_id: object_id.into(), code, message, }) @@ -89,8 +84,8 @@ impl WlDisplay { pub fn delete_id(self: &Rc, id: ObjectId) -> DynEventFormatter { Box::new(DeleteId { - obj: self.clone(), - id, + self_id: self.id, + id: id.raw(), }) } } diff --git a/src/ifs/wl_display/types.rs b/src/ifs/wl_display/types.rs index f1a2ed61..1c28ca5a 100644 --- a/src/ifs/wl_display/types.rs +++ b/src/ifs/wl_display/types.rs @@ -44,80 +44,3 @@ pub enum SyncError { efrom!(SyncError, ParseFailed, MsgParserError); efrom!(SyncError, ClientError); - -pub(super) struct GetRegistry { - pub registry: WlRegistryId, -} -impl RequestParser<'_> for GetRegistry { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - registry: parser.object()?, - }) - } -} -impl Debug for GetRegistry { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "get_registry(registry: {})", self.registry) - } -} - -pub(super) struct Sync { - pub callback: WlCallbackId, -} -impl RequestParser<'_> for Sync { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - callback: parser.object()?, - }) - } -} -impl Debug for Sync { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "sync(callback: {})", self.callback) - } -} - -pub(super) struct DeleteId { - pub obj: Rc, - pub id: ObjectId, -} -impl EventFormatter for DeleteId { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(WL_DISPLAY_ID, DELETE_ID).object(self.id); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for DeleteId { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "delete_id(id: {})", self.id) - } -} - -pub(super) struct Error { - pub obj: Rc, - pub object_id: ObjectId, - pub code: u32, - pub message: String, -} -impl EventFormatter for Error { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(WL_DISPLAY_ID, ERROR) - .object(self.object_id) - .uint(self.code) - .string(&self.message); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Error { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "error(object_id: {}, code: {}, message: {:?})", - self.object_id, self.code, self.message - ) - } -} diff --git a/src/ifs/wl_drm/mod.rs b/src/ifs/wl_drm/mod.rs index da7bba46..d4bf468a 100644 --- a/src/ifs/wl_drm/mod.rs +++ b/src/ifs/wl_drm/mod.rs @@ -4,21 +4,12 @@ use crate::object::Object; use crate::utils::buffd::MsgParser; use std::ffi::CString; use std::rc::Rc; +use bstr::ByteSlice; pub use types::*; +use crate::wire::wl_drm::*; mod types; -id!(WlDrmId); - -const AUTHENTICATE: u32 = 0; -const CREATE_BUFFER: u32 = 1; -const CREATE_PLANAR_BUFFER: u32 = 2; - -const DEVICE: u32 = 0; -const FORMAT: u32 = 1; -const AUTHENTICATED: u32 = 2; -const CAPABILITIES: u32 = 3; - const PRIME: u32 = 1; pub struct WlDrmGlobal { @@ -72,19 +63,19 @@ pub struct WlDrm { impl WlDrm { fn device(self: &Rc, device: &Rc) -> DynEventFormatter { - Box::new(Device { - obj: self.clone(), - name: device.clone(), + Box::new(DeviceOut { + self_id: self.id, + name: device.as_bytes().as_bstr().to_owned(), }) } fn authenticated(self: &Rc) -> DynEventFormatter { - Box::new(Authenticated { obj: self.clone() }) + Box::new(Authenticated { self_id: self.id }) } fn capabilities(self: &Rc, value: u32) -> DynEventFormatter { Box::new(Capabilities { - obj: self.clone(), + self_id: self.id, value, }) } diff --git a/src/ifs/wl_drm/types.rs b/src/ifs/wl_drm/types.rs index 1e1b6a87..67780e2f 100644 --- a/src/ifs/wl_drm/types.rs +++ b/src/ifs/wl_drm/types.rs @@ -45,166 +45,3 @@ pub enum CreatePlanarBufferError { Unsupported, } efrom!(CreatePlanarBufferError, ParseError, MsgParserError); - -pub(super) struct Authenticate { - id: u32, -} -impl RequestParser<'_> for Authenticate { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { id: parser.uint()? }) - } -} -impl Debug for Authenticate { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "authenticate(id: {})", self.id) - } -} - -pub(super) struct CreateBuffer { - pub id: WlBufferId, - pub name: u32, - pub width: i32, - pub height: i32, - pub stride: u32, - pub format: u32, -} -impl RequestParser<'_> for CreateBuffer { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - name: parser.uint()?, - width: parser.int()?, - height: parser.int()?, - stride: parser.uint()?, - format: parser.uint()?, - }) - } -} -impl Debug for CreateBuffer { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "create_buffer(id: {}, name: {}, width: {}, height: {}, stride: {}, format: {})", - self.id, self.name, self.width, self.height, self.stride, self.format, - ) - } -} - -pub(super) struct CreatePlanarBuffer { - id: WlBufferId, - name: u32, - width: i32, - height: i32, - format: u32, - offset0: i32, - stride0: i32, - offset1: i32, - stride1: i32, - offset2: i32, - stride2: i32, -} -impl RequestParser<'_> for CreatePlanarBuffer { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - name: parser.uint()?, - width: parser.int()?, - height: parser.int()?, - format: parser.uint()?, - offset0: parser.int()?, - stride0: parser.int()?, - offset1: parser.int()?, - stride1: parser.int()?, - offset2: parser.int()?, - stride2: parser.int()?, - }) - } -} -impl Debug for CreatePlanarBuffer { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "create_params(id: {}, name: {}, width: {}, height: {}, format: {}, offset0: {}, stride0: {}, offset1: {}, stride1: {}, offset2: {}, stride2: {})", - self.id, - self.name, - self.width, - self.height, - self.format, - self.offset0, - self.stride0, - self.offset1, - self.stride1, - self.offset2, - self.stride2, - ) - } -} - -pub(super) struct Device { - pub obj: Rc, - pub name: Rc, -} -impl EventFormatter for Device { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, DEVICE).string(self.name.as_bytes()); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Device { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "device(name: {:?})", self.name) - } -} - -pub(super) struct Format { - pub obj: Rc, - pub format: u32, -} -impl EventFormatter for Format { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, FORMAT).uint(self.format); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Format { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "format(format: {})", self.format,) - } -} - -pub(super) struct Authenticated { - pub obj: Rc, -} -impl EventFormatter for Authenticated { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, AUTHENTICATED); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Authenticated { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "authenticated()",) - } -} - -pub(super) struct Capabilities { - pub obj: Rc, - pub value: u32, -} -impl EventFormatter for Capabilities { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, CAPABILITIES).uint(self.value); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Capabilities { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "capabilities(value: {})", self.value,) - } -} diff --git a/src/ifs/wl_output/mod.rs b/src/ifs/wl_output/mod.rs index 24a03432..da1d052c 100644 --- a/src/ifs/wl_output/mod.rs +++ b/src/ifs/wl_output/mod.rs @@ -11,15 +11,7 @@ use std::collections::hash_map::Entry; use std::iter; use std::rc::Rc; pub use types::*; - -id!(WlOutputId); - -const RELEASE: u32 = 0; - -const GEOMETRY: u32 = 0; -const MODE: u32 = 1; -const DONE: u32 = 2; -const SCALE: u32 = 3; +use crate::wire::wl_output::*; const SP_UNKNOWN: i32 = 0; #[allow(dead_code)] @@ -186,7 +178,7 @@ impl WlOutput { fn mode(self: &Rc) -> DynEventFormatter { Box::new(Mode { - obj: self.clone(), + self_id: self.id, flags: MODE_CURRENT, width: self.global.width.get() as _, height: self.global.height.get() as _, @@ -196,13 +188,13 @@ impl WlOutput { fn scale(self: &Rc) -> DynEventFormatter { Box::new(Scale { - obj: self.clone(), + self_id: self.id, factor: 1, }) } fn done(self: &Rc) -> DynEventFormatter { - Box::new(Done { obj: self.clone() }) + Box::new(Done { self_id: self.id }) } fn remove_binding(&self) { diff --git a/src/ifs/wl_output/types.rs b/src/ifs/wl_output/types.rs index eae81a3b..a867d5ac 100644 --- a/src/ifs/wl_output/types.rs +++ b/src/ifs/wl_output/types.rs @@ -24,113 +24,3 @@ pub enum ReleaseError { } efrom!(ReleaseError, ClientError); efrom!(ReleaseError, ParseError, MsgParserError); - -pub(super) struct Release; -impl RequestParser<'_> for Release { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Release { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "release()") - } -} - -pub(super) struct Geometry { - pub obj: Rc, - pub x: i32, - pub y: i32, - pub physical_width: i32, - pub physical_height: i32, - pub subpixel: i32, - pub make: String, - pub model: String, - pub transform: i32, -} -impl EventFormatter for Geometry { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, GEOMETRY) - .int(self.x) - .int(self.y) - .int(self.physical_width) - .int(self.physical_height) - .int(self.subpixel) - .string(&self.make) - .string(&self.model) - .int(self.transform); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Geometry { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "geometry(x: {}, y: {}, physical_width: {}, physical_height: {}, subpixel: {}, make: {}, model: {}, transform: {})", - self.x, self.y, self.physical_width, self.physical_height, self.subpixel, self.make, self.model, self.transform) - } -} - -pub(super) struct Mode { - pub obj: Rc, - pub flags: u32, - pub width: i32, - pub height: i32, - pub refresh: i32, -} -impl EventFormatter for Mode { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, MODE) - .uint(self.flags) - .int(self.width) - .int(self.height) - .int(self.refresh); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Mode { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "mode(flags: 0x{:x}, width: {}, height: {}, refresh: {})", - self.flags, self.width, self.height, self.refresh - ) - } -} - -pub(super) struct Done { - pub obj: Rc, -} -impl EventFormatter for Done { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, DONE); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Done { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "done()") - } -} - -pub(super) struct Scale { - pub obj: Rc, - pub factor: i32, -} -impl EventFormatter for Scale { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, SCALE).int(self.factor); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Scale { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "scale(factor: {})", self.factor) - } -} diff --git a/src/ifs/wl_region/mod.rs b/src/ifs/wl_region/mod.rs index e522ae5e..908d0e2d 100644 --- a/src/ifs/wl_region/mod.rs +++ b/src/ifs/wl_region/mod.rs @@ -7,12 +7,7 @@ use crate::utils::buffd::MsgParser; use std::cell::RefCell; use std::rc::Rc; pub use types::*; - -const DESTROY: u32 = 0; -const ADD: u32 = 1; -const SUBTRACT: u32 = 2; - -id!(WlRegionId); +use crate::wire::wl_region::*; pub struct WlRegion { id: WlRegionId, diff --git a/src/ifs/wl_region/types.rs b/src/ifs/wl_region/types.rs index 6eb2dca5..de496818 100644 --- a/src/ifs/wl_region/types.rs +++ b/src/ifs/wl_region/types.rs @@ -40,67 +40,3 @@ pub enum SubtractError { NegativeExtents, } efrom!(SubtractError, ParseFailed, MsgParserError); - -pub(super) struct Destroy; -impl RequestParser<'_> for Destroy { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Destroy { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "destroy()") - } -} - -pub(super) struct Add { - pub x: i32, - pub y: i32, - pub width: i32, - pub height: i32, -} -impl RequestParser<'_> for Add { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - x: parser.int()?, - y: parser.int()?, - width: parser.int()?, - height: parser.int()?, - }) - } -} -impl Debug for Add { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "add(x: {}, y: {}, width: {}, height: {})", - self.x, self.y, self.width, self.height, - ) - } -} - -pub(super) struct Subtract { - pub x: i32, - pub y: i32, - pub width: i32, - pub height: i32, -} -impl RequestParser<'_> for Subtract { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - x: parser.int()?, - y: parser.int()?, - width: parser.int()?, - height: parser.int()?, - }) - } -} -impl Debug for Subtract { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "subtract(x: {}, y: {}, width: {}, height: {})", - self.x, self.y, self.width, self.height, - ) - } -} diff --git a/src/ifs/wl_registry/mod.rs b/src/ifs/wl_registry/mod.rs index 4908be94..7d07895f 100644 --- a/src/ifs/wl_registry/mod.rs +++ b/src/ifs/wl_registry/mod.rs @@ -6,13 +6,7 @@ use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; - -const BIND: u32 = 0; - -const GLOBAL: u32 = 0; -const GLOBAL_REMOVE: u32 = 1; - -id!(WlRegistryId); +use crate::wire::wl_registry::*; pub struct WlRegistry { id: WlRegistryId, @@ -28,16 +22,18 @@ impl WlRegistry { } pub fn global(self: &Rc, global: &Rc) -> DynEventFormatter { - Box::new(GlobalE { - obj: self.clone(), - global: global.clone(), + Box::new(GlobalOut { + self_id: self.id, + name: global.name().raw(), + interface: global.interface().name().to_string(), + version: global.version(), }) } pub fn global_remove(self: &Rc, name: GlobalName) -> DynEventFormatter { Box::new(GlobalRemove { - obj: self.clone(), - name, + self_id: self.id, + name: name.raw(), }) } diff --git a/src/ifs/wl_registry/types.rs b/src/ifs/wl_registry/types.rs index 75a12c92..e506399a 100644 --- a/src/ifs/wl_registry/types.rs +++ b/src/ifs/wl_registry/types.rs @@ -27,6 +27,8 @@ pub enum BindError { #[error("Tried to bind to global {} of type {} and version {} using version {}", .0.name, .0.interface.name(), .0.version, .0.actual)] InvalidVersion(VersionError), } +efrom!(BindError, ParseError, MsgParserError); +efrom!(BindError, GlobalsError); #[derive(Debug)] pub struct InterfaceError { @@ -43,76 +45,3 @@ pub struct VersionError { pub actual: u32, } -efrom!(BindError, ParseError, MsgParserError); -efrom!(BindError, GlobalsError); - -pub(super) struct GlobalE { - pub obj: Rc, - pub global: Rc, -} -impl EventFormatter for GlobalE { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, GLOBAL) - .uint(self.global.name().raw()) - .string(self.global.interface().name()) - .uint(self.global.version()); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for GlobalE { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "global(name: {}, interface: {:?}, version: {})", - self.global.name(), - self.global.interface().name(), - self.global.version() - ) - } -} - -pub(super) struct GlobalRemove { - pub obj: Rc, - pub name: GlobalName, -} -impl EventFormatter for GlobalRemove { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, GLOBAL_REMOVE).uint(self.name.raw()); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for GlobalRemove { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "global_remove(name: {})", self.name) - } -} - -pub(super) struct Bind<'a> { - pub name: GlobalName, - pub id: ObjectId, - pub interface: &'a BStr, - pub version: u32, -} -impl<'a> RequestParser<'a> for Bind<'a> { - fn parse(parser: &mut MsgParser<'_, 'a>) -> Result { - Ok(Self { - name: parser.global()?, - interface: parser.bstr()?, - version: parser.uint()?, - id: parser.object()?, - }) - } -} -impl Debug for Bind<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "bind(name: {}, interface: {:?}, version: {}, id: {})", - self.name, self.interface, self.version, self.id - ) - } -} diff --git a/src/ifs/wl_seat/handling.rs b/src/ifs/wl_seat/handling.rs index 64e105ff..746ac8aa 100644 --- a/src/ifs/wl_seat/handling.rs +++ b/src/ifs/wl_seat/handling.rs @@ -13,12 +13,12 @@ use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel; use crate::ifs::wl_surface::xdg_surface::XdgSurface; use crate::ifs::wl_surface::WlSurface; use crate::ifs::zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1; +use crate::ifs::zwp_primary_selection_offer_v1::ZwpPrimarySelectionOfferV1Id; use crate::tree::{FloatNode, FoundNode, Node}; use crate::utils::smallmap::SmallMap; use crate::xkbcommon::{ModifierState, XKB_KEY_DOWN, XKB_KEY_UP}; use std::ops::{Deref, DerefMut}; use std::rc::Rc; -use crate::ifs::zwp_primary_selection_offer_v1::ZwpPrimarySelectionOfferV1Id; #[derive(Default)] pub struct NodeSeatState { @@ -371,8 +371,8 @@ impl WlSeatGlobal { } fn surface_primary_selection_device_event(&self, ver: u32, surface: &WlSurface, mut f: F) - where - F: FnMut(&Rc) -> DynEventFormatter, + where + F: FnMut(&Rc) -> DynEventFormatter, { let client = &surface.client; self.for_each_primary_selection_device(ver, client.id, |p| { diff --git a/src/ifs/wl_seat/mod.rs b/src/ifs/wl_seat/mod.rs index d40ca1cc..6cf48bd0 100644 --- a/src/ifs/wl_seat/mod.rs +++ b/src/ifs/wl_seat/mod.rs @@ -39,19 +39,11 @@ 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; pub use types::*; use uapi::{c, OwnedFd}; - -id!(WlSeatId); - -const GET_POINTER: u32 = 0; -const GET_KEYBOARD: u32 = 1; -const GET_TOUCH: u32 = 2; -const RELEASE: u32 = 3; - -const CAPABILITIES: u32 = 0; -const NAME: u32 = 1; +use crate::wire::wl_seat::*; const POINTER: u32 = 1; const KEYBOARD: u32 = 2; @@ -317,15 +309,15 @@ pub struct WlSeat { impl WlSeat { fn capabilities(self: &Rc) -> DynEventFormatter { Box::new(Capabilities { - obj: self.clone(), + self_id: self.id, capabilities: POINTER | KEYBOARD, }) } fn name(self: &Rc, name: &Rc) -> DynEventFormatter { - Box::new(Name { - obj: self.clone(), - name: name.clone(), + Box::new(NameOut { + self_id: self.id, + name: name.deref().clone(), }) } diff --git a/src/ifs/wl_seat/types.rs b/src/ifs/wl_seat/types.rs index f320c385..af44421a 100644 --- a/src/ifs/wl_seat/types.rs +++ b/src/ifs/wl_seat/types.rs @@ -66,100 +66,3 @@ pub enum ReleaseError { } efrom!(ReleaseError, ClientError, ClientError); efrom!(ReleaseError, ParseError, MsgParserError); - -pub(super) struct GetPointer { - pub id: WlPointerId, -} -impl RequestParser<'_> for GetPointer { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - }) - } -} -impl Debug for GetPointer { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "get_pointer(id: {})", self.id) - } -} - -pub(super) struct GetKeyboard { - pub id: WlKeyboardId, -} -impl RequestParser<'_> for GetKeyboard { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - }) - } -} -impl Debug for GetKeyboard { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "get_keyboard(id: {})", self.id) - } -} - -pub(super) struct GetTouch { - pub id: WlTouchId, -} -impl RequestParser<'_> for GetTouch { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - id: parser.object()?, - }) - } -} -impl Debug for GetTouch { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "get_touch(id: {})", self.id) - } -} - -pub(super) struct Release; -impl RequestParser<'_> for Release { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Release { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "release()") - } -} - -pub(super) struct Capabilities { - pub obj: Rc, - pub capabilities: u32, -} -impl EventFormatter for Capabilities { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, CAPABILITIES) - .uint(self.capabilities); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Capabilities { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "capabilities(capabilities: {})", self.capabilities) - } -} - -pub(super) struct Name { - pub obj: Rc, - pub name: Rc, -} -impl EventFormatter for Name { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, NAME).string(self.name.as_bytes()); - } - fn obj(&self) -> &dyn Object { - &*self.obj - } -} -impl Debug for Name { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "name(name: {})", self.name) - } -} diff --git a/src/ifs/wl_seat/wl_keyboard/mod.rs b/src/ifs/wl_seat/wl_keyboard/mod.rs index d3214cf8..f257e6ab 100644 --- a/src/ifs/wl_seat/wl_keyboard/mod.rs +++ b/src/ifs/wl_seat/wl_keyboard/mod.rs @@ -8,15 +8,7 @@ use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; use uapi::{c, Errno, OwnedFd}; - -const RELEASE: u32 = 0; - -const KEYMAP: u32 = 0; -const ENTER: u32 = 1; -const LEAVE: u32 = 2; -const KEY: u32 = 3; -const MODIFIERS: u32 = 4; -const REPEAT_INFO: u32 = 5; +use crate::wire::wl_keyboard::*; pub const REPEAT_INFO_SINCE: u32 = 4; @@ -24,13 +16,9 @@ pub const REPEAT_INFO_SINCE: u32 = 4; const NO_KEYMAP: u32 = 0; pub(super) const XKB_V1: u32 = 1; -#[allow(dead_code)] pub(super) const RELEASED: u32 = 0; -#[allow(dead_code)] pub(super) const PRESSED: u32 = 1; -id!(WlKeyboardId); - pub struct WlKeyboard { id: WlKeyboardId, seat: Rc, @@ -76,41 +64,38 @@ impl WlKeyboard { pub fn keymap(self: &Rc, format: u32, fd: Rc, size: u32) -> DynEventFormatter { Box::new(Keymap { - obj: self.clone(), + self_id: self.id, format, fd, size, }) } - #[allow(dead_code)] pub fn enter( self: &Rc, serial: u32, surface: WlSurfaceId, keys: Vec, ) -> DynEventFormatter { - Box::new(Enter { - obj: self.clone(), + Box::new(EnterOut { + self_id: self.id, serial, surface, keys, }) } - #[allow(dead_code)] pub fn leave(self: &Rc, serial: u32, surface: WlSurfaceId) -> DynEventFormatter { Box::new(Leave { - obj: self.clone(), + self_id: self.id, serial, surface, }) } - #[allow(dead_code)] pub fn key(self: &Rc, serial: u32, time: u32, key: u32, state: u32) -> DynEventFormatter { Box::new(Key { - obj: self.clone(), + self_id: self.id, serial, time, key, @@ -118,7 +103,6 @@ impl WlKeyboard { }) } - #[allow(dead_code)] pub fn modifiers( self: &Rc, serial: u32, @@ -128,7 +112,7 @@ impl WlKeyboard { group: u32, ) -> DynEventFormatter { Box::new(Modifiers { - obj: self.clone(), + self_id: self.id, serial, mods_depressed, mods_latched, @@ -137,10 +121,9 @@ impl WlKeyboard { }) } - #[allow(dead_code)] pub fn repeat_info(self: &Rc, rate: i32, delay: i32) -> DynEventFormatter { Box::new(RepeatInfo { - obj: self.clone(), + self_id: self.id, rate, delay, }) diff --git a/src/ifs/wl_seat/wl_keyboard/types.rs b/src/ifs/wl_seat/wl_keyboard/types.rs index 648742d7..68bf74f4 100644 --- a/src/ifs/wl_seat/wl_keyboard/types.rs +++ b/src/ifs/wl_seat/wl_keyboard/types.rs @@ -33,177 +33,3 @@ pub enum ReleaseError { } efrom!(ReleaseError, ParseError, MsgParserError); efrom!(ReleaseError, ClientError, ClientError); - -pub(super) struct Release; -impl RequestParser<'_> for Release { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Release { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "destroy()",) - } -} - -pub(super) struct Keymap { - pub obj: Rc, - pub format: u32, - pub fd: Rc, - pub size: u32, -} -impl EventFormatter for Keymap { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, KEYMAP) - .uint(self.format) - .fd(self.fd) - .uint(self.size); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for Keymap { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "keymap(format: {}, fd: {}, size: {})", - self.format, - self.fd.raw(), - self.size - ) - } -} - -pub(super) struct Enter { - pub obj: Rc, - pub serial: u32, - pub surface: WlSurfaceId, - pub keys: Vec, -} -impl EventFormatter for Enter { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, ENTER) - .uint(self.serial) - .object(self.surface) - .array(|f| { - for &key in &self.keys { - f.uint(key); - } - }); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for Enter { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "enter(serial: {}, surface: {}, keys: {:?})", - self.serial, self.surface, self.keys - ) - } -} - -pub(super) struct Leave { - pub obj: Rc, - pub serial: u32, - pub surface: WlSurfaceId, -} -impl EventFormatter for Leave { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, LEAVE) - .uint(self.serial) - .object(self.surface); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for Leave { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "leave(serial: {}, surface: {})", - self.serial, self.surface - ) - } -} - -pub(super) struct Key { - pub obj: Rc, - pub serial: u32, - pub time: u32, - pub key: u32, - pub state: u32, -} -impl EventFormatter for Key { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, KEY) - .uint(self.serial) - .uint(self.time) - .uint(self.key) - .uint(self.state); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for Key { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "key(serial: {}, time: {}, key: {}, state: {})", - self.serial, self.time, self.key, self.state - ) - } -} - -pub(super) struct Modifiers { - pub obj: Rc, - pub serial: u32, - pub mods_depressed: u32, - pub mods_latched: u32, - pub mods_locked: u32, - pub group: u32, -} -impl EventFormatter for Modifiers { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, MODIFIERS) - .uint(self.serial) - .uint(self.mods_depressed) - .uint(self.mods_latched) - .uint(self.mods_locked) - .uint(self.group); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for Modifiers { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "modifiers(serial: {}, mods_depressed: {}, mods_latched: {}, mods_locked: {}, group: {})", self.serial, self.mods_depressed, self.mods_latched, self.mods_locked, self.group) - } -} - -pub(super) struct RepeatInfo { - pub obj: Rc, - pub rate: i32, - pub delay: i32, -} -impl EventFormatter for RepeatInfo { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, REPEAT_INFO) - .int(self.rate) - .int(self.delay); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for RepeatInfo { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "repeat_info(rate: {}, delay: {})", self.rate, self.delay) - } -} diff --git a/src/ifs/wl_seat/wl_pointer/mod.rs b/src/ifs/wl_seat/wl_pointer/mod.rs index 995d82d3..b826c23b 100644 --- a/src/ifs/wl_seat/wl_pointer/mod.rs +++ b/src/ifs/wl_seat/wl_pointer/mod.rs @@ -9,19 +9,7 @@ use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; - -const SET_CURSOR: u32 = 0; -const RELEASE: u32 = 1; - -const ENTER: u32 = 0; -const LEAVE: u32 = 1; -const MOTION: u32 = 2; -const BUTTON: u32 = 3; -const AXIS: u32 = 4; -const FRAME: u32 = 5; -const AXIS_SOURCE: u32 = 6; -const AXIS_STOP: u32 = 7; -const AXIS_DISCRETE: u32 = 8; +use crate::wire::wl_pointer::*; #[allow(dead_code)] const ROLE: u32 = 0; @@ -43,8 +31,6 @@ const WHEEL_TILT: u32 = 3; pub const POINTER_FRAME_SINCE_VERSION: u32 = 5; -id!(WlPointerId); - pub struct WlPointer { id: WlPointerId, seat: Rc, @@ -66,7 +52,7 @@ impl WlPointer { y: Fixed, ) -> DynEventFormatter { Box::new(Enter { - obj: self.clone(), + self_id: self.id, serial, surface, surface_x: x, @@ -76,7 +62,7 @@ impl WlPointer { pub fn leave(self: &Rc, serial: u32, surface: WlSurfaceId) -> DynEventFormatter { Box::new(Leave { - obj: self.clone(), + self_id: self.id, serial, surface, }) @@ -84,7 +70,7 @@ impl WlPointer { pub fn motion(self: &Rc, time: u32, x: Fixed, y: Fixed) -> DynEventFormatter { Box::new(Motion { - obj: self.clone(), + self_id: self.id, time, surface_x: x, surface_y: y, @@ -99,7 +85,7 @@ impl WlPointer { state: u32, ) -> DynEventFormatter { Box::new(Button { - obj: self.clone(), + self_id: self.id, serial, time, button, @@ -109,7 +95,7 @@ impl WlPointer { pub fn axis(self: &Rc, time: u32, axis: u32, value: Fixed) -> DynEventFormatter { Box::new(Axis { - obj: self.clone(), + self_id: self.id, time, axis, value, @@ -118,13 +104,13 @@ impl WlPointer { #[allow(dead_code)] pub fn frame(self: &Rc) -> DynEventFormatter { - Box::new(Frame { obj: self.clone() }) + Box::new(Frame { self_id: self.id }) } #[allow(dead_code)] pub fn axis_source(self: &Rc, axis_source: u32) -> DynEventFormatter { Box::new(AxisSource { - obj: self.clone(), + self_id: self.id, axis_source, }) } @@ -132,7 +118,7 @@ impl WlPointer { #[allow(dead_code)] pub fn axis_stop(self: &Rc, time: u32, axis: u32) -> DynEventFormatter { Box::new(AxisStop { - obj: self.clone(), + self_id: self.id, time, axis, }) @@ -141,7 +127,7 @@ impl WlPointer { #[allow(dead_code)] pub fn axis_discrete(self: &Rc, axis: u32, discrete: i32) -> DynEventFormatter { Box::new(AxisDiscrete { - obj: self.clone(), + self_id: self.id, axis, discrete, }) diff --git a/src/ifs/wl_seat/wl_pointer/types.rs b/src/ifs/wl_seat/wl_pointer/types.rs index 43f04f06..c5fb5a48 100644 --- a/src/ifs/wl_seat/wl_pointer/types.rs +++ b/src/ifs/wl_seat/wl_pointer/types.rs @@ -44,265 +44,3 @@ pub enum ReleaseError { } efrom!(ReleaseError, ParseError, MsgParserError); efrom!(ReleaseError, ClientError, ClientError); - -pub(super) struct SetCursor { - pub serial: u32, - pub surface: WlSurfaceId, - pub hotspot_x: i32, - pub hotspot_y: i32, -} -impl RequestParser<'_> for SetCursor { - fn parse(parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self { - serial: parser.uint()?, - surface: parser.object()?, - hotspot_x: parser.int()?, - hotspot_y: parser.int()?, - }) - } -} -impl Debug for SetCursor { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "set_cursor(serial: {}, surface: {}, hotspot_x: {}, hotspot_y: {})", - self.serial, self.surface, self.hotspot_x, self.hotspot_y - ) - } -} - -pub(super) struct Release; -impl RequestParser<'_> for Release { - fn parse(_parser: &mut MsgParser<'_, '_>) -> Result { - Ok(Self) - } -} -impl Debug for Release { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "destroy()",) - } -} - -pub(super) struct Enter { - pub obj: Rc, - pub serial: u32, - pub surface: WlSurfaceId, - pub surface_x: Fixed, - pub surface_y: Fixed, -} -impl EventFormatter for Enter { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, ENTER) - .uint(self.serial) - .object(self.surface) - .fixed(self.surface_x) - .fixed(self.surface_y); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for Enter { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "enter(serial: {}, surface: {}, surface_x: {}, surface_y: {})", - self.serial, self.surface, self.surface_x, self.surface_y - ) - } -} - -pub(super) struct Leave { - pub obj: Rc, - pub serial: u32, - pub surface: WlSurfaceId, -} -impl EventFormatter for Leave { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, LEAVE) - .uint(self.serial) - .object(self.surface); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for Leave { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "leave(serial: {}, surface: {})", - self.serial, self.surface - ) - } -} - -pub(super) struct Motion { - pub obj: Rc, - pub time: u32, - pub surface_x: Fixed, - pub surface_y: Fixed, -} -impl EventFormatter for Motion { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, MOTION) - .uint(self.time) - .fixed(self.surface_x) - .fixed(self.surface_y); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } - fn should_log(&self) -> bool { - false - } -} -impl Debug for Motion { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "motion(time: {}, surface_x: {}, surface_y: {})", - self.time, self.surface_x, self.surface_y - ) - } -} - -pub(super) struct Button { - pub obj: Rc, - pub serial: u32, - pub time: u32, - pub button: u32, - pub state: u32, -} -impl EventFormatter for Button { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, BUTTON) - .uint(self.serial) - .uint(self.time) - .uint(self.button) - .uint(self.state); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for Button { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "button(serial: {}, time: {}, button: 0x{:x}, state: {})", - self.serial, self.time, self.button, self.state - ) - } -} - -pub(super) struct Axis { - pub obj: Rc, - pub time: u32, - pub axis: u32, - pub value: Fixed, -} -impl EventFormatter for Axis { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, AXIS) - .uint(self.time) - .uint(self.axis) - .fixed(self.value); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for Axis { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "axis(time: {}, axis: {}, value: {:?})", - self.time, self.axis, self.value - ) - } -} - -pub(super) struct Frame { - pub obj: Rc, -} -impl EventFormatter for Frame { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, FRAME); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } - fn should_log(&self) -> bool { - false - } -} -impl Debug for Frame { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "frame()") - } -} - -pub(super) struct AxisSource { - pub obj: Rc, - pub axis_source: u32, -} -impl EventFormatter for AxisSource { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, AXIS_SOURCE).uint(self.axis_source); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for AxisSource { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "axis_source(axis_source: {})", self.axis_source) - } -} - -pub(super) struct AxisStop { - pub obj: Rc, - pub time: u32, - pub axis: u32, -} -impl EventFormatter for AxisStop { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, AXIS_STOP) - .uint(self.time) - .uint(self.axis); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for AxisStop { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "axis_stop(time: {}, axis: {})", self.time, self.axis) - } -} - -pub(super) struct AxisDiscrete { - pub obj: Rc, - pub axis: u32, - pub discrete: i32, -} -impl EventFormatter for AxisDiscrete { - fn format(self: Box, fmt: &mut MsgFormatter<'_>) { - fmt.header(self.obj.id, AXIS_DISCRETE) - .uint(self.axis) - .int(self.discrete); - } - fn obj(&self) -> &dyn Object { - self.obj.deref() - } -} -impl Debug for AxisDiscrete { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "axis_discrete(axis: {}, discrete: {})", - self.axis, self.discrete - ) - } -} diff --git a/src/main.rs b/src/main.rs index f9faacf6..84f3e181 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,6 +68,7 @@ mod tree; mod utils; mod wheel; mod xkbcommon; +mod wire; fn main() { env_logger::builder() diff --git a/src/object.rs b/src/object.rs index b697ab96..2e7ea1ad 100644 --- a/src/object.rs +++ b/src/object.rs @@ -2,8 +2,9 @@ use crate::client::ClientError; use crate::utils::buffd::MsgParser; use std::fmt::{Display, Formatter}; use std::rc::Rc; +use crate::wire::WlDisplayId; -pub const WL_DISPLAY_ID: ObjectId = ObjectId(1); +pub const WL_DISPLAY_ID: WlDisplayId = WlDisplayId(1); #[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] pub struct ObjectId(u32); diff --git a/src/utils/buffd/parser.rs b/src/utils/buffd/parser.rs index e993ecf6..c27d3dad 100644 --- a/src/utils/buffd/parser.rs +++ b/src/utils/buffd/parser.rs @@ -1,3 +1,4 @@ +use std::rc::Rc; use crate::fixed::Fixed; use crate::globals::GlobalName; use crate::object::ObjectId; @@ -65,18 +66,11 @@ impl<'a, 'b> MsgParser<'a, 'b> { } pub fn bstr(&mut self) -> Result<&'b BStr, MsgParserError> { - let len = self.uint()? as usize; - if len == 0 { + let s = self.array()?; + if s.len() == 0 { return Err(MsgParserError::EmptyString); } - let cap = (len + 3) & !3; - if cap > self.data.len() - self.pos { - return Err(MsgParserError::UnexpectedEof); - } - let s = &self.data[self.pos..self.pos + len - 1]; - let s = s.as_bstr(); - self.pos += cap; - Ok(s) + Ok(s[..s.len()-1].as_bstr()) } pub fn str(&mut self) -> Result<&'b str, MsgParserError> { @@ -86,9 +80,9 @@ impl<'a, 'b> MsgParser<'a, 'b> { } } - pub fn fd(&mut self) -> Result { + pub fn fd(&mut self) -> Result, MsgParserError> { match self.buf.get_fd() { - Ok(fd) => Ok(fd), + Ok(fd) => Ok(Rc::new(fd)), _ => Err(MsgParserError::MissingFd), } } @@ -100,4 +94,15 @@ impl<'a, 'b> MsgParser<'a, 'b> { Err(MsgParserError::TrailingData) } } + + pub fn array(&mut self) -> Result<&'b [u8], MsgParserError> { + let len = self.uint()? as usize; + let cap = (len + 3) & !3; + if cap > self.data.len() - self.pos { + return Err(MsgParserError::UnexpectedEof); + } + let pos = self.pos; + self.pos += cap; + Ok(&self.data[pos..pos + len]) + } } diff --git a/src/wire.rs b/src/wire.rs new file mode 100644 index 00000000..4b7c9fd3 --- /dev/null +++ b/src/wire.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/wire.rs")); diff --git a/wire/org_kde_kwin_server_decoration.txt b/wire/org_kde_kwin_server_decoration.txt new file mode 100644 index 00000000..2e083bf2 --- /dev/null +++ b/wire/org_kde_kwin_server_decoration.txt @@ -0,0 +1,15 @@ +# requests + +msg release = 0 { + +} + +msg request_mode = 1 { + mode: u32, +} + +# events + +msg mode = 0 { + mode: u32, +} diff --git a/wire/org_kde_kwin_server_decoration_manager.txt b/wire/org_kde_kwin_server_decoration_manager.txt new file mode 100644 index 00000000..6919d214 --- /dev/null +++ b/wire/org_kde_kwin_server_decoration_manager.txt @@ -0,0 +1,12 @@ +# requests + +msg create = 0 { + id: id(org_kde_kwin_server_decoration), + surface: id(wl_surface), +} + +# events + +msg default_mode = 0 { + mode: u32, +} diff --git a/wire/wl_buffer.txt b/wire/wl_buffer.txt new file mode 100644 index 00000000..b7a5ca52 --- /dev/null +++ b/wire/wl_buffer.txt @@ -0,0 +1,11 @@ +# requests + +msg destroy = 0 { + +} + +# events + +msg release = 0 { + +} diff --git a/wire/wl_callback.txt b/wire/wl_callback.txt new file mode 100644 index 00000000..cd661540 --- /dev/null +++ b/wire/wl_callback.txt @@ -0,0 +1,5 @@ +# events + +msg done = 0 { + callback_data: u32, +} diff --git a/wire/wl_compositor.txt b/wire/wl_compositor.txt new file mode 100644 index 00000000..1165960e --- /dev/null +++ b/wire/wl_compositor.txt @@ -0,0 +1,9 @@ +# requests + +msg create_surface = 0 { + id: id(wl_surface), +} + +msg create_region = 1 { + id: id(wl_region), +} diff --git a/wire/wl_data_device.txt b/wire/wl_data_device.txt new file mode 100644 index 00000000..d187b537 --- /dev/null +++ b/wire/wl_data_device.txt @@ -0,0 +1,49 @@ +# requests + +msg start_drag = 0 { + source: id(wl_data_source), + origin: id(wl_surface), + icon: id(wl_surface), + serial: u32, +} + +msg set_selection = 1 { + source: id(wl_data_source), + serial: u32, +} + +msg release = 2 { + +} + +# events + +msg data_offer = 0 { + id: id(wl_data_offer), +} + +msg enter = 1 { + serial: u32, + surface: id(wl_surface), + x: fixed, + y: fixed, + id: id(wl_data_offer), +} + +msg leave = 2 { + +} + +msg motion = 3 { + time: u32, + x: fixed, + y: fixed, +} + +msg drop = 4 { + +} + +msg selection = 5 { + id: id(wl_data_offer), +} diff --git a/wire/wl_data_device_manager.txt b/wire/wl_data_device_manager.txt new file mode 100644 index 00000000..24e5d883 --- /dev/null +++ b/wire/wl_data_device_manager.txt @@ -0,0 +1,10 @@ +# requests + +msg create_data_source = 0 { + id: id(wl_data_source), +} + +msg get_data_device = 1 { + id: id(wl_data_device), + seat: id(wl_seat), +} diff --git a/wire/wl_data_offer.txt b/wire/wl_data_offer.txt new file mode 100644 index 00000000..d67465a3 --- /dev/null +++ b/wire/wl_data_offer.txt @@ -0,0 +1,36 @@ +# requests + +msg accept = 0 { + serial: u32, + mime_type: str, +} + +msg receive = 1 { + mime_type: str, + fd: fd, +} + +msg destroy = 2 { +} + +msg finish = 3 { +} + +msg set_actions = 4 { + dnd_actions: u32, + preferred_action: u32, +} + +# events + +msg offer = 0 { + mime_type: str, +} + +msg source_actions = 1 { + source_actions: u32, +} + +msg action = 2 { + dnd_action: u32, +} diff --git a/wire/wl_data_source.txt b/wire/wl_data_source.txt new file mode 100644 index 00000000..8c6465a1 --- /dev/null +++ b/wire/wl_data_source.txt @@ -0,0 +1,40 @@ +# requests + +msg offer = 0 { + mime_type: str, +} + +msg destroy = 1 { + +} + +msg set_actions = 2 { + dnd_actions: u32, +} + +# events + +msg target = 0 { + mime_type: str, +} + +msg send = 1 { + mime_type: str, + fd: fd, +} + +msg cancelled = 2 { + +} + +msg dnd_drop_performed = 3 { + +} + +msg dnd_finished = 4 { + +} + +msg action = 5 { + dnd_action: u32, +} diff --git a/wire/wl_display.txt b/wire/wl_display.txt new file mode 100644 index 00000000..cb7971fc --- /dev/null +++ b/wire/wl_display.txt @@ -0,0 +1,21 @@ +# requests + +msg sync = 0 { + callback: id(wl_callback), +} + +msg get_registry = 1 { + registry: id(wl_registry), +} + +# events + +msg error = 0 { + object_id: id(object), + code: u32, + message: str, +} + +msg delete_id = 1 { + id: u32, +} diff --git a/wire/wl_drm.txt b/wire/wl_drm.txt new file mode 100644 index 00000000..7290e2f4 --- /dev/null +++ b/wire/wl_drm.txt @@ -0,0 +1,60 @@ +# requests + +msg authenticate = 0 { + id: u32, +} + +msg create_buffer = 1 { + id: id(wl_buffer), + name: u32, + width: i32, + height: i32, + stride: u32, + format: u32, +} + +msg create_planar_buffer = 2 { + id: id(wl_buffer), + name: u32, + width: i32, + height: i32, + format: u32, + offset0: i32, + stride0: i32, + offset1: i32, + stride1: i32, + offset2: i32, + stride2: i32, +} + +msg create_prime_buffer = 3 { + id: id(wl_buffer), + name: fd, + width : i32, + height : i32, + format : u32, + offset0 : i32, + stride0 : i32, + offset1 : i32, + stride1 : i32, + offset2 : i32, + stride2 : i32, +} + +# events + +msg device = 0 { + name: bstr, +} + +msg format = 1 { + format: u32, +} + +msg authenticated = 2 { + +} + +msg capabilities = 3 { + value: u32, +} diff --git a/wire/wl_keyboard.txt b/wire/wl_keyboard.txt new file mode 100644 index 00000000..a2d138fb --- /dev/null +++ b/wire/wl_keyboard.txt @@ -0,0 +1,44 @@ +# requests + +msg release = 0 { + +} + +# events + +msg keymap = 0 { + format: u32, + fd: fd, + size: u32, +} + +msg enter = 1 { + serial: u32, + surface: id(wl_surface), + keys: array(u32), +} + +msg leave = 2 { + serial: u32, + surface: id(wl_surface), +} + +msg key = 3 { + serial: u32, + time: u32, + key: u32, + state: u32, +} + +msg modifiers = 4 { + serial: u32, + mods_depressed: u32, + mods_latched: u32, + mods_locked: u32, + group: u32, +} + +msg repeat_info = 5 { + rate: i32, + delay: i32, +} diff --git a/wire/wl_output.txt b/wire/wl_output.txt new file mode 100644 index 00000000..fca84aa6 --- /dev/null +++ b/wire/wl_output.txt @@ -0,0 +1,41 @@ +# requests + +msg release = 0 { + +} + +# events + +msg geometry = 0 { + x : i32, + y : i32, + physical_width : i32, + physical_height : i32, + subpixel : i32, + make : str, + model : str, + transform : i32, +} + +msg mode = 1 { + flags : u32, + width : i32, + height : i32, + refresh : i32, +} + +msg done = 2 { + +} + +msg scale = 3 { + factor: i32, +} + +msg name = 4 { + name: str, +} + +msg description = 5 { + description: str, +} diff --git a/wire/wl_pointer.txt b/wire/wl_pointer.txt new file mode 100644 index 00000000..598db62b --- /dev/null +++ b/wire/wl_pointer.txt @@ -0,0 +1,63 @@ +# requests + +msg set_cursor = 0 { + serial: u32, + surface: id(wl_surface), + hotspot_x: i32, + hotspot_y: i32, +} + +msg release = 1 { + +} + +# events + +msg enter = 0 { + serial: u32, + surface: id(wl_surface), + surface_x: fixed, + surface_y: fixed, +} + +msg leave = 1 { + serial: u32, + surface: id(wl_surface), +} + +msg motion = 2 { + time: u32, + surface_x: fixed, + surface_y: fixed, +} + +msg button = 3 { + serial: u32, + time: u32, + button: u32, + state: u32, +} + +msg axis = 4 { + time: u32, + axis: u32, + value: fixed, +} + +msg frame = 5 { + +} + +msg axis_source = 6 { + axis_source: u32, +} + +msg axis_stop = 7 { + time: u32, + axis: u32, +} + +msg axis_discrete = 8 { + axis: u32, + discrete: i32, +} diff --git a/wire/wl_region.txt b/wire/wl_region.txt new file mode 100644 index 00000000..efa74ccd --- /dev/null +++ b/wire/wl_region.txt @@ -0,0 +1,19 @@ +# requests + +msg destroy = 0 { + +} + +msg add = 1 { + x: i32, + y: i32, + width: i32, + height: i32, +} + +msg subtract = 2 { + x: i32, + y: i32, + width: i32, + height: i32, +} diff --git a/wire/wl_registry.txt b/wire/wl_registry.txt new file mode 100644 index 00000000..c0b32716 --- /dev/null +++ b/wire/wl_registry.txt @@ -0,0 +1,20 @@ +# requests + +msg bind = 0 { + name: u32, + id: id(object), + interface: str, + version: u32, +} + +# events + +msg global = 0 { + name: u32, + interface: str, + version: u32, +} + +msg global_remove = 1 { + name: u32, +} diff --git a/wire/wl_seat.txt b/wire/wl_seat.txt new file mode 100644 index 00000000..053e95ef --- /dev/null +++ b/wire/wl_seat.txt @@ -0,0 +1,26 @@ +# requests + +msg get_pointer = 0 { + id: id(wl_pointer), +} + +msg get_keyboard = 1 { + id: id(wl_keyboard), +} + +msg get_touch = 2 { + id: id(wl_touch), +} + +msg release = 3 { +} + +# events + +msg capabilities = 0 { + capabilities: u32, +} + +msg name = 1 { + name: str, +}