Skip to content

Commit

Permalink
fix(CompositeDevice): remove double tracking of source devices to all…
Browse files Browse the repository at this point in the history
…ow stopping
  • Loading branch information
ShadowApex committed Mar 15, 2024
1 parent 215dc34 commit 628baec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions src/input/composite_device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ impl CompositeDevice {
// then start listening for inputs from that device.
SourceDevice::EventDevice(device) => {
let device_id = device.get_id();
self.source_devices_used.push(device_id.clone());
let tx = self.tx.clone();
self.source_device_tasks.spawn(async move {
if let Err(e) = device.run().await {
Expand All @@ -447,7 +446,6 @@ impl CompositeDevice {
// then start listening for inputs from that device.
SourceDevice::HIDRawDevice(device) => {
let device_id = device.get_id();
self.source_devices_used.push(device_id.clone());
let tx = self.tx.clone();
self.source_device_tasks.spawn(async move {
if let Err(e) = device.run().await {
Expand Down Expand Up @@ -828,11 +826,9 @@ impl CompositeDevice {
self.source_device_paths.remove(idx);
};

let Some(idx) = self.source_devices_used.iter().position(|str| str == &id) else {
return Ok(());
if let Some(idx) = self.source_devices_used.iter().position(|str| str == &id) {
self.source_devices_used.remove(idx);
};

self.source_devices_used.remove(idx);
}
if id.starts_with("hidraw://") {
let name = id.strip_prefix("hidraw://").unwrap();
Expand All @@ -842,13 +838,20 @@ impl CompositeDevice {
self.source_device_paths.remove(idx);
};

let Some(idx) = self.source_devices_used.iter().position(|str| str == &id) else {
return Ok(());
if let Some(idx) = self.source_devices_used.iter().position(|str| str == &id) {
self.source_devices_used.remove(idx);
};

self.source_devices_used.remove(idx);
}

log::debug!(
"Current source device paths: {:?}",
self.source_device_paths
);
log::debug!(
"Current source devices used: {:?}",
self.source_devices_used
);

Ok(())
}

Expand Down

0 comments on commit 628baec

Please sign in to comment.