config: add on_idle
This commit is contained in:
parent
ce567b9999
commit
0e5b1b5e35
5 changed files with 25 additions and 0 deletions
|
|
@ -45,6 +45,7 @@ pub(crate) struct Client {
|
|||
on_new_connector: RefCell<Option<Rc<dyn Fn(Connector)>>>,
|
||||
on_new_drm_device: RefCell<Option<Rc<dyn Fn(DrmDevice)>>>,
|
||||
on_del_drm_device: RefCell<Option<Rc<dyn Fn(DrmDevice)>>>,
|
||||
on_idle: RefCell<Option<Rc<dyn Fn()>>>,
|
||||
bufs: RefCell<Vec<Vec<u8>>>,
|
||||
reload: Cell<bool>,
|
||||
}
|
||||
|
|
@ -131,6 +132,7 @@ pub unsafe extern "C" fn init(
|
|||
on_new_connector: Default::default(),
|
||||
on_new_drm_device: Default::default(),
|
||||
on_del_drm_device: Default::default(),
|
||||
on_idle: Default::default(),
|
||||
bufs: Default::default(),
|
||||
reload: Cell::new(false),
|
||||
});
|
||||
|
|
@ -532,6 +534,10 @@ impl Client {
|
|||
*self.on_new_connector.borrow_mut() = Some(Rc::new(f));
|
||||
}
|
||||
|
||||
pub fn on_idle<F: Fn() + 'static>(&self, f: F) {
|
||||
*self.on_idle.borrow_mut() = Some(Rc::new(f));
|
||||
}
|
||||
|
||||
pub fn on_connector_connected<F: Fn(Connector) + 'static>(&self, f: F) {
|
||||
*self.on_connector_connected.borrow_mut() = Some(Rc::new(f));
|
||||
}
|
||||
|
|
@ -718,6 +724,12 @@ impl Client {
|
|||
handler(device);
|
||||
}
|
||||
}
|
||||
ServerMessage::Idle => {
|
||||
let handler = self.on_idle.borrow_mut();
|
||||
if let Some(handler) = handler.deref() {
|
||||
handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ pub enum ServerMessage {
|
|||
DelDrmDev {
|
||||
device: DrmDevice,
|
||||
},
|
||||
Idle,
|
||||
}
|
||||
|
||||
#[derive(Encode, BorrowDecode, Debug)]
|
||||
|
|
|
|||
|
|
@ -132,3 +132,8 @@ impl Display for PciId {
|
|||
write!(f, "{:04x}:{:04x}", self.vendor, self.model)
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the callback to be called when the display goes idle.
|
||||
pub fn on_idle<F: Fn() + 'static>(f: F) {
|
||||
get!().on_idle(f)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue