1
0
Fork 0
forked from wry/wry

config: expose runtime protocol

This commit is contained in:
kossLAN 2026-05-29 18:36:27 -04:00
parent bcc85c8b1b
commit e3f122e903
No known key found for this signature in database
16 changed files with 179 additions and 157 deletions

1
Cargo.lock generated
View file

@ -792,7 +792,6 @@ name = "jay-config"
version = "1.10.0" version = "1.10.0"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bincode",
"bstr", "bstr",
"error_reporter", "error_reporter",
"futures-util", "futures-util",

View file

@ -7,7 +7,6 @@ description = "Configuration crate for the Jay compositor"
repository = "https://github.com/mahkoh/jay" repository = "https://github.com/mahkoh/jay"
[dependencies] [dependencies]
bincode = "1.3.3"
serde = { version = "1.0.196", features = ["derive"] } serde = { version = "1.0.196", features = ["derive"] }
log = "0.4.14" log = "0.4.14"
futures-util = { version = "0.3.30", features = ["io"] } futures-util = { version = "0.3.30", features = ["io"] }

View file

@ -1,124 +1,15 @@
pub mod client; pub mod client;
pub mod messages;
mod logging; mod logging;
use { pub use crate::protocol::{
crate::{ ClientCriterionPayload, ClientCriterionStringField, ConfigEntry, ConfigHandler,
Workspace, DEFAULT_SEAT_NAME, GenericCriterionPayload, PollableId, ServerHandler, Unref, VERSION,
client::ClientMatcher, WindowCriterionPayload, WindowCriterionStringField, WireMode,
input::Seat,
video::Mode,
window::{ContentType, WindowMatcher, WindowType},
},
bincode::Options,
serde::{Deserialize, Serialize},
}; };
pub const VERSION: u32 = 1; pub mod messages {
pub use crate::protocol::{
pub type ServerHandler = unsafe fn(data: *const u8, msg: &messages::ClientMessage<'_>); ClientMessage, InitMessage, Response, ServerFeature, ServerMessage, V1InitMessage,
pub type ConfigHandler = unsafe fn(data: *const u8, msg: &messages::ServerMessage); WorkspaceSource,
pub type Unref = unsafe fn(data: *const u8); };
pub struct ConfigEntry {
pub version: u32,
pub init: unsafe fn(
srv_data: *const u8,
srv_unref: Unref,
srv_handler: ServerHandler,
msg: messages::InitMessage,
) -> *const u8,
pub unref: Unref,
pub handle_msg: ConfigHandler,
}
pub fn bincode_ops() -> impl Options {
bincode::DefaultOptions::new()
.with_fixint_encoding()
.with_little_endian()
.with_no_limit()
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct WireMode {
pub width: i32,
pub height: i32,
pub refresh_millihz: u32,
}
impl WireMode {
pub fn to_mode(self) -> Mode {
Mode {
width: self.width,
height: self.height,
refresh_millihz: self.refresh_millihz,
}
}
}
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct PollableId(pub u64);
pub const DEFAULT_SEAT_NAME: &str = "default";
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
pub enum GenericCriterionPayload<T> {
Matcher(T),
Not(T),
List { list: Vec<T>, all: bool },
Exactly { list: Vec<T>, num: usize },
}
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
pub enum ClientCriterionPayload {
Generic(GenericCriterionPayload<ClientMatcher>),
String {
string: String,
field: ClientCriterionStringField,
regex: bool,
},
Sandboxed,
Uid(i32),
Pid(i32),
IsXwayland,
}
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
pub enum ClientCriterionStringField {
SandboxEngine,
SandboxAppId,
SandboxInstanceId,
Comm,
Exe,
}
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
pub enum WindowCriterionPayload {
Generic(GenericCriterionPayload<WindowMatcher>),
String {
string: String,
field: WindowCriterionStringField,
regex: bool,
},
Types(WindowType),
Client(ClientMatcher),
Floating,
Visible,
Urgent,
SeatFocus(Seat),
Fullscreen,
JustMapped,
Workspace(Workspace),
ContentTypes(ContentType),
}
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
pub enum WindowCriterionStringField {
Title,
AppId,
Tag,
XClass,
XInstance,
XRole,
Workspace,
} }

View file

@ -3,11 +3,7 @@
use { use {
crate::{ crate::{
_private::{ _private::{
ClientCriterionPayload, ClientCriterionStringField, GenericCriterionPayload, PollableId, ServerHandler, Unref,
ServerHandler, Unref, WindowCriterionPayload, WindowCriterionStringField, WireMode,
messages::{
ClientMessage, InitMessage, Response, ServerFeature, ServerMessage, WorkspaceSource,
},
}, },
Axis, Direction, ModifiedKeySym, PciId, Workspace, Axis, Direction, ModifiedKeySym, PciId, Workspace,
client::{Client, ClientCriterion, ClientMatcher, MatchedClient}, client::{Client, ClientCriterion, ClientMatcher, MatchedClient},
@ -23,6 +19,12 @@ use {
syms::KeySym, syms::KeySym,
}, },
logging::LogLevel, logging::LogLevel,
protocol::{
ClientCriterionPayload, ClientCriterionStringField, ClientMessage,
GenericCriterionPayload, InitMessage, PollableId, Response, ServerFeature,
ServerMessage, WindowCriterionPayload, WindowCriterionStringField, WireMode,
WorkspaceSource,
},
tasks::{JoinHandle, JoinSlot}, tasks::{JoinHandle, JoinSlot},
theme::{BarPosition, Color, colors::Colorable, sized::Resizable}, theme::{BarPosition, Color, colors::Colorable, sized::Resizable},
timer::Timer, timer::Timer,

View file

@ -6,10 +6,10 @@ pub mod clickmethod;
use { use {
crate::{ crate::{
_private::{DEFAULT_SEAT_NAME, messages::WorkspaceSource},
Axis, Direction, ModifiedKeySym, Workspace, Axis, Direction, ModifiedKeySym, Workspace,
input::{acceleration::AccelProfile, capability::Capability, clickmethod::ClickMethod}, input::{acceleration::AccelProfile, capability::Capability, clickmethod::ClickMethod},
keyboard::{Keymap, mods::Modifiers, syms::KeySym}, keyboard::{Keymap, mods::Modifiers, syms::KeySym},
protocol::{DEFAULT_SEAT_NAME, WorkspaceSource},
video::Connector, video::Connector,
window::Window, window::Window,
}, },

View file

@ -1,7 +1,7 @@
//! Tools for IO operations. //! Tools for IO operations.
use { use {
crate::_private::PollableId, crate::protocol::PollableId,
futures_util::{AsyncWrite, io::AsyncRead}, futures_util::{AsyncWrite, io::AsyncRead},
std::{ std::{
future::poll_fn, future::poll_fn,

View file

@ -17,7 +17,7 @@ use crate::input::Seat;
use { use {
crate::{ crate::{
_private::messages::WorkspaceSource, keyboard::ModifiedKeySym, video::Connector, window::Window, keyboard::ModifiedKeySym, protocol::WorkspaceSource, video::Connector, window::Window,
}, },
serde::{Deserialize, Serialize}, serde::{Deserialize, Serialize},
std::{ std::{
@ -37,6 +37,7 @@ pub mod input;
pub mod io; pub mod io;
pub mod keyboard; pub mod keyboard;
pub mod logging; pub mod logging;
pub mod protocol;
pub mod status; pub mod status;
pub mod tasks; pub mod tasks;
pub mod theme; pub mod theme;

View file

@ -1,6 +1,5 @@
use { use {
crate::{ crate::{
_private::{ClientCriterionPayload, PollableId, WindowCriterionPayload, WireMode},
Axis, Direction, PciId, Workspace, Axis, Direction, PciId, Workspace,
client::{Client, ClientMatcher}, client::{Client, ClientMatcher},
input::{ input::{
@ -13,7 +12,7 @@ use {
theme::{BarPosition, Color, colors::Colorable, sized::Resizable}, theme::{BarPosition, Color, colors::Colorable, sized::Resizable},
timer::Timer, timer::Timer,
video::{ video::{
BlendSpace, ColorSpace, Connector, DrmDevice, Eotf, Format, GfxApi, TearingMode, BlendSpace, ColorSpace, Connector, DrmDevice, Eotf, Format, GfxApi, Mode, TearingMode,
Transform, VrrMode, connector_type::ConnectorType, Transform, VrrMode, connector_type::ConnectorType,
}, },
window::{ContentType, TileState, Window, WindowMatcher, WindowType}, window::{ContentType, TileState, Window, WindowMatcher, WindowType},
@ -24,6 +23,132 @@ use {
std::time::{Duration, SystemTime}, std::time::{Duration, SystemTime},
}; };
pub const VERSION: u32 = 1;
pub type ServerHandler = unsafe fn(data: *const u8, msg: &ClientMessage<'_>);
pub type ConfigHandler = unsafe fn(data: *const u8, msg: &ServerMessage);
pub type Unref = unsafe fn(data: *const u8);
pub struct ConfigEntry {
pub version: u32,
pub init: unsafe fn(
srv_data: *const u8,
srv_unref: Unref,
srv_handler: ServerHandler,
msg: InitMessage,
) -> *const u8,
pub unref: Unref,
pub handle_msg: ConfigHandler,
}
pub unsafe fn init_client(
srv_data: *const u8,
srv_unref: Unref,
srv_handler: ServerHandler,
msg: InitMessage,
configure: fn(),
) -> *const u8 {
unsafe {
crate::_private::client::init(srv_data, srv_unref, srv_handler, msg, configure)
}
}
pub unsafe fn unref_client(data: *const u8) {
unsafe {
crate::_private::client::unref(data);
}
}
pub unsafe fn handle_client_message(data: *const u8, msg: &ServerMessage) {
unsafe {
crate::_private::client::handle_msg(data, msg);
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct WireMode {
pub width: i32,
pub height: i32,
pub refresh_millihz: u32,
}
impl WireMode {
pub fn to_mode(self) -> Mode {
Mode {
width: self.width,
height: self.height,
refresh_millihz: self.refresh_millihz,
}
}
}
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct PollableId(pub u64);
pub const DEFAULT_SEAT_NAME: &str = "default";
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
pub enum GenericCriterionPayload<T> {
Matcher(T),
Not(T),
List { list: Vec<T>, all: bool },
Exactly { list: Vec<T>, num: usize },
}
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
pub enum ClientCriterionPayload {
Generic(GenericCriterionPayload<ClientMatcher>),
String {
string: String,
field: ClientCriterionStringField,
regex: bool,
},
Sandboxed,
Uid(i32),
Pid(i32),
IsXwayland,
}
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
pub enum ClientCriterionStringField {
SandboxEngine,
SandboxAppId,
SandboxInstanceId,
Comm,
Exe,
}
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
pub enum WindowCriterionPayload {
Generic(GenericCriterionPayload<WindowMatcher>),
String {
string: String,
field: WindowCriterionStringField,
regex: bool,
},
Types(WindowType),
Client(ClientMatcher),
Floating,
Visible,
Urgent,
SeatFocus(Seat),
Fullscreen,
JustMapped,
Workspace(Workspace),
ContentTypes(ContentType),
}
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
pub enum WindowCriterionStringField {
Title,
AppId,
Tag,
XClass,
XInstance,
XRole,
Workspace,
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)] #[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
#[serde(transparent)] #[serde(transparent)]
pub struct ServerFeature(u16); pub struct ServerFeature(u16);

View file

@ -2,8 +2,8 @@
use { use {
crate::{ crate::{
_private::WireMode,
Direction, PciId, Workspace, Direction, PciId, Workspace,
protocol::WireMode,
video::connector_type::{ video::connector_type::{
CON_9PIN_DIN, CON_COMPONENT, CON_COMPOSITE, CON_DISPLAY_PORT, CON_DPI, CON_DSI, CON_9PIN_DIN, CON_COMPONENT, CON_COMPOSITE, CON_DISPLAY_PORT, CON_DPI, CON_DSI,
CON_DVIA, CON_DVID, CON_DVII, CON_EDP, CON_EMBEDDED_WINDOW, CON_HDMIA, CON_HDMIB, CON_DVIA, CON_DVID, CON_DVII, CON_EDP, CON_EMBEDDED_WINDOW, CON_HDMIA, CON_HDMIB,

View file

@ -84,7 +84,7 @@ use {
}, },
ahash::AHashSet, ahash::AHashSet,
forker::ForkerProxy, forker::ForkerProxy,
jay_config::_private::DEFAULT_SEAT_NAME, jay_config::protocol::DEFAULT_SEAT_NAME,
std::{ std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
env, env,

View file

@ -16,9 +16,9 @@ use {
}, },
}, },
jay_config::{ jay_config::{
_private::{ protocol::{
ConfigEntry, VERSION, ClientMessage, ConfigEntry, InitMessage, ServerFeature, ServerHandler, ServerMessage,
messages::{InitMessage, ServerFeature, ServerMessage, V1InitMessage}, Unref, V1InitMessage, VERSION, handle_client_message, init_client, unref_client,
}, },
input::{InputDevice, Seat, SwitchEvent}, input::{InputDevice, Seat, SwitchEvent},
keyboard::{mods::Modifiers, syms::KeySym}, keyboard::{mods::Modifiers, syms::KeySym},
@ -168,15 +168,15 @@ impl Drop for ConfigProxy {
unsafe fn default_client_init( unsafe fn default_client_init(
srv_data: *const u8, srv_data: *const u8,
srv_unref: jay_config::_private::Unref, srv_unref: Unref,
srv_handler: jay_config::_private::ServerHandler, srv_handler: ServerHandler,
msg: InitMessage, msg: InitMessage,
) -> *const u8 { ) -> *const u8 {
fn configure() { fn configure() {
jay_toml_config::configure(); jay_toml_config::configure();
} }
unsafe { unsafe {
jay_config::_private::client::init(srv_data, srv_unref, srv_handler, msg, configure) init_client(srv_data, srv_unref, srv_handler, msg, configure)
} }
} }
@ -241,8 +241,8 @@ impl ConfigProxy {
let entry = ConfigEntry { let entry = ConfigEntry {
version: VERSION, version: VERSION,
init: default_client_init, init: default_client_init,
unref: jay_config::_private::client::unref, unref: unref_client,
handle_msg: jay_config::_private::client::handle_msg, handle_msg: handle_client_message,
}; };
Self::new(&entry, state) Self::new(&entry, state)
} }
@ -260,7 +260,7 @@ unsafe fn unref(data: *const u8) {
} }
} }
unsafe fn handle_msg(data: *const u8, msg: &jay_config::_private::messages::ClientMessage<'_>) { unsafe fn handle_msg(data: *const u8, msg: &ClientMessage<'_>) {
unsafe { unsafe {
let server = (data as *const ConfigProxyHandler).deref(); let server = (data as *const ConfigProxyHandler).deref();
if server.dropped.get() { if server.dropped.get() {

View file

@ -41,10 +41,10 @@ use {
}, },
}, },
jay_config::{ jay_config::{
_private::{ protocol::{
ClientCriterionPayload, ClientCriterionStringField, GenericCriterionPayload, PollableId, ClientCriterionPayload, ClientCriterionStringField, ClientMessage, ConfigHandler,
ConfigHandler, Unref, WindowCriterionPayload, WindowCriterionStringField, WireMode, GenericCriterionPayload, PollableId, Response, ServerMessage, Unref,
messages::{ClientMessage, Response, ServerMessage, WorkspaceSource}, WindowCriterionPayload, WindowCriterionStringField, WireMode, WorkspaceSource,
}, },
Axis, Direction, Workspace, Axis, Direction, Workspace,
client::{Client as ConfigClient, ClientMatcher}, client::{Client as ConfigClient, ClientMatcher},

View file

@ -22,7 +22,6 @@ use {
}, },
ahash::AHashMap, ahash::AHashMap,
bincode::Options, bincode::Options,
jay_config::_private::bincode_ops,
log::Level, log::Level,
serde::{Deserialize, Serialize}, serde::{Deserialize, Serialize},
std::{ std::{
@ -38,6 +37,13 @@ use {
uapi::{Errno, Fd, IntoUstr, OwnedFd, UstrPtr, c}, uapi::{Errno, Fd, IntoUstr, OwnedFd, UstrPtr, c},
}; };
pub fn bincode_ops() -> impl Options {
bincode::DefaultOptions::new()
.with_fixint_encoding()
.with_little_endian()
.with_no_limit()
}
pub struct ForkerProxy { pub struct ForkerProxy {
pidfd: Rc<OwnedFd>, pidfd: Rc<OwnedFd>,
socket: Rc<OwnedFd>, socket: Rc<OwnedFd>,

View file

@ -6,7 +6,7 @@ use {
use { use {
crate::{ crate::{
forker::ForkerError, forker::{ForkerError, bincode_ops},
io_uring::IoUring, io_uring::IoUring,
utils::{ utils::{
buf::DynamicBuf, buf::DynamicBuf,
@ -14,7 +14,6 @@ use {
vec_ext::VecExt, vec_ext::VecExt,
}, },
}, },
jay_config::_private::bincode_ops,
uapi::OwnedFd, uapi::OwnedFd,
}; };

View file

@ -8,9 +8,9 @@ use {
}, },
isnt::std_1::primitive::IsntConstPtrExt, isnt::std_1::primitive::IsntConstPtrExt,
jay_config::{ jay_config::{
_private::{ protocol::{
ConfigEntry, VERSION, ClientMessage, ConfigEntry, InitMessage, Response, ServerHandler, ServerMessage, Unref,
messages::{ClientMessage, Response, ServerMessage}, VERSION,
}, },
Axis, Direction, Axis, Direction,
input::{InputDevice, Seat}, input::{InputDevice, Seat},
@ -54,9 +54,9 @@ where
unsafe fn init( unsafe fn init(
srv_data: *const u8, srv_data: *const u8,
srv_unref: jay_config::_private::Unref, srv_unref: Unref,
srv_handler: jay_config::_private::ServerHandler, srv_handler: ServerHandler,
_msg: jay_config::_private::messages::InitMessage, _msg: InitMessage,
) -> *const u8 { ) -> *const u8 {
let tc = CONFIG.get(); let tc = CONFIG.get();
assert!(tc.is_not_null()); assert!(tc.is_not_null());
@ -128,8 +128,8 @@ unsafe fn handle_msg(data: *const u8, msg: &ServerMessage) {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct ServerData { struct ServerData {
srv_data: *const u8, srv_data: *const u8,
srv_unref: jay_config::_private::Unref, srv_unref: Unref,
srv_handler: jay_config::_private::ServerHandler, srv_handler: ServerHandler,
} }
pub struct TestConfig { pub struct TestConfig {

View file

@ -6,7 +6,7 @@ use {
tasks::udev_utils::{UdevProps, udev_props}, tasks::udev_utils::{UdevProps, udev_props},
utils::{asyncevent::AsyncEvent, event_listener::EventListener}, utils::{asyncevent::AsyncEvent, event_listener::EventListener},
}, },
jay_config::_private::DEFAULT_SEAT_NAME, jay_config::protocol::DEFAULT_SEAT_NAME,
std::{ std::{
cell::Cell, cell::Cell,
rc::{Rc, Weak}, rc::{Rc, Weak},