Merge pull request #193 from mahkoh/jorth/input-init
metal: initialize initially paused input devices
This commit is contained in:
commit
14042282e1
2 changed files with 27 additions and 24 deletions
|
|
@ -343,6 +343,7 @@ struct MetalInputDevice {
|
||||||
state: Rc<State>,
|
state: Rc<State>,
|
||||||
slot: usize,
|
slot: usize,
|
||||||
id: InputDeviceId,
|
id: InputDeviceId,
|
||||||
|
fully_initialized: Cell<bool>,
|
||||||
devnum: c::dev_t,
|
devnum: c::dev_t,
|
||||||
fd: CloneCell<Option<Rc<OwnedFd>>>,
|
fd: CloneCell<Option<Rc<OwnedFd>>>,
|
||||||
inputdev: CloneCell<Option<Rc<RegisteredDevice>>>,
|
inputdev: CloneCell<Option<Rc<RegisteredDevice>>>,
|
||||||
|
|
|
||||||
|
|
@ -110,16 +110,10 @@ impl MetalBackend {
|
||||||
|
|
||||||
fn handle_input_device_resume(self: &Rc<Self>, dev: &Rc<MetalInputDevice>, fd: Rc<OwnedFd>) {
|
fn handle_input_device_resume(self: &Rc<Self>, dev: &Rc<MetalInputDevice>, fd: Rc<OwnedFd>) {
|
||||||
log::info!("Device resumed: {}", dev.devnode.to_bytes().as_bstr());
|
log::info!("Device resumed: {}", dev.devnode.to_bytes().as_bstr());
|
||||||
if let Some(old) = dev.fd.set(Some(fd)) {
|
if let Some(old) = dev.fd.take() {
|
||||||
self.state.fdcloser.close(old);
|
self.state.fdcloser.close(old);
|
||||||
}
|
}
|
||||||
let inputdev = match self.libinput.open(dev.devnode.as_c_str()) {
|
self.reinit_input_device(dev, &fd);
|
||||||
Ok(d) => Rc::new(d),
|
|
||||||
Err(_) => return,
|
|
||||||
};
|
|
||||||
inputdev.device().set_slot(dev.slot);
|
|
||||||
dev.inputdev.set(Some(inputdev));
|
|
||||||
dev.apply_config();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_device_removed(self: &Rc<Self>, dev: c::dev_t) {
|
fn handle_device_removed(self: &Rc<Self>, dev: c::dev_t) {
|
||||||
|
|
@ -309,6 +303,7 @@ impl MetalBackend {
|
||||||
state: self.state.clone(),
|
state: self.state.clone(),
|
||||||
slot,
|
slot,
|
||||||
id: device_id,
|
id: device_id,
|
||||||
|
fully_initialized: Cell::new(false),
|
||||||
devnum,
|
devnum,
|
||||||
fd: Default::default(),
|
fd: Default::default(),
|
||||||
inputdev: Default::default(),
|
inputdev: Default::default(),
|
||||||
|
|
@ -354,26 +349,33 @@ impl MetalBackend {
|
||||||
if res.inactive == TRUE {
|
if res.inactive == TRUE {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Err(e) = set_nonblock(res.fd.raw()) {
|
slf.reinit_input_device(&dev, &res.fd);
|
||||||
log::error!("Could set input fd to non-blocking: {}", ErrorFmt(e));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dev.fd.set(Some(res.fd.clone()));
|
|
||||||
let inputdev = match slf.libinput.open(dev.devnode.as_c_str()) {
|
|
||||||
Ok(d) => Rc::new(d),
|
|
||||||
Err(_) => return,
|
|
||||||
};
|
|
||||||
inputdev.device().set_slot(slot);
|
|
||||||
dev.name.set(Rc::new(inputdev.device().name()));
|
|
||||||
dev.inputdev.set(Some(inputdev));
|
|
||||||
dev.apply_config();
|
|
||||||
slf.state
|
|
||||||
.backend_events
|
|
||||||
.push(BackendEvent::NewInputDevice(dev.clone()));
|
|
||||||
});
|
});
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn reinit_input_device(&self, dev: &Rc<MetalInputDevice>, fd: &Rc<OwnedFd>) {
|
||||||
|
if let Err(e) = set_nonblock(fd.raw()) {
|
||||||
|
log::error!("Could set input fd to non-blocking: {}", ErrorFmt(e));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dev.fd.set(Some(fd.clone()));
|
||||||
|
let inputdev = match self.libinput.open(dev.devnode.as_c_str()) {
|
||||||
|
Ok(d) => Rc::new(d),
|
||||||
|
Err(_) => return,
|
||||||
|
};
|
||||||
|
inputdev.device().set_slot(dev.slot);
|
||||||
|
if !dev.fully_initialized.get() {
|
||||||
|
dev.name.set(Rc::new(inputdev.device().name()));
|
||||||
|
self.state
|
||||||
|
.backend_events
|
||||||
|
.push(BackendEvent::NewInputDevice(dev.clone()));
|
||||||
|
dev.fully_initialized.set(true);
|
||||||
|
}
|
||||||
|
dev.inputdev.set(Some(inputdev));
|
||||||
|
dev.apply_config();
|
||||||
|
}
|
||||||
|
|
||||||
fn get_device<F>(self: &Rc<Self>, dev: c::dev_t, f: F)
|
fn get_device<F>(self: &Rc<Self>, dev: c::dev_t, f: F)
|
||||||
where
|
where
|
||||||
F: FnOnce(Result<&TakeDeviceReply, DbusError>) + 'static,
|
F: FnOnce(Result<&TakeDeviceReply, DbusError>) + 'static,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue