Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metal: initialize initially paused input devices #193

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/backends/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ struct MetalInputDevice {
state: Rc<State>,
slot: usize,
id: InputDeviceId,
fully_initialized: Cell<bool>,
devnum: c::dev_t,
fd: CloneCell<Option<Rc<OwnedFd>>>,
inputdev: CloneCell<Option<Rc<RegisteredDevice>>>,
Expand Down
48 changes: 25 additions & 23 deletions src/backends/metal/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,10 @@ impl MetalBackend {

fn handle_input_device_resume(self: &Rc<Self>, dev: &Rc<MetalInputDevice>, fd: Rc<OwnedFd>) {
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);
}
let inputdev = match self.libinput.open(dev.devnode.as_c_str()) {
Ok(d) => Rc::new(d),
Err(_) => return,
};
inputdev.device().set_slot(dev.slot);
dev.inputdev.set(Some(inputdev));
dev.apply_config();
self.reinit_input_device(dev, &fd);
}

fn handle_device_removed(self: &Rc<Self>, dev: c::dev_t) {
Expand Down Expand Up @@ -309,6 +303,7 @@ impl MetalBackend {
state: self.state.clone(),
slot,
id: device_id,
fully_initialized: Cell::new(false),
devnum,
fd: Default::default(),
inputdev: Default::default(),
Expand Down Expand Up @@ -354,24 +349,31 @@ impl MetalBackend {
if res.inactive == TRUE {
return;
}
if let Err(e) = set_nonblock(res.fd.raw()) {
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);
slf.reinit_input_device(&dev, &res.fd);
});
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()));
dev.inputdev.set(Some(inputdev));
dev.apply_config();
slf.state
self.state
.backend_events
.push(BackendEvent::NewInputDevice(dev.clone()));
});
None
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)
Expand Down
Loading