Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Make get_event nonblocking #3

Open
whot opened this issue Feb 16, 2018 · 5 comments
Open

Make get_event nonblocking #3

whot opened this issue Feb 16, 2018 · 5 comments

Comments

@whot
Copy link

whot commented Feb 16, 2018

Note, I'm going by the documentation here, not by the code.

I'm surprised that you opted to block on get_event - that seems not ideal for anything but the most basic tools that just need to pull events off and process them. libinput is primarily designed to be integrated into compositors with their own event loops, making this nonblocking would be an important feature here.

@whot whot changed the title Make get_events nonblocking Make get_event nonblocking Feb 16, 2018
@OzymandiasTheGreat
Copy link
Owner

I combined file descriptor watching and event retrieval into a single method, therefor get_event blocks when select would block.
Honestly, I didn't see a need to expose file descriptor through python. In case blocking is undesired, there's a timeout parameter, same as select.
Of course there may be use cases I haven't considered, where this approach is sub-optimal. If you can illustrate such a use case for me, I'll make the changes.
I do doubt anybody wants to write a compositor in python, altho that's not a reason not to support this 😀

@whot
Copy link
Author

whot commented Feb 16, 2018

yeah, I think the compositor in python is a bit of a niche use-case :) but you can imagine e.g. games that need direct access to the devices and have their own event loops.

afaict the only way to check if there are events is to call get_event - but that may block. And the timeout is in seconds, so the minimum block time is 1s, that's way too long.

@OzymandiasTheGreat
Copy link
Owner

Ok, now I get this.
I'll make get_event non-blocking, guess I'll have to expose file descriptor as well.
As for the timeout, there's an error in the documentation, it's supposed to be a float, as in fractional seconds.

@whot
Copy link
Author

whot commented Feb 18, 2018

there is libinput_next_event_type() that returns LIBINPUT_EVENT_NONE if no event is waiting. That at least gets rid of the blocking issue, but without the fd you'd still have to resort to polling which isn't ideal.

On that note: if you don't have libinput_next_event_type() exposed in python, then you don't need the NONE event type, nothing else uses it.

@OzymandiasTheGreat
Copy link
Owner

Oh I completely forgot about that function. This would require far less modification to existing code, I think I'll just implement next_event_type.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants