sync last commit before release

This commit is contained in:
shenjack 2023-06-22 20:13:59 +08:00
parent c55eaffa5d
commit 1b29360701

View File

@ -4,6 +4,7 @@ import fcntl
import ctypes import ctypes
import warnings import warnings
from os import readv
from ctypes import c_uint16 as _u16 from ctypes import c_uint16 as _u16
from ctypes import c_int16 as _s16 from ctypes import c_int16 as _s16
from ctypes import c_uint32 as _u32 from ctypes import c_uint32 as _u32
@ -306,7 +307,6 @@ class EvdevDevice(XlibSelectDevice, Device):
self._filename = filename self._filename = filename
fileno = os.open(filename, os.O_RDONLY) fileno = os.open(filename, os.O_RDONLY)
# event_version = EVIOCGVERSION(fileno).value
self._id = EVIOCGID(fileno) self._id = EVIOCGID(fileno)
self.id_bustype = self._id.bustype self.id_bustype = self._id.bustype
@ -357,6 +357,9 @@ class EvdevDevice(XlibSelectDevice, Device):
self.controls.sort(key=lambda c: c._event_code) self.controls.sort(key=lambda c: c._event_code)
os.close(fileno) os.close(fileno)
self._event_size = ctypes.sizeof(InputEvent)
self._event_buffer = (InputEvent * 64)()
super().__init__(display, name) super().__init__(display, name)
def get_guid(self): def get_guid(self):
@ -405,17 +408,16 @@ class EvdevDevice(XlibSelectDevice, Device):
return return
try: try:
events = (InputEvent * 64)() bytes_read = readv(self._fileno, self._event_buffer)
bytes_read = os.readv(self._fileno, events)
except OSError: except OSError:
self.close() self.close()
return return
n_events = bytes_read // ctypes.sizeof(InputEvent) n_events = bytes_read // self._event_size
for event in events[:n_events]:
for event in self._event_buffer[:n_events]:
try: try:
control = self.control_map[(event.type, event.code)] self.control_map[(event.type, event.code)].value = event.value
control.value = event.value
except KeyError: except KeyError:
pass pass
@ -651,5 +653,4 @@ def _create_controller(device):
def get_controllers(display=None): def get_controllers(display=None):
return [controller for controller in return [controller for controller in
[_create_controller(device) for device in get_devices(display)] [_create_controller(device) for device in get_devices(display)] if controller]
if controller is not None]