1
0
Fork 0
forked from wry/wry

config: remove bincode command bridge

This commit is contained in:
kossLAN 2026-05-29 18:05:41 -04:00
parent d8920ed7a0
commit 87de5fcca3
No known key found for this signature in database
6 changed files with 64 additions and 119 deletions

View file

@ -16,18 +16,20 @@ use {
pub const VERSION: u32 = 1;
#[repr(C)]
pub type ServerHandler = unsafe fn(data: *const u8, msg: &ipc::ClientMessage<'_>);
pub type ConfigHandler = unsafe fn(data: *const u8, msg: &ipc::ServerMessage);
pub type Unref = unsafe fn(data: *const u8);
pub struct ConfigEntry {
pub version: u32,
pub init: unsafe extern "C" fn(
pub init: unsafe fn(
srv_data: *const u8,
srv_unref: unsafe extern "C" fn(data: *const u8),
srv_handler: unsafe extern "C" fn(data: *const u8, msg: *const u8, size: usize),
msg: *const u8,
size: usize,
srv_unref: Unref,
srv_handler: ServerHandler,
msg: ipc::InitMessage,
) -> *const u8,
pub unref: unsafe extern "C" fn(data: *const u8),
pub handle_msg: unsafe extern "C" fn(data: *const u8, msg: *const u8, size: usize),
pub unref: Unref,
pub handle_msg: ConfigHandler,
}
pub fn bincode_ops() -> impl Options {
@ -37,7 +39,7 @@ pub fn bincode_ops() -> impl Options {
.with_no_limit()
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct WireMode {
pub width: i32,
pub height: i32,

View file

@ -4,7 +4,7 @@ use {
crate::{
_private::{
ClientCriterionIpc, ClientCriterionStringField, GenericCriterionIpc, PollableId,
WindowCriterionIpc, WindowCriterionStringField, WireMode, bincode_ops,
ServerHandler, Unref, WindowCriterionIpc, WindowCriterionStringField, WireMode,
ipc::{
ClientMessage, InitMessage, Response, ServerFeature, ServerMessage, WorkspaceSource,
},
@ -38,7 +38,6 @@ use {
workspace::WorkspaceDisplayOrder,
xwayland::XScalingMode,
},
bincode::Options,
futures_util::task::ArcWake,
run_on_drop::{OnDrop, on_drop},
std::{
@ -52,7 +51,6 @@ use {
pin::Pin,
ptr,
rc::Rc,
slice,
sync::{
Arc, Mutex,
atomic::{AtomicBool, Ordering::Relaxed},
@ -89,10 +87,10 @@ struct KeyHandler {
}
pub(crate) struct ConfigClient {
configure: extern "C" fn(),
configure: fn(),
srv_data: *const u8,
srv_unref: unsafe extern "C" fn(data: *const u8),
srv_handler: unsafe extern "C" fn(data: *const u8, msg: *const u8, size: usize),
srv_unref: Unref,
srv_handler: ServerHandler,
key_handlers: RefCell<HashMap<(Seat, ModifiedKeySym), KeyHandler>>,
timer_handlers: RefCell<HashMap<Timer, Callback>>,
response: RefCell<Vec<Response>>,
@ -109,7 +107,6 @@ pub(crate) struct ConfigClient {
on_idle: RefCell<Option<Callback>>,
on_switch_event: RefCell<HashMap<InputDevice, Callback<SwitchEvent>>>,
on_unload: Cell<Option<OnDrop<Box<dyn FnOnce()>>>>,
bufs: RefCell<Vec<Vec<u8>>>,
reload: Cell<bool>,
read_interests: RefCell<HashMap<PollableId, Interest>>,
write_interests: RefCell<HashMap<PollableId, Interest>>,
@ -197,13 +194,12 @@ unsafe fn with_client<T, F: FnOnce(&ConfigClient) -> T>(data: *const u8, f: F) -
})
}
pub unsafe extern "C" fn init(
pub unsafe fn init(
srv_data: *const u8,
srv_unref: unsafe extern "C" fn(data: *const u8),
srv_handler: unsafe extern "C" fn(data: *const u8, msg: *const u8, size: usize),
init: *const u8,
size: usize,
f: extern "C" fn(),
srv_unref: Unref,
srv_handler: ServerHandler,
init: InitMessage,
f: fn(),
) -> *const u8 {
let client = Rc::new(ConfigClient {
configure: f,
@ -226,7 +222,6 @@ pub unsafe extern "C" fn init(
on_idle: Default::default(),
on_switch_event: Default::default(),
on_unload: Default::default(),
bufs: Default::default(),
reload: Cell::new(false),
read_interests: Default::default(),
write_interests: Default::default(),
@ -239,22 +234,20 @@ pub unsafe extern "C" fn init(
feat_mod_mask: Cell::new(false),
feat_show_workspace_on: Cell::new(false),
});
let init = unsafe { slice::from_raw_parts(init, size) };
client.handle_init_msg(init);
Rc::into_raw(client) as *const u8
}
pub unsafe extern "C" fn unref(data: *const u8) {
pub unsafe fn unref(data: *const u8) {
let client = data as *const ConfigClient;
unsafe {
drop(Rc::from_raw(client));
}
}
pub unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
pub unsafe fn handle_msg(data: *const u8, msg: &ServerMessage) {
unsafe {
with_client(data, |client| {
let msg = slice::from_raw_parts(msg, size);
client.handle_msg(msg);
});
}
@ -284,13 +277,9 @@ enum GenericCriterion<'a, Crit, Matcher> {
impl ConfigClient {
fn send(&self, msg: &ClientMessage) {
let mut buf = self.bufs.borrow_mut().pop().unwrap_or_default();
buf.clear();
bincode_ops().serialize_into(&mut buf, msg).unwrap();
unsafe {
(self.srv_handler)(self.srv_data, buf.as_ptr(), buf.len());
(self.srv_handler)(self.srv_data, msg);
}
self.bufs.borrow_mut().push(buf);
}
fn send_with_response(&self, msg: &ClientMessage) -> Response {
@ -1609,6 +1598,7 @@ impl ConfigClient {
}
}
#[allow(dead_code)]
pub fn log(&self, level: LogLevel, msg: &str, file: Option<&str>, line: Option<u32>) {
self.send(&ClientMessage::Log {
level,
@ -2032,7 +2022,7 @@ impl ConfigClient {
self.send(&ClientMessage::SeatMoveTab { seat, right });
}
fn handle_msg(&self, msg: &[u8]) {
fn handle_msg(&self, msg: &ServerMessage) {
self.handle_msg2(msg);
self.dispatch_futures();
}
@ -2163,16 +2153,8 @@ impl ConfigClient {
}
}
fn handle_msg2(&self, msg: &[u8]) {
let res = bincode_ops().deserialize::<ServerMessage>(msg);
let msg = match res {
Ok(msg) => msg,
Err(e) => {
let msg = format!("could not deserialize message: {}", e);
self.log(LogLevel::Error, &msg, None, None);
return;
}
};
fn handle_msg2(&self, msg: &ServerMessage) {
let msg = msg.clone();
match msg {
ServerMessage::Configure { reload } => {
self.reload.set(reload);
@ -2347,15 +2329,7 @@ impl ConfigClient {
}
}
fn handle_init_msg(&self, msg: &[u8]) {
let init = match bincode_ops().deserialize::<InitMessage>(msg) {
Ok(m) => m,
Err(e) => {
let msg = format!("could not deserialize message: {}", e);
self.log(LogLevel::Error, &msg, None, None);
return;
}
};
fn handle_init_msg(&self, init: InitMessage) {
match init {
InitMessage::V1(_) => {}
}

View file

@ -24,7 +24,7 @@ use {
std::time::{Duration, SystemTime},
};
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq)]
#[serde(transparent)]
pub struct ServerFeature(u16);
@ -34,7 +34,7 @@ impl ServerFeature {
pub const SHOW_WORKSPACE_ON: Self = Self(2);
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum ServerMessage {
Configure {
reload: bool,
@ -115,7 +115,7 @@ pub enum ServerMessage {
},
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum ClientMessage<'a> {
Reload,
Quit,
@ -922,13 +922,13 @@ pub enum ClientMessage<'a> {
},
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum WorkspaceSource {
Seat(Seat),
Explicit(Workspace),
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum Response {
None,
GetSeats {
@ -1178,10 +1178,10 @@ pub enum Response {
},
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum InitMessage {
V1(V1InitMessage),
}
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct V1InitMessage {}