optimize UInput.can_emit()

pull/595/head
Jonas Bosse 1 year ago
parent caa8f2c57b
commit d5e74d05e0
No known key found for this signature in database
GPG Key ID: E77C7242D9D3EE18

@ -65,12 +65,16 @@ class UInput(evdev.UInput):
logger.debug('creating UInput device: "%s"', name)
super().__init__(*args, **kwargs)
# this will never change, so we cache it since evdev runs an expensive loop to
# gather the capabilities. (can_emit is called regularly)
self._capabilities_cache = self.capabilities(absinfo=False)
def can_emit(self, event: Tuple[int, int, int]):
"""Check if an event can be emitted by the UIinput.
Wrong events might be injected if the group mappings are wrong,
"""
return event[1] in self.capabilities(absinfo=False).get(event[0], [])
return event[1] in self._capabilities_cache.get(event[0], [])
class FrontendUInput:

Loading…
Cancel
Save