ardaku / stick

Rust library for platform-agnostic asynchronous gamepad, joystick, and flightstick interaction
https://crates.io/crates/stick
Apache License 2.0
76 stars 14 forks source link

Listener returns hot-plugged devices twice #69

Open henryso opened 1 year ago

henryso commented 1 year ago

I am running under Linux, and if I plug in a controller while my program is running, Listener returns the Controller twice. If the controller is plugged in before the program starts, I only get the Controller once. There appears to be nothing in the structure returned that will allow me to de-duplicate the Controller instances. Both of them fire the same events, and I only have one such controller plugged in so, both structures represent the same exact device.

I am using stick 0.13.0 with pasts 0.14.3.

AldaronLau commented 1 year ago

@henryso Thanks for opening an issue! I haven't yet tried with that combination of versions. If possible, an example would be useful (and if you wanted to make a PR, less work for me on #66 :smile:). One thing that would be useful to verify as well is whether this also happens with the current examples in the stick repo (on the old pasts version). What Linux distribution are you on?

henryso commented 1 year ago

@AldaronLau Yes, it behaves the same with the example at https://docs.rs/stick/0.13.0/stick/index.html, only using stick 0.13 instead of 0.12. I am using Gentoo Linux, kernel version 6.1.19 (a little old, yes). I don't have a fix, so I can't offer a PR, at least not yet. I'm currently working around it by ignoring any duplicate controllers (with the same id()) received within 50ms.

AldaronLau commented 1 year ago

@henryso Sorry, I should have been clearer. I meant a PR for the example using a newer pasts version (as I don't think it would trivial with the current stick version - but, eventually, I'll change the API to make it easier). I'll look into the bug when I can.

henryso commented 1 year ago

Because of the way pasts 0.14.3 works, I had to implement a custom Notify for my collection of Controller which returns an extended event with some way of identifying the Controller along with the Event. Additionally, I had to add some extra code which removes the Controller from the collection when Event::Disconnect is returned or that Controller will essentially return Event::Disconnect forever. As this adds a lot of baggage to the code, I don't think it's great for a short-form example.