Skip to content

Commit 3450482

Browse files
committed
include certain constants from uinput.h
1 parent f455e2d commit 3450482

3 files changed

Lines changed: 39 additions & 22 deletions

File tree

evdev/ecodes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# encoding: utf-8
22

33
'''
4-
This modules exposes the integer constants defined in ``linux/input.h``.
4+
This modules exposes integer constants defined in ``linux/input.h``
5+
and ``linux/uinput.h``.
56
67
Exposed constants::
78
89
KEY, ABS, REL, SW, MSC, LED, BTN, REP, SND, ID, EV,
9-
BUS, SYN, FF, FF_STATUS
10+
BUS, SYN, FF, FF_STATUS, UI, UINPUT
1011
1112
This module also provides numerous reverse and forward mappings that are best
1213
illustrated by a few examples::

evdev/genecodes.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
'''
55
Generate a Python extension module that exports macros from
6-
/usr/include/linux/input.h
6+
/usr/include/linux/input.h and /usr/include/linux/uinput.h
77
'''
88

99
import os, sys, re
@@ -12,12 +12,13 @@
1212
template = r'''
1313
#include <Python.h>
1414
#include <linux/input.h>
15+
#include <linux/uinput.h>
1516
1617
/* Automatically generated by evdev.genecodes */
17-
/* Generated on %s */
18+
/* Generated on %(uname)s */
1819
1920
#define MODULE_NAME "_ecodes"
20-
#define MODULE_HELP "linux/input.h macros"
21+
#define MODULE_HELP "linux/input.h and linux/uinput.h macros"
2122
2223
static PyMethodDef MethodTable[] = {
2324
{ NULL, NULL, 0, NULL}
@@ -49,7 +50,11 @@
4950
5051
if (m == NULL) return NULL;
5152
52-
%s
53+
/* input.h constants */
54+
%(input)s
55+
56+
/* uinput.h constants */
57+
%(uinput)s
5358
5459
return m;
5560
}
@@ -69,22 +74,30 @@
6974
#endif
7075
'''
7176

72-
header = '/usr/include/linux/input.h' if len(sys.argv) == 1 else sys.argv[1]
73-
regex = r'#define +((?:KEY|ABS|REL|SW|MSC|LED|BTN|REP|SND|ID|EV|BUS|SYN|FF)_\w+)'
74-
regex = re.compile(regex)
77+
inputh = '/usr/include/linux/input.h' if len(sys.argv) == 1 else sys.argv[1]
78+
uinputh = '/usr/include/linux/uinput.h' if len(sys.argv) < 3 else sys.argv[2]
79+
80+
inputh_re = r'#define +((?:KEY|ABS|REL|SW|MSC|LED|BTN|REP|SND|ID|EV|BUS|SYN|FF)_\w+)'
81+
inputh_re = re.compile(inputh_re)
82+
uinputh_re = r'#define +((?:EV|UI_FF)_\w+)'
83+
uinputh_re = re.compile(uinputh_re)
7584

76-
if not os.path.exists(header):
77-
print('no such file: %s' % header)
78-
sys.exit(1)
85+
for fn in inputh, uinputh:
86+
if not os.path.exists(fn):
87+
print('no such file: %s' % inputh)
88+
sys.exit(1)
7989

80-
def getmacros():
81-
for line in open(header):
90+
def getmacros(fn, regex):
91+
for line in open(fn):
8292
macro = regex.search(line)
8393
if macro:
8494
yield ' PyModule_AddIntMacro(m, %s);' % macro.group(1)
8595

8696
uname = list(os.uname()); del uname[1]
8797
uname = ' '.join(uname)
8898

89-
macros = os.linesep.join(getmacros())
90-
print(template % (uname, macros))
99+
input_macros = os.linesep.join(getmacros(inputh, inputh_re))
100+
uinput_macros = os.linesep.join(getmacros(uinputh, uinputh_re))
101+
102+
ctx = {'uname': uname, 'input': input_macros, 'uinput': uinput_macros}
103+
print(template % ctx)

setup.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@
5959

6060
def create_ecodes():
6161
# :todo: expose as a command option
62-
header = '/usr/include/linux/input.h'
62+
input_header = '/usr/include/linux/input.h'
63+
uinput_header = '/usr/include/linux/uinput.h'
6364

64-
if not os.path.isfile(header):
65+
if not all(map(os.path.isfile, (input_header, uinput_header))):
6566
msg = '''\
66-
The linux/input.h header file is missing. You will have to
67-
install the headers for your kernel in order to continue:
67+
The linux/input.h and linux/uinput.h header files are
68+
missing. You will have to install the headers for your kernel
69+
in order to continue:
6870
6971
yum install kernel-headers-$(uname -r)
7072
apt-get intall linux-headers-$(uname -r)
@@ -75,8 +77,9 @@ def create_ecodes():
7577

7678
from subprocess import check_call
7779

78-
print('writing ecodes.c (using %s)' % header)
79-
cmd = '%s genecodes.py %s > ecodes.c' % (sys.executable, header)
80+
headers = (input_header, uinput_header)
81+
print('writing ecodes.c (using %s and %s)' % headers)
82+
cmd = '%s genecodes.py %s > ecodes.c' % (sys.executable, ' '.join(headers))
8083
check_call(cmd, cwd="%s/evdev" % here, shell=True)
8184

8285

0 commit comments

Comments
 (0)