Skip to content

Commit 9723ea1

Browse files
authored
Read consistency changes
Fixes at read_loop_blockless: .Changed "previous" variable name and its references to "previous_event", for consistency's sake. .Fixed typo and function name at second docstring and merged it with the first docstring. .Took down assignment at 'if current_event == None' clause. It now only returns previous_event. .Made previous_event update assignment clearer at main loop. Again, thanks to sezanzeb for pointing out some of the things that made me do these changes.
1 parent b940a65 commit 9723ea1

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

evdev/eventio.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,20 @@ def read_loop(self):
4949
def read_loop_blockless(self, timeout=0.001):
5050
'''
5151
Enter a blockless :func:`select.select()` loop that yields input events endlessly.
52+
53+
It is different from its blocking counterpart because it does not stop the execution when the device is
54+
idle, instead it replicates the previous event until another one happens. This is made possible by
55+
making use of a custom :func: 'read_one_blockless()' function that doesn't raise 'BlockingIOError' if there
56+
are no available events at the moment.
5257
'''
5358

54-
# previous -> InputEvent.sec, InputEvent.usec, InputEvent.type, InputEvent.code, InputEvent.val
55-
previous = InputEvent(sec=0, usec=0, type=0, code=0, value=0)
59+
# previous_event -> InputEvent.sec, InputEvent.usec, InputEvent.type, InputEvent.code, InputEvent.val
60+
previous_event = InputEvent(sec=0, usec=0, type=0, code=0, value=0)
5661

5762
# flag for 0 / SynEvent type value
5863
syn_event = 0
59-
60-
'''
61-
It is different from it's blocking counterpart because it does not stop the execution when the device is
62-
idle, instead it replicates the previous event until another one happens. This is made possible by
63-
making use of a custom :func: 'read_blockless()' function that doesn't raise 'BlockingIOError' if there
64-
are no available events at the moment.
65-
'''
66-
67-
def read_one_blockless(previous):
64+
65+
def read_one_blockless(previous_event):
6866
'''
6967
Read and yield a single input event as an instance of :class:`InputEvent <evdev.events.InputEvent>`.
7068
@@ -76,14 +74,13 @@ def read_one_blockless(previous):
7674
current_event = _input.device_read(self.fd)
7775

7876
if current_event == None:
79-
current_event = InputEvent(previous.sec, previous.usec, previous.type, previous.code, previous.value)
80-
return current_event
77+
return previous_event
8178

8279
# transforming result of device_read into an InputEvent
8380
current_event = InputEvent(*current_event)
8481

8582
if current_event.type == syn_event:
86-
current_event = InputEvent(current_event.sec, current_event.usec, previous.type, previous.code, previous.value)
83+
current_event = InputEvent(current_event.sec, current_event.usec, previous_event.type, previous_event.code, previous_event.value)
8784
return current_event
8885

8986
# returns current_event as InputEvent containing new data if none of the above applies
@@ -94,11 +91,11 @@ def read_one_blockless(previous):
9491
select.select([self.fd], [], [], timeout)
9592

9693
# event -> InputEvent.sec, InputEvent.usec, InputEvent.type, InputEvent.code, InputEvent.value
97-
event = read_one_blockless(previous)
94+
current_event = read_one_blockless(previous_event)
9895

9996
# updating previous event with current event data
100-
previous.sec, previous.usec, previous.type, previous.code, previous.value = event.sec, event.usec, event.type, event.code, event.value
101-
yield event
97+
previous_event = current_event
98+
yield current_event
10299

103100
def read_one(self):
104101
'''

0 commit comments

Comments
 (0)