1
0
Fork 0
forked from wry/wry

backend: add DevicesEnumerated event

This commit is contained in:
Julian Orth 2022-11-13 13:23:15 +01:00
parent dddd68ba06
commit c6c87bdaa1
11 changed files with 65 additions and 4 deletions

View file

@ -42,6 +42,7 @@ pub(crate) struct Client {
on_new_input_device: RefCell<Option<Rc<dyn Fn(InputDevice)>>>,
on_connector_connected: RefCell<Option<Rc<dyn Fn(Connector)>>>,
on_graphics_initialized: Cell<Option<Box<dyn FnOnce()>>>,
on_devices_enumerated: Cell<Option<Box<dyn FnOnce()>>>,
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)>>>,
@ -129,6 +130,7 @@ pub unsafe extern "C" fn init(
on_new_input_device: Default::default(),
on_connector_connected: Default::default(),
on_graphics_initialized: Default::default(),
on_devices_enumerated: Default::default(),
on_new_connector: Default::default(),
on_new_drm_device: Default::default(),
on_del_drm_device: Default::default(),
@ -550,6 +552,10 @@ impl Client {
self.on_graphics_initialized.set(Some(Box::new(f)));
}
pub fn on_devices_enumerated<F: FnOnce() + 'static>(&self, f: F) {
self.on_devices_enumerated.set(Some(Box::new(f)));
}
pub fn set_seat(&self, device: InputDevice, seat: Seat) {
self.send(&ClientMessage::SetSeat { device, seat })
}
@ -734,6 +740,11 @@ impl Client {
handler();
}
}
ServerMessage::DevicesEnumerated => {
if let Some(handler) = self.on_devices_enumerated.take() {
handler();
}
}
}
}

View file

@ -55,6 +55,7 @@ pub enum ServerMessage {
device: DrmDevice,
},
Idle,
DevicesEnumerated,
}
#[derive(Encode, BorrowDecode, Debug)]

View file

@ -139,3 +139,11 @@ impl Display for PciId {
pub fn on_idle<F: Fn() + 'static>(f: F) {
get!().on_idle(f)
}
/// Sets the callback to be called when all devices have been enumerated.
///
/// This callback is only invoked once during the lifetime of the compositor. This is a
/// good place to select the DRM device used for rendering.
pub fn on_devices_enumerated<F: FnOnce() + 'static>(f: F) {
get!().on_devices_enumerated(f)
}