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

Udev async #217

Merged
merged 7 commits into from
Jul 23, 2023
Merged

Udev async #217

merged 7 commits into from
Jul 23, 2023

Conversation

Shinyzenith
Copy link
Member

No description provided.

Instead of reading from the clap arguments, store the unwrapped device list into
a Vec (potentially empty). This is convenient to check if a given device
name is one of the names given by the user.

`keyboard_devices` has also been updated to use this new variable.
Support for listening asynchronously to udev DeviceRemoved/DeviceAdded events
with the `tokio-udev` crate.

For now, this only works with the latest commits on the tokio-udev repo.
This adds the libudev-dev package to the Build, Clippy and Test jobs.
@Shinyzenith Shinyzenith linked an issue Jul 20, 2023 that may be closed by this pull request
keyboard_stream_map and keyboard_states have to be kept in sync, but
beacause of states being a vector, it had different semantics during
removal. If 2 devices were added and the first was removed then the
vector shifts the second device to the front but the map obviously
did not, leading to the collections becoming out of sync. This cause
out-of-bounds errors on the states vector when accessing it using
stream_map's keys.

This patch changes keyboard_states to be a map as well, and both maps
are indexed using the udev input path as a key. A string key is not
ideal, but is close to being the only unique ID for a connected
device (physical path is not made serialised in many udev events for
reasons unknown.), besides being easily accessible from both disjoint
APIs being used here, evdev and tokio_udev.

An additional concern may be that tokio's StreamMap manages its own
members and removes streams upon completion, but:
a) We don't index into stream_map at all, only consume from it,
   so this will never be an issue
b) the corresponding entry in states will be removed as well upon
   the udev remove event
@Shinyzenith Shinyzenith merged commit 605c935 into main Jul 23, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

swhkd does not process hotkeys of newly connected devices
3 participants