From d8380b3dce63c9fdb2f9de34bc9d3a1dbdf4b70f Mon Sep 17 00:00:00 2001 From: kossLAN Date: Fri, 29 May 2026 11:02:40 -0400 Subject: [PATCH] xcon: move wire core into workspace crate --- Cargo.lock | 14 ++++ Cargo.toml | 2 + src/xcon.rs | 94 ++------------------------- src/xcon/incoming.rs | 2 +- xcon/Cargo.toml | 15 +++++ {src/xcon => xcon/src}/consts.rs | 0 {src/xcon => xcon/src}/formatter.rs | 3 +- xcon/src/lib.rs | 95 ++++++++++++++++++++++++++++ {src/xcon => xcon/src}/parser.rs | 6 +- {src/xcon => xcon/src}/wire_type.rs | 4 +- {src/xcon => xcon/src}/xauthority.rs | 2 +- 11 files changed, 138 insertions(+), 99 deletions(-) create mode 100644 xcon/Cargo.toml rename {src/xcon => xcon/src}/consts.rs (100%) rename {src/xcon => xcon/src}/formatter.rs (97%) create mode 100644 xcon/src/lib.rs rename {src/xcon => xcon/src}/parser.rs (97%) rename {src/xcon => xcon/src}/wire_type.rs (97%) rename {src/xcon => xcon/src}/xauthority.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index 6e90ca2b..7e6d4c1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -707,6 +707,7 @@ dependencies = [ "jay-tracy", "jay-units", "jay-utils", + "jay-xcon", "kbvm", "libloading", "linearize", @@ -883,6 +884,19 @@ dependencies = [ "uapi", ] +[[package]] +name = "jay-xcon" +version = "0.1.0" +dependencies = [ + "bstr", + "jay-bufio", + "jay-io-uring", + "jay-utils", + "log", + "thiserror", + "uapi", +] + [[package]] name = "js-sys" version = "0.3.91" diff --git a/Cargo.toml b/Cargo.toml index 8237e3c0..3393b9c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ members = [ "io-uring", "bufio", "dbus-core", + "xcon", "toml-config", "algorithms", "toml-spec", @@ -63,6 +64,7 @@ jay-async-engine = { version = "0.1.0", path = "async-engine" } jay-io-uring = { version = "0.1.0", path = "io-uring" } jay-bufio = { version = "0.1.0", path = "bufio" } jay-dbus-core = { version = "0.1.0", path = "dbus-core" } +jay-xcon = { version = "0.1.0", path = "xcon" } uapi = "0.2.13" thiserror = "2.0.11" diff --git a/src/xcon.rs b/src/xcon.rs index 0cd9ebc2..764f25dc 100644 --- a/src/xcon.rs +++ b/src/xcon.rs @@ -1,21 +1,18 @@ -pub use crate::xcon::{ - formatter::Formatter, - parser::Parser, - wire_type::{Message, Request, XEvent}, +pub use jay_xcon::{ + consts, xauthority, Formatter, Message, Parser, Request, SendEvent, XEvent, XconError, }; use { crate::{ async_engine::{Phase, SpawnedFuture}, compositor::DISPLAY, - io_uring::IoUringError, state::State, utils::{ buf::DynamicBuf, - bufio::{BufIo, BufIoError, BufIoMessage}, + bufio::{BufIo, BufIoMessage}, clonecell::CloneCell, errorfmt::ErrorFmt, numcell::NumCell, - oserror::{OsError, OsErrorExt2}, + oserror::OsErrorExt2, queue::AsyncQueue, stack::Stack, vec_ext::VecExt, @@ -29,7 +26,6 @@ use { consts::{IMAGE_FORMAT_Z_PIXMAP, RENDER_PICT_TYPE_DIRECT}, incoming::handle_incoming, outgoing::handle_outgoing, - wire_type::SendEvent, xauthority::{LOCAL, MIT_MAGIC_COOKIE, XAuthority}, }, }, @@ -49,93 +45,11 @@ use { rc::{Rc, Weak}, task::{Context, Poll, Waker}, }, - thiserror::Error, uapi::{OwnedFd, c}, }; -pub mod consts; -mod formatter; mod incoming; mod outgoing; -mod parser; -mod wire_type; -mod xauthority; - -#[derive(Debug, Error)] -pub enum XconError { - #[error("Unexpected EOF")] - UnexpectedEof, - #[error("Buffer slice is not properly aligned")] - UnalignedSlice, - #[error("Neither XAUTHORITY nor HOME is set")] - HomeNotSet, - #[error("Could not read Xauthority file")] - ReadXAuthority(#[source] std::io::Error), - #[error("Display field in Xauthority could not be parsed")] - InvalidAuthorityDisplay, - #[error("The DISPLAY is not set")] - DisplayNotSet, - #[error("DISPLAY contains an invalid value")] - InvalidDisplayFormat, - #[error("Could not create a unix socket")] - CreateSocket(#[source] OsError), - #[error("Could not connect to Xserver")] - ConnectSocket(#[source] IoUringError), - #[error("Could not retrive the hostname")] - Hostname(#[source] OsError), - #[error("Server did not send enough fds")] - NotEnoughFds, - #[error("Server rejected our connection attempt: {0}")] - Connect(BString), - #[error("Server requires additional authentication: {0}")] - Authenticate(BString), - #[error(transparent)] - BufIoError(#[from] BufIoError), - #[error("The server did not send a reply to a request")] - MissingReply, - #[error("The server did not send fds with a reply")] - MissingFds, - #[error("The server sent a message with an excessive size")] - ExcessiveMessageSize, - #[error(transparent)] - XconError(Rc), - #[error("The server does not support the `{0}` extension")] - ExtensionUnavailable(&'static str), - #[error("The server returned error {0}")] - CoreError(u8), - #[error("The extension `{}` returned error {}", .0.name(), .1)] - ExtensionError(Extension, u8), - #[error("The connection to the server has already been closed")] - Dead, - #[error("Could not query the `{0}` extension")] - QueryExtension(BString, #[source] Box), - #[error("All available xids have been used")] - XidExhausted, - #[error("Enum contains an unknown variant")] - UnknownEnumVariant, - #[error("Could not query the render pict formats")] - QueryPictFormats(#[source] Box), - #[error("The server does not support the picture format for cursors")] - CursorFormatNotSupported, - #[error("Could not create a pixmap")] - CreatePixmap(#[source] Box), - #[error("Could not create a graphics context")] - CreateGc(#[source] Box), - #[error("Could not upload an image")] - PutImage(#[source] Box), - #[error("Could not create a picture")] - CreatePicture(#[source] Box), - #[error("Could not create a cursor")] - CreateCursor(#[source] Box), - #[error("Property has an invalid type")] - InvalidPropertyType, - #[error("Property has an invalid format. Expected: {0}; Actual: {1}")] - InvalidPropertyFormat(u8, u8), - #[error("Length of the property data is not a multiple of its format")] - IrregularPropertyLength, - #[error("The property is not set")] - PropertyUnavailable, -} #[derive(Debug)] struct ExtensionIdRange { diff --git a/src/xcon/incoming.rs b/src/xcon/incoming.rs index 540bb4cd..47965304 100644 --- a/src/xcon/incoming.rs +++ b/src/xcon/incoming.rs @@ -99,7 +99,7 @@ impl Incoming { break 'handle_error; }; let e = match ext { - Some(e) => XconError::ExtensionError(e, code), + Some(e) => XconError::ExtensionError(e.name(), code), _ => XconError::CoreError(code), }; if let Some(first) = reply_handlers.front() diff --git a/xcon/Cargo.toml b/xcon/Cargo.toml new file mode 100644 index 00000000..8b5d85e6 --- /dev/null +++ b/xcon/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "jay-xcon" +version = "0.1.0" +edition = "2024" +license = "GPL-3.0-only" + +[dependencies] +jay-bufio = { version = "0.1.0", path = "../bufio" } +jay-io-uring = { version = "0.1.0", path = "../io-uring" } +jay-utils = { version = "0.1.0", path = "../utils" } + +bstr = { version = "1.9.0", default-features = false, features = ["std"] } +log = { version = "0.4.20", features = ["std"] } +thiserror = "2.0.11" +uapi = "0.2.13" diff --git a/src/xcon/consts.rs b/xcon/src/consts.rs similarity index 100% rename from src/xcon/consts.rs rename to xcon/src/consts.rs diff --git a/src/xcon/formatter.rs b/xcon/src/formatter.rs similarity index 97% rename from src/xcon/formatter.rs rename to xcon/src/formatter.rs index e1fcf21f..d284c23b 100644 --- a/src/xcon/formatter.rs +++ b/xcon/src/formatter.rs @@ -1,5 +1,6 @@ use { - crate::{utils::buf::DynamicBuf, xcon::Message}, + crate::Message, + jay_utils::buf::DynamicBuf, std::rc::Rc, uapi::{AssertPacked, OwnedFd, Packed}, }; diff --git a/xcon/src/lib.rs b/xcon/src/lib.rs new file mode 100644 index 00000000..09db05d6 --- /dev/null +++ b/xcon/src/lib.rs @@ -0,0 +1,95 @@ +pub use { + formatter::Formatter, + parser::Parser, + wire_type::{Message, Request, SendEvent, XEvent}, +}; +use { + bstr::BString, + jay_bufio::BufIoError, + jay_io_uring::IoUringError, + jay_utils::oserror::OsError, + std::rc::Rc, + thiserror::Error, +}; + +pub mod consts; +mod formatter; +mod parser; +mod wire_type; +pub mod xauthority; + +#[derive(Debug, Error)] +pub enum XconError { + #[error("Unexpected EOF")] + UnexpectedEof, + #[error("Buffer slice is not properly aligned")] + UnalignedSlice, + #[error("Neither XAUTHORITY nor HOME is set")] + HomeNotSet, + #[error("Could not read Xauthority file")] + ReadXAuthority(#[source] std::io::Error), + #[error("Display field in Xauthority could not be parsed")] + InvalidAuthorityDisplay, + #[error("The DISPLAY is not set")] + DisplayNotSet, + #[error("DISPLAY contains an invalid value")] + InvalidDisplayFormat, + #[error("Could not create a unix socket")] + CreateSocket(#[source] OsError), + #[error("Could not connect to Xserver")] + ConnectSocket(#[source] IoUringError), + #[error("Could not retrive the hostname")] + Hostname(#[source] OsError), + #[error("Server did not send enough fds")] + NotEnoughFds, + #[error("Server rejected our connection attempt: {0}")] + Connect(BString), + #[error("Server requires additional authentication: {0}")] + Authenticate(BString), + #[error(transparent)] + BufIoError(#[from] BufIoError), + #[error("The server did not send a reply to a request")] + MissingReply, + #[error("The server did not send fds with a reply")] + MissingFds, + #[error("The server sent a message with an excessive size")] + ExcessiveMessageSize, + #[error(transparent)] + XconError(Rc), + #[error("The server does not support the `{0}` extension")] + ExtensionUnavailable(&'static str), + #[error("The server returned error {0}")] + CoreError(u8), + #[error("The extension `{0}` returned error {1}")] + ExtensionError(&'static str, u8), + #[error("The connection to the server has already been closed")] + Dead, + #[error("Could not query the `{0}` extension")] + QueryExtension(BString, #[source] Box), + #[error("All available xids have been used")] + XidExhausted, + #[error("Enum contains an unknown variant")] + UnknownEnumVariant, + #[error("Could not query the render pict formats")] + QueryPictFormats(#[source] Box), + #[error("The server does not support the picture format for cursors")] + CursorFormatNotSupported, + #[error("Could not create a pixmap")] + CreatePixmap(#[source] Box), + #[error("Could not create a graphics context")] + CreateGc(#[source] Box), + #[error("Could not upload an image")] + PutImage(#[source] Box), + #[error("Could not create a picture")] + CreatePicture(#[source] Box), + #[error("Could not create a cursor")] + CreateCursor(#[source] Box), + #[error("Property has an invalid type")] + InvalidPropertyType, + #[error("Property has an invalid format. Expected: {0}; Actual: {1}")] + InvalidPropertyFormat(u8, u8), + #[error("Length of the property data is not a multiple of its format")] + IrregularPropertyLength, + #[error("The property is not set")] + PropertyUnavailable, +} diff --git a/src/xcon/parser.rs b/xcon/src/parser.rs similarity index 97% rename from src/xcon/parser.rs rename to xcon/src/parser.rs index a8d103f0..d68d47e9 100644 --- a/src/xcon/parser.rs +++ b/xcon/src/parser.rs @@ -1,9 +1,7 @@ use { - crate::{ - utils::ptr_ext::PtrExt, - xcon::{XconError, wire_type::Message}, - }, + crate::{Message, XconError}, bstr::{BStr, ByteSlice}, + jay_utils::ptr_ext::PtrExt, std::{borrow::Cow, rc::Rc}, uapi::{OwnedFd, Pod}, }; diff --git a/src/xcon/wire_type.rs b/xcon/src/wire_type.rs similarity index 97% rename from src/xcon/wire_type.rs rename to xcon/src/wire_type.rs index a3dbbfa5..7e932360 100644 --- a/src/xcon/wire_type.rs +++ b/xcon/src/wire_type.rs @@ -1,5 +1,5 @@ use { - crate::xcon::{XconError, formatter::Formatter, parser::Parser}, + crate::{Formatter, Parser, XconError}, bstr::{BStr, ByteSlice}, std::{borrow::Cow, fmt::Debug, rc::Rc}, uapi::OwnedFd, @@ -118,7 +118,7 @@ unsafe impl<'a> Message<'a> for Rc { } #[derive(Debug, Clone)] -pub(super) struct SendEvent { +pub struct SendEvent { pub propagate: u8, pub destination: u32, pub event_mask: u32, diff --git a/src/xcon/xauthority.rs b/xcon/src/xauthority.rs similarity index 98% rename from src/xcon/xauthority.rs rename to xcon/src/xauthority.rs index 09827d30..aeff63aa 100644 --- a/src/xcon/xauthority.rs +++ b/xcon/src/xauthority.rs @@ -1,5 +1,5 @@ use { - crate::xcon::XconError, + crate::XconError, bstr::{BString, ByteSlice}, std::{fs::File, io::Read}, };