1
0
Fork 0
forked from wry/wry

config: implement config reloading

This commit is contained in:
Julian Orth 2022-05-02 16:20:25 +02:00
parent aa19aab915
commit 7b40b42990
14 changed files with 188 additions and 50 deletions

View file

@ -41,6 +41,7 @@ pub(crate) struct Client {
on_graphics_initialized: Cell<Option<Box<dyn FnOnce()>>>,
on_new_connector: RefCell<Option<Rc<dyn Fn(Connector)>>>,
bufs: RefCell<Vec<Vec<u8>>>,
reload: Cell<bool>,
}
impl Drop for Client {
@ -124,6 +125,7 @@ pub unsafe extern "C" fn init(
on_graphics_initialized: Default::default(),
on_new_connector: Default::default(),
bufs: Default::default(),
reload: Cell::new(false),
});
let init = slice::from_raw_parts(init, size);
client.handle_init_msg(init);
@ -169,6 +171,14 @@ impl Client {
self.with_response(|| self.send(msg))
}
pub fn reload(&self) {
self.send(&ClientMessage::Reload);
}
pub fn is_reload(&self) -> bool {
self.reload.get()
}
pub fn spawn(&self, command: &Command) {
let env = command
.env
@ -358,9 +368,9 @@ impl Client {
self.send(&ClientMessage::FocusParent { seat });
}
pub fn create_seat(&self, name: &str) -> Seat {
let res = self.send_with_response(&ClientMessage::CreateSeat { name });
get_response!(res, Seat(0), CreateSeat, seat);
pub fn get_seat(&self, name: &str) -> Seat {
let res = self.send_with_response(&ClientMessage::GetSeat { name });
get_response!(res, Seat(0), GetSeat, seat);
seat
}
@ -531,8 +541,10 @@ impl Client {
}
};
match msg {
ServerMessage::Configure => {
ServerMessage::Configure { reload } => {
self.reload.set(reload);
(self.configure)();
self.reload.set(false);
}
ServerMessage::Response { response } => {
self.response.borrow_mut().push(response);

View file

@ -12,7 +12,9 @@ use {
#[derive(Encode, BorrowDecode, Debug)]
pub enum ServerMessage {
Configure,
Configure {
reload: bool,
},
GraphicsInitialized,
Response {
response: Response,
@ -53,7 +55,7 @@ pub enum ClientMessage<'a> {
file: Option<&'a str>,
line: Option<u32>,
},
CreateSeat {
GetSeat {
name: &'a str,
},
Quit,
@ -237,6 +239,7 @@ pub enum ClientMessage<'a> {
GetFullscreen {
seat: Seat,
},
Reload,
}
#[derive(Encode, Decode, Debug)]
@ -258,7 +261,7 @@ pub enum Response {
ParseKeymap {
keymap: Keymap,
},
CreateSeat {
GetSeat {
seat: Seat,
},
GetInputDevices {

View file

@ -4,7 +4,7 @@ use {
};
pub fn init() {
log::set_logger(&Logger).unwrap();
let _ = log::set_logger(&Logger);
log::set_max_level(LevelFilter::Trace);
}

View file

@ -161,9 +161,9 @@ pub fn input_devices() -> Vec<InputDevice> {
pub fn remove_all_seats() {}
pub fn create_seat(name: &str) -> Seat {
pub fn get_seat(name: &str) -> Seat {
let mut res = Seat(0);
(|| res = get!().create_seat(name))();
(|| res = get!().get_seat(name))();
res
}

View file

@ -121,3 +121,11 @@ impl Timer {
get!().on_timer_tick(self, f);
}
}
pub fn reload() {
get!().reload()
}
pub fn is_reload() -> bool {
get!(false).is_reload()
}