Skip to content

Commit b48d923

Browse files
suinput_set_capabilities() replaced by more flexible suinput_enable_event()
1 parent bc6329d commit b48d923

6 files changed

Lines changed: 66 additions & 107 deletions

File tree

NEWS

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
0.5
2+
===
3+
4+
- ABI change: `suinput_set_capapbilites()` is replaced by
5+
`suinput_enable_event()`.
6+
- SO-version: 4
7+
18
0.4
29
===
310

4-
Licensing changed from LGPLv3+ to GPLv3+. Usage examples are now
5-
included.
11+
- Licensing changed from LGPLv3+ to GPLv3+.
12+
13+
- Usage examples are now included.
614

715
0.3
816
===
917

10-
Provides more generic interface that is "compatible" with standard
11-
uinput. Functions are just helper functions operating on an uinput
12-
file descriptor.
18+
- More generic interface that is "compatible" with standard uinput.
19+
20+
- Functions operating on an uinput file descriptor.

README

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,18 @@ Libsuinput
33

44
Uinput is a Linux kernel module which allows attaching user-space
55
device drivers into the Linux kernel. However, it is pretty low level
6-
from the application developers perspective. This library provides a
6+
from an application developers perspective. This library provides a
77
set of helper functions for making the usage of uinput easier.
88

9-
Usage example
10-
-------------
11-
12-
Create and use a new uinput device with key-capabilities:
13-
14-
int uinput_fd;
15-
int keys[] = {KEY_E, KEY_H, KEY_L, KEY_O};
16-
struct uinput_user_dev user_dev;
17-
18-
memset(&user_dev, 0, sizeof(struct uinput_user_dev));
19-
strcpy(user_dev.name, "libsuinput-example-keyboard");
20-
21-
uinput_fd = suinput_open();
22-
23-
suinput_set_capabilities(uinput_fd, EV_KEY, keys, 4);
24-
25-
suinput_create(uinput_fd, &user_dev);
26-
27-
suinput_write(uinput_fd, EV_KEY, KEY_H, 1); /* Press. */
28-
suinput_syn(uinput_fd); /* "Flushes" events written so far. */
29-
30-
suinput_write(uinput_fd, EV_KEY, KEY_H, 0); /* Release */
31-
suinput_syn(uinput_fd);
32-
33-
suinput_write(uinput_fd, EV_KEY, KEY_E, 1);
34-
suinput_syn(uinput_fd);
35-
36-
suinput_write(uinput_fd, EV_KEY, KEY_E, 0);
37-
suinput_syn(uinput_fd);
38-
39-
suinput_write(uinput_fd, EV_KEY, KEY_L, 1);
40-
suinput_syn(uinput_fd);
41-
42-
suinput_write(uinput_fd, EV_KEY, KEY_L, 0);
43-
suinput_syn(uinput_fd);
44-
45-
suinput_write(uinput_fd, EV_KEY, KEY_L, 1);
46-
suinput_syn(uinput_fd);
47-
48-
suinput_write(uinput_fd, EV_KEY, KEY_L, 0);
49-
suinput_syn(uinput_fd);
50-
51-
suinput_write(uinput_fd, EV_KEY, KEY_O, 1);
52-
suinput_syn(uinput_fd);
53-
54-
suinput_write(uinput_fd, EV_KEY, KEY_O, 0);
55-
suinput_syn(uinput_fd);
56-
57-
suinput_destroy(uinput_fd);
58-
599
General information
6010
-------------------
6111

62-
- Author: Tuomas Jorma Juhani Räsänen <tuomas.rasanen@tjjr.fi>
63-
- Homepage: <http://tjjr.fi/sw/libsuinput>
12+
- Version: 0.5
6413
- License: GPLv3+ (see COPYING for details)
65-
- Version: 0.4
66-
- Repository: <http://github.com/tuos/libsuinput>
67-
- Bugs: <http://github.com/tuos/libsuinput/issues>
68-
- Tarballs: <http://github.com/tuos/libsuinput/downloads>
14+
- Author: [Tuomas Jorma Juhani Räsänen](http://tjjr.fi)
15+
- Homepage: <http://tjjr.fi/sw/libsuinput/>
16+
- Code: <http://code.launchpad.net/libsuinput/>
17+
- Bugs: <http://bugs.launchpad.net/libsuinput/>
6918

7019
Build requirements
7120
------------------
@@ -76,5 +25,5 @@ Runtime requirements
7625
--------------------
7726

7827
- libudev0
79-
- uinput-module installed
80-
- write permissions to `/dev/uinput`
28+
- uinput.ko
29+
- rw-permissions to uinput device node

examples/kbd.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,40 @@ int main(void)
2121

2222
/* Error handling is omitted to keep code as readible as possible. */
2323

24-
suinput_set_capabilities(uinput_fd, EV_KEY, keys, 4);
24+
for (int i = 0; i < 4; ++i) {
25+
suinput_enable_event(uinput_fd, EV_KEY, keys[i]);
26+
}
2527

2628
suinput_create(uinput_fd, &user_dev);
2729

28-
suinput_write(uinput_fd, EV_KEY, KEY_H, 1); /* Press. */
30+
suinput_emit(uinput_fd, EV_KEY, KEY_H, 1); /* Press. */
2931
suinput_syn(uinput_fd); /* "Flushes" events written so far. */
3032

31-
suinput_write(uinput_fd, EV_KEY, KEY_H, 0); /* Release */
33+
suinput_emit(uinput_fd, EV_KEY, KEY_H, 0); /* Release */
3234
suinput_syn(uinput_fd);
3335

34-
suinput_write(uinput_fd, EV_KEY, KEY_E, 1);
36+
suinput_emit(uinput_fd, EV_KEY, KEY_E, 1);
3537
suinput_syn(uinput_fd);
3638

37-
suinput_write(uinput_fd, EV_KEY, KEY_E, 0);
39+
suinput_emit(uinput_fd, EV_KEY, KEY_E, 0);
3840
suinput_syn(uinput_fd);
3941

40-
suinput_write(uinput_fd, EV_KEY, KEY_L, 1);
42+
suinput_emit(uinput_fd, EV_KEY, KEY_L, 1);
4143
suinput_syn(uinput_fd);
4244

43-
suinput_write(uinput_fd, EV_KEY, KEY_L, 0);
45+
suinput_emit(uinput_fd, EV_KEY, KEY_L, 0);
4446
suinput_syn(uinput_fd);
4547

46-
suinput_write(uinput_fd, EV_KEY, KEY_L, 1);
48+
suinput_emit(uinput_fd, EV_KEY, KEY_L, 1);
4749
suinput_syn(uinput_fd);
4850

49-
suinput_write(uinput_fd, EV_KEY, KEY_L, 0);
51+
suinput_emit(uinput_fd, EV_KEY, KEY_L, 0);
5052
suinput_syn(uinput_fd);
5153

52-
suinput_write(uinput_fd, EV_KEY, KEY_O, 1);
54+
suinput_emit(uinput_fd, EV_KEY, KEY_O, 1);
5355
suinput_syn(uinput_fd);
5456

55-
suinput_write(uinput_fd, EV_KEY, KEY_O, 0);
57+
suinput_emit(uinput_fd, EV_KEY, KEY_O, 0);
5658
suinput_syn(uinput_fd);
5759

5860
suinput_destroy(uinput_fd);

examples/mouse.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,27 @@ int main(void)
2323

2424
/* Error handling is omitted to keep code as readible as possible. */
2525

26-
suinput_set_capabilities(uinput_fd, EV_KEY, btns, 3);
27-
suinput_set_capabilities(uinput_fd, EV_REL, rel_axes, 3);
26+
for (i = 0; i < 3; ++i) {
27+
suinput_enable_event(uinput_fd, EV_KEY, btns[i]);
28+
}
29+
30+
for (i = 0; i < 3; ++i) {
31+
suinput_enable_events(uinput_fd, EV_REL, rel_axes[i]);
32+
}
2833

2934
suinput_create(uinput_fd, &user_dev);
3035

3136
/* Move pointer 20 * 5 units towards bottom-right. */
3237
for (i = 0; i < 20; ++i) {
33-
suinput_write(uinput_fd, EV_REL, REL_X, 5);
34-
suinput_write(uinput_fd, EV_REL, REL_Y, 5);
38+
suinput_emit(uinput_fd, EV_REL, REL_X, 5);
39+
suinput_emit(uinput_fd, EV_REL, REL_Y, 5);
3540
suinput_syn(uinput_fd);
3641
}
3742

38-
suinput_write(uinput_fd, EV_KEY, BTN_LEFT, 1); /* Press. */
43+
suinput_emit(uinput_fd, EV_KEY, BTN_LEFT, 1); /* Press. */
3944
suinput_syn(uinput_fd); /* "Flushes" events written so far. */
4045

41-
suinput_write(uinput_fd, EV_KEY, BTN_LEFT, 0); /* Release. */
46+
suinput_emit(uinput_fd, EV_KEY, BTN_LEFT, 0); /* Release. */
4247
suinput_syn(uinput_fd);
4348

4449
suinput_destroy(uinput_fd);

src/suinput.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
libsuinput - A set of uinput helper functions
3-
Copyright © 2011 Tuomas Jorma Juhani Räsänen <tuomas.j.j.rasanen@tjjr.fi>
3+
Copyright © 2011 Tuomas Jorma Juhani Räsänen <tuomasjjrasanen@tjjr.fi>
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -133,28 +133,26 @@ int suinput_destroy(int uinput_fd)
133133
return close(uinput_fd);
134134
}
135135

136-
int suinput_set_event_capabilities(int uinput_fd, uint16_t ev_type,
137-
const uint16_t *ev_code_v, size_t ev_code_c)
136+
int suinput_enable_event(int uinput_fd, uint16_t ev_type, uint16_t ev_code)
138137
{
139-
size_t i;
140138
unsigned long io;
141139

142140
if (ioctl(uinput_fd, UI_SET_EVBIT, ev_type) == -1)
143141
return -1;
144142

145143
switch (ev_type) {
146-
case EV_REL:
147-
io = UI_SET_RELBIT;
148-
break;
149-
case EV_MSC:
150-
io = UI_SET_MSCBIT;
151-
break;
152144
case EV_KEY:
153145
io = UI_SET_KEYBIT;
154146
break;
147+
case EV_REL:
148+
io = UI_SET_RELBIT;
149+
break;
155150
case EV_ABS:
156151
io = UI_SET_ABSBIT;
157152
break;
153+
case EV_MSC:
154+
io = UI_SET_MSCBIT;
155+
break;
158156
case EV_SW:
159157
io = UI_SET_SWBIT;
160158
break;
@@ -171,15 +169,12 @@ int suinput_set_event_capabilities(int uinput_fd, uint16_t ev_type,
171169
return -2;
172170
}
173171

174-
for (i = 0; i < ev_code_c; ++i) {
175-
int ev_code = ev_code_v[i];
176-
if (ioctl(uinput_fd, io, ev_code) == -1)
177-
return -1;
178-
}
179-
return 0;
172+
return ioctl(uinput_fd, io, ev_code);
180173
}
181174

182-
int suinput_set_input_properties(int uinput_fd, const uint8_t *input_prop_v, size_t input_prop_c)
175+
int suinput_set_input_properties(int const uinput_fd,
176+
uint8_t const *input_prop_v,
177+
size_t const input_prop_c)
183178
{
184179
size_t i;
185180
for (i = 0; i < input_prop_c; ++i) {

src/suinput.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
libsuinput - A set of uinput helper functions
3-
Copyright © 2011 Tuomas Jorma Juhani Räsänen <tuomas.j.j.rasanen@tjjr.fi>
3+
Copyright © 2011 Tuomas Jorma Juhani Räsänen <tuomasjjrasanen@tjjr.fi>
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -23,23 +23,23 @@
2323

2424
#include <linux/uinput.h>
2525

26+
int suinput_open(void);
27+
28+
int suinput_enable_event(int uinput_fd, uint16_t ev_type, uint16_t ev_code);
29+
30+
int suinput_create(int uinput_fd, const struct uinput_user_dev *user_dev_p);
31+
2632
int suinput_write_event(int uinput_fd, const struct input_event *event_p);
2733

2834
int suinput_emit(int uinput_fd, uint16_t ev_type, uint16_t ev_code,
2935
int32_t ev_value);
3036

3137
int suinput_syn(int uinput_fd);
3238

33-
int suinput_open(void);
34-
35-
int suinput_create(int uinput_fd, const struct uinput_user_dev *user_dev_p);
36-
3739
int suinput_destroy(int uinput_fd);
3840

39-
int suinput_set_event_capabilities(int uinput_fd, uint16_t ev_type,
40-
const uint16_t *ev_code_v, size_t ev_code_c);
41-
4241
int suinput_set_input_properties(int uinput_fd,
43-
const uint8_t *input_prop_v, size_t input_prop_c);
42+
const uint8_t *input_prop_v,
43+
size_t input_prop_c);
4444

4545
#endif /* SUINPUT_H */

0 commit comments

Comments
 (0)