Skip to content

Commit 05e68fc

Browse files
gvalkovGeorgi Valkov
authored andcommitted
Rework input props functionality
- Merged geniprops into genecodes and reverted the changes to setup.py. - Renamed InputDevice.props to InputDevice.input_props. - Renamed UInput(props=) to UInput(input_props=).
1 parent a4cf8b5 commit 05e68fc

File tree

9 files changed

+44
-199
lines changed

9 files changed

+44
-199
lines changed

docs/changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
---------
33

4+
Master
5+
====================
6+
7+
- Fix build on 32bit arches with 64bit time_t
8+
9+
- Add functionality to query device properties. See ``InputDevice.input_props``
10+
and the ``input_props`` argument to ``Uinput``.
11+
12+
413
1.2.0 (Apr 7, 2019)
514
====================
615

evdev/device.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,24 @@ def capabilities(self, verbose=False, absinfo=True):
223223
else:
224224
return self._capabilities(absinfo)
225225

226-
def props(self):
226+
def input_props(self, verbose=False):
227+
'''
228+
Get device properties and quirks.
229+
230+
Example
231+
-------
232+
>>> device.input_props()
233+
[0, 5]
234+
235+
If ``verbose`` is ``True``, input properties are resolved to their
236+
names. Unknown codes are resolved to ``'?'``::
237+
238+
[('INPUT_PROP_POINTER', 0), ('INPUT_PROP_POINTING_STICK', 5)]
239+
240+
'''
227241
props = _input.ioctl_EVIOCGPROP(self.fd)
242+
if verbose:
243+
return util.resolve_ecodes(ecodes.INPUT_PROP, props)
228244

229245
return props
230246

evdev/ecodes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Exposed constants::
88
99
KEY, ABS, REL, SW, MSC, LED, BTN, REP, SND, ID, EV,
10-
BUS, SYN, FF, FF_STATUS
10+
BUS, SYN, FF, FF_STATUS, INPUT_PROP
1111
1212
This module also provides reverse and forward mappings of the names and values
1313
of the above mentioned constants::
@@ -47,7 +47,7 @@
4747
#: Mapping of names to values.
4848
ecodes = {}
4949

50-
prefixes = 'KEY ABS REL SW MSC LED BTN REP SND ID EV BUS SYN FF_STATUS FF'
50+
prefixes = 'KEY ABS REL SW MSC LED BTN REP SND ID EV BUS SYN FF_STATUS FF INPUT_PROP'
5151
prev_prefix = ''
5252
g = globals()
5353

@@ -94,7 +94,8 @@
9494
_ecodes.EV_SND: SND,
9595
_ecodes.EV_SYN: SYN,
9696
_ecodes.EV_FF: FF,
97-
_ecodes.EV_FF_STATUS: FF_STATUS, }
97+
_ecodes.EV_FF_STATUS: FF_STATUS,
98+
}
9899

99100
from evdev._ecodes import *
100101

evdev/genecodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
#-----------------------------------------------------------------------------
23-
macro_regex = r'#define +((?:KEY|ABS|REL|SW|MSC|LED|BTN|REP|SND|ID|EV|BUS|SYN|FF|UI_FF)_\w+)'
23+
macro_regex = r'#define +((?:KEY|ABS|REL|SW|MSC|LED|BTN|REP|SND|ID|EV|BUS|SYN|FF|UI_FF|INPUT_PROP)_\w+)'
2424
macro_regex = re.compile(macro_regex)
2525

2626
uname = list(os.uname()); del uname[1]

evdev/geniprops.py

Lines changed: 0 additions & 116 deletions
This file was deleted.

evdev/input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,11 @@ static PyMethodDef MethodTable[] = {
491491
{ "ioctl_EVIOCGRAB", ioctl_EVIOCGRAB, METH_VARARGS},
492492
{ "ioctl_EVIOCGEFFECTS", ioctl_EVIOCGEFFECTS, METH_VARARGS, "fetch the number of effects the device can keep in its memory." },
493493
{ "ioctl_EVIOCG_bits", ioctl_EVIOCG_bits, METH_VARARGS, "get state of KEY|LED|SND|SW"},
494+
{ "ioctl_EVIOCGPROP", ioctl_EVIOCGPROP, METH_VARARGS, "get device properties"},
494495
{ "device_read", device_read, METH_VARARGS, "read an input event from a device" },
495496
{ "device_read_many", device_read_many, METH_VARARGS, "read all available input events from a device" },
496497
{ "upload_effect", upload_effect, METH_VARARGS, "" },
497498
{ "erase_effect", erase_effect, METH_VARARGS, "" },
498-
{ "ioctl_EVIOCGPROP", ioctl_EVIOCGPROP, METH_VARARGS, "get device properties"},
499499

500500
{ NULL, NULL, 0, NULL}
501501
};

evdev/uinput.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static PyMethodDef MethodTable[] = {
360360
"Set physical path"},
361361

362362
{ "set_prop", uinput_set_prop, METH_VARARGS,
363-
"Set device property"},
363+
"Set device input property"},
364364

365365
{ NULL, NULL, 0, NULL}
366366
};

evdev/uinput.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self,
7777
events=None,
7878
name='py-evdev-uinput',
7979
vendor=0x1, product=0x1, version=0x1, bustype=0x3,
80-
devnode='/dev/uinput', phys='py-evdev-uinput', props=[]):
80+
devnode='/dev/uinput', phys='py-evdev-uinput', input_props=None):
8181
'''
8282
Arguments
8383
---------
@@ -96,13 +96,16 @@ def __init__(self,
9696
Product identifier.
9797
9898
version
99-
version identifier.
99+
Version identifier.
100100
101101
bustype
102-
bustype identifier.
102+
Bustype identifier.
103103
104104
phys
105-
physical path.
105+
Physical path.
106+
107+
input_props
108+
Input properties and quirks.
106109
107110
Note
108111
----
@@ -133,7 +136,8 @@ def __init__(self,
133136
_uinput.set_phys(self.fd, phys)
134137

135138
# Set properties
136-
for prop in props:
139+
input_props = input_props or []
140+
for prop in input_props:
137141
_uinput.set_prop(self.fd, prop)
138142

139143
for etype, code in prepared_events:

setup.py

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
input_c = Extension('evdev._input', sources=['evdev/input.c'], extra_compile_args=cflags)
4141
uinput_c = Extension('evdev._uinput', sources=['evdev/uinput.c'], extra_compile_args=cflags)
4242
ecodes_c = Extension('evdev._ecodes', sources=['evdev/ecodes.c'], extra_compile_args=cflags)
43-
iprops_c = Extension('evdev.iprops', sources=['evdev/iprops.c'], extra_compile_args=cflags)
4443

4544
#-----------------------------------------------------------------------------
4645
kw = {
@@ -58,7 +57,7 @@
5857
'classifiers': classifiers,
5958

6059
'packages': ['evdev'],
61-
'ext_modules': [input_c, uinput_c, ecodes_c, iprops_c],
60+
'ext_modules': [input_c, uinput_c, ecodes_c],
6261
'include_package_data': False,
6362
'zip_safe': True,
6463
'cmdclass': {},
@@ -107,48 +106,6 @@ def create_ecodes(headers=None):
107106
check_call(cmd, cwd="%s/evdev" % here, shell=True)
108107

109108

110-
#-----------------------------------------------------------------------------
111-
def create_iprops(headers=None):
112-
if not headers:
113-
headers = [
114-
'/usr/include/linux/input.h',
115-
'/usr/include/linux/input-event-codes.h',
116-
'/usr/include/linux/uinput.h',
117-
]
118-
119-
headers = [header for header in headers if os.path.isfile(header)]
120-
if not headers:
121-
msg = '''\
122-
The 'linux/input.h' and 'linux/input-event-codes.h' include files
123-
are missing. You will have to install the kernel header files in
124-
order to continue:
125-
126-
yum install kernel-headers-$(uname -r)
127-
apt-get install linux-headers-$(uname -r)
128-
emerge sys-kernel/linux-headers
129-
pacman -S kernel-headers
130-
131-
In case they are installed in a non-standard location, you may use
132-
the '--evdev-headers' option to specify one or more colon-separated
133-
paths. For example:
134-
135-
python setup.py \\
136-
build \\
137-
build_iprops --evdev-headers path/input.h:path/input-event-codes.h \\
138-
build_ext --include-dirs path/ \\
139-
install
140-
'''
141-
142-
sys.stderr.write(textwrap.dedent(msg))
143-
sys.exit(1)
144-
145-
from subprocess import check_call
146-
147-
print('writing iprops.c (using %s)' % ' '.join(headers))
148-
cmd = '%s geniprops.py %s > iprops.c' % (sys.executable, ' '.join(headers))
149-
check_call(cmd, cwd="%s/evdev" % here, shell=True)
150-
151-
152109
#-----------------------------------------------------------------------------
153110
class build_ecodes(Command):
154111
description = 'generate ecodes.c'
@@ -168,24 +125,6 @@ def run(self):
168125
create_ecodes(self.evdev_headers)
169126

170127

171-
class build_iprops(Command):
172-
description = 'generate iprops.c'
173-
174-
user_options = [
175-
('evdev-headers=', None, 'colon-separated paths to input subsystem headers'),
176-
]
177-
178-
def initialize_options(self):
179-
self.evdev_headers = None
180-
181-
def finalize_options(self):
182-
if self.evdev_headers:
183-
self.evdev_headers = self.evdev_headers.split(':')
184-
185-
def run(self):
186-
create_iprops(self.evdev_headers)
187-
188-
189128
class build_ext(_build_ext.build_ext):
190129
def has_ecodes(self):
191130
ecodes_path = os.path.join(here, 'evdev/ecodes.c')
@@ -194,25 +133,17 @@ def has_ecodes(self):
194133
print('ecodes.c already exists ... skipping build_ecodes')
195134
return not res
196135

197-
def has_iprops(self):
198-
iprops_path = os.path.join(here, 'evdev/iprops.c')
199-
res = os.path.exists(iprops_path)
200-
if res:
201-
print('iprops.c already exists ... skipping build_iprops')
202-
return not res
203-
204136
def run(self):
205137
for cmd_name in self.get_sub_commands():
206138
self.run_command(cmd_name)
207139
_build_ext.build_ext.run(self)
208140

209-
sub_commands = [('build_ecodes', has_ecodes), ('build_iprops', has_iprops)] + _build_ext.build_ext.sub_commands
141+
sub_commands = [('build_ecodes', has_ecodes)] + _build_ext.build_ext.sub_commands
210142

211143

212144
#-----------------------------------------------------------------------------
213145
kw['cmdclass']['build_ext'] = build_ext
214146
kw['cmdclass']['build_ecodes'] = build_ecodes
215-
kw['cmdclass']['build_iprops'] = build_iprops
216147

217148

218149
#-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)