1
0
Fork 0
forked from wry/wry

xcon: move wire core into workspace crate

This commit is contained in:
kossLAN 2026-05-29 11:02:40 -04:00
parent 61ec13def0
commit d8380b3dce
No known key found for this signature in database
11 changed files with 138 additions and 99 deletions

14
Cargo.lock generated
View file

@ -707,6 +707,7 @@ dependencies = [
"jay-tracy", "jay-tracy",
"jay-units", "jay-units",
"jay-utils", "jay-utils",
"jay-xcon",
"kbvm", "kbvm",
"libloading", "libloading",
"linearize", "linearize",
@ -883,6 +884,19 @@ dependencies = [
"uapi", "uapi",
] ]
[[package]]
name = "jay-xcon"
version = "0.1.0"
dependencies = [
"bstr",
"jay-bufio",
"jay-io-uring",
"jay-utils",
"log",
"thiserror",
"uapi",
]
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.91" version = "0.3.91"

View file

@ -31,6 +31,7 @@ members = [
"io-uring", "io-uring",
"bufio", "bufio",
"dbus-core", "dbus-core",
"xcon",
"toml-config", "toml-config",
"algorithms", "algorithms",
"toml-spec", "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-io-uring = { version = "0.1.0", path = "io-uring" }
jay-bufio = { version = "0.1.0", path = "bufio" } jay-bufio = { version = "0.1.0", path = "bufio" }
jay-dbus-core = { version = "0.1.0", path = "dbus-core" } jay-dbus-core = { version = "0.1.0", path = "dbus-core" }
jay-xcon = { version = "0.1.0", path = "xcon" }
uapi = "0.2.13" uapi = "0.2.13"
thiserror = "2.0.11" thiserror = "2.0.11"

View file

@ -1,21 +1,18 @@
pub use crate::xcon::{ pub use jay_xcon::{
formatter::Formatter, consts, xauthority, Formatter, Message, Parser, Request, SendEvent, XEvent, XconError,
parser::Parser,
wire_type::{Message, Request, XEvent},
}; };
use { use {
crate::{ crate::{
async_engine::{Phase, SpawnedFuture}, async_engine::{Phase, SpawnedFuture},
compositor::DISPLAY, compositor::DISPLAY,
io_uring::IoUringError,
state::State, state::State,
utils::{ utils::{
buf::DynamicBuf, buf::DynamicBuf,
bufio::{BufIo, BufIoError, BufIoMessage}, bufio::{BufIo, BufIoMessage},
clonecell::CloneCell, clonecell::CloneCell,
errorfmt::ErrorFmt, errorfmt::ErrorFmt,
numcell::NumCell, numcell::NumCell,
oserror::{OsError, OsErrorExt2}, oserror::OsErrorExt2,
queue::AsyncQueue, queue::AsyncQueue,
stack::Stack, stack::Stack,
vec_ext::VecExt, vec_ext::VecExt,
@ -29,7 +26,6 @@ use {
consts::{IMAGE_FORMAT_Z_PIXMAP, RENDER_PICT_TYPE_DIRECT}, consts::{IMAGE_FORMAT_Z_PIXMAP, RENDER_PICT_TYPE_DIRECT},
incoming::handle_incoming, incoming::handle_incoming,
outgoing::handle_outgoing, outgoing::handle_outgoing,
wire_type::SendEvent,
xauthority::{LOCAL, MIT_MAGIC_COOKIE, XAuthority}, xauthority::{LOCAL, MIT_MAGIC_COOKIE, XAuthority},
}, },
}, },
@ -49,93 +45,11 @@ use {
rc::{Rc, Weak}, rc::{Rc, Weak},
task::{Context, Poll, Waker}, task::{Context, Poll, Waker},
}, },
thiserror::Error,
uapi::{OwnedFd, c}, uapi::{OwnedFd, c},
}; };
pub mod consts;
mod formatter;
mod incoming; mod incoming;
mod outgoing; 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<XconError>),
#[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<XconError>),
#[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<XconError>),
#[error("The server does not support the picture format for cursors")]
CursorFormatNotSupported,
#[error("Could not create a pixmap")]
CreatePixmap(#[source] Box<XconError>),
#[error("Could not create a graphics context")]
CreateGc(#[source] Box<XconError>),
#[error("Could not upload an image")]
PutImage(#[source] Box<XconError>),
#[error("Could not create a picture")]
CreatePicture(#[source] Box<XconError>),
#[error("Could not create a cursor")]
CreateCursor(#[source] Box<XconError>),
#[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)] #[derive(Debug)]
struct ExtensionIdRange { struct ExtensionIdRange {

View file

@ -99,7 +99,7 @@ impl Incoming {
break 'handle_error; break 'handle_error;
}; };
let e = match ext { let e = match ext {
Some(e) => XconError::ExtensionError(e, code), Some(e) => XconError::ExtensionError(e.name(), code),
_ => XconError::CoreError(code), _ => XconError::CoreError(code),
}; };
if let Some(first) = reply_handlers.front() if let Some(first) = reply_handlers.front()

15
xcon/Cargo.toml Normal file
View file

@ -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"

View file

@ -1,5 +1,6 @@
use { use {
crate::{utils::buf::DynamicBuf, xcon::Message}, crate::Message,
jay_utils::buf::DynamicBuf,
std::rc::Rc, std::rc::Rc,
uapi::{AssertPacked, OwnedFd, Packed}, uapi::{AssertPacked, OwnedFd, Packed},
}; };

95
xcon/src/lib.rs Normal file
View file

@ -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<XconError>),
#[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<XconError>),
#[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<XconError>),
#[error("The server does not support the picture format for cursors")]
CursorFormatNotSupported,
#[error("Could not create a pixmap")]
CreatePixmap(#[source] Box<XconError>),
#[error("Could not create a graphics context")]
CreateGc(#[source] Box<XconError>),
#[error("Could not upload an image")]
PutImage(#[source] Box<XconError>),
#[error("Could not create a picture")]
CreatePicture(#[source] Box<XconError>),
#[error("Could not create a cursor")]
CreateCursor(#[source] Box<XconError>),
#[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,
}

View file

@ -1,9 +1,7 @@
use { use {
crate::{ crate::{Message, XconError},
utils::ptr_ext::PtrExt,
xcon::{XconError, wire_type::Message},
},
bstr::{BStr, ByteSlice}, bstr::{BStr, ByteSlice},
jay_utils::ptr_ext::PtrExt,
std::{borrow::Cow, rc::Rc}, std::{borrow::Cow, rc::Rc},
uapi::{OwnedFd, Pod}, uapi::{OwnedFd, Pod},
}; };

View file

@ -1,5 +1,5 @@
use { use {
crate::xcon::{XconError, formatter::Formatter, parser::Parser}, crate::{Formatter, Parser, XconError},
bstr::{BStr, ByteSlice}, bstr::{BStr, ByteSlice},
std::{borrow::Cow, fmt::Debug, rc::Rc}, std::{borrow::Cow, fmt::Debug, rc::Rc},
uapi::OwnedFd, uapi::OwnedFd,
@ -118,7 +118,7 @@ unsafe impl<'a> Message<'a> for Rc<OwnedFd> {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(super) struct SendEvent { pub struct SendEvent {
pub propagate: u8, pub propagate: u8,
pub destination: u32, pub destination: u32,
pub event_mask: u32, pub event_mask: u32,

View file

@ -1,5 +1,5 @@
use { use {
crate::xcon::XconError, crate::XconError,
bstr::{BString, ByteSlice}, bstr::{BString, ByteSlice},
std::{fs::File, io::Read}, std::{fs::File, io::Read},
}; };