swhkd: `swhkd` does not process hotkeys of newly connected devices
Version Information:
- Linux arch-dktp-alexis 5.19.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 31 Aug 2022 22:09:40 +0000 x86_64 GNU/Linux
- swhkd 1.2.1 (installed from the
swhkd-gitAUR package)
Describe the bug:
swhkd does not register hotkeys from a newly connected keyboard (or disconnected then reconnected).
Expected behavior:
swhkd should be able to register hotkeys on a newly connected keyboard.
Actual behavior:
swhkd does not grab newly connected devices and thus cannot handle their keypresses events.
To Reproduce:
Start swhkd. Connect a keyboard (or disconnect yours before reconnecting it). Hotkeys will not work.
Additional information:
This can probably be solved using udev, with either the udev crate or tokio-udev crate.
My attempts at implementing this (the same content is also in the [wip] commits of each branch):
- Using the
tokio-udevcrate (udev_asyncbranch):This does not work as-is. Unfortunately, sometimes udev events get ‘stuck’ and only processed after another batch of events comes in. In practice, this translates to e.g. a batch of ‘Add’ events (after connecting a device) only passed to the application loop after a batch of ‘Remove’ events (after disconnecting the same device for instance).
- Using the
udevcrate iterators wrapped in a tokio stream (udev_syncbranch):This does not work as-is, as the
MonitorSocketIteratormay returnNonewhen no udev events are available. tokio stops listening after the firstNonereceived from the stream, which means that events are not listened to at all. - Using the
udevcrate with a busy loop (udev_sync_busybranch):At the cost of an always busy thread, this does receive all udev events in a timely manner.
The busy loop is the only one which is working, but also the worst performance-wise. See this one more as a proof of concept.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 42 (27 by maintainers)
I have no need for a bounty; I’m happy for @jeandudey to pick it up as thanks for maintaining tokio-udev or for the funding to be re-used for another issue that seems worthwhile.
Sadly I was warned about BountySource before but there isn’t that many sites that offer bounties with escrow. Rysolv is one that I have used before. I was debating switching to it but decided against it which was my mistake I guess.
I’m really sorry about this @ConcurrentCrab. Please send me a DM with your PayPal email on Matrix (@cluelesstechnologist:matrix.org) or email me. (email in my GitHub profile)
Another option is to enable Github Sponsors on your profile.
To be completely fair, alexis created the initial fix, just in a branch. I opened the PR. I obviously don’t want any part of the bounty, I’m just stating the facts. The next PR fixing the index out of bounds issue was from ConcurrentCrab.
@Shinyzenith I released the fixes for tokio-udev but who fixed it was @sjoerdsimons, so I don’t actually deserve any bounty but him
Sure. Just tested the latest commit from udev branch. Happy to report that it’s still working:
I have merged the pr sent by @ConcurrentCrab. Just to be sure @CluelessTechnologist would you mind testing the latest HEAD of udev branch once more? If all is good to go, I’ll merge.
Nice, seems to be working now. Great job!
I have time this weekend to work on the udev problem! I’ll go ahead and start on a patch asap. PS: Cleared up some unnecessary messages.