Skip to content

Commit 6d2d341

Browse files
Update libsuinput
2 parents 5be2225 + 87bb049 commit 6d2d341

9 files changed

Lines changed: 100 additions & 50 deletions

File tree

libsuinput/AUTHORS

Lines changed: 0 additions & 1 deletion
This file was deleted.

libsuinput/NEWS

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
Libsuinput NEWS -- history of user-visible changes
33
====================================================
44

5-
Release M.m
5+
Release x.y
66
===========
77

8-
- Use GNU Autotools as a build system.
8+
- API changes:
9+
10+
- add new function `suinput_emit_click()`.
11+
- add new function `suinput_emit_combo()`.
12+
13+
- SO-version: 5.0.1
914

1015
Release 0.5
1116
===========
1217

18+
- Use GNU Autotools as a build system.
19+
1320
- API change: `suinput_set_capapbilites()` is replaced by
1421
`suinput_enable_event()`.
1522

libsuinput/README

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
================
2-
Libsuinput 0.5
3-
================
4-
5-
Uinput is a Linux kernel module which allows attaching user-space
6-
device drivers into the Linux kernel. However, its C interface is
7-
pretty low level from an application developer's perspective. This
8-
library provides a set of helper functions for making the usage of
9-
uinput easier.
10-
11-
Author: Tuomas Jorma Juhani Räsänen <tuomasjjrasanen@tjjr.fi>
1+
============
2+
Libsuinput
3+
============
4+
5+
Uinput is Linux kernel module which allows attaching userspace device
6+
drivers into the Linux kernel. However, its ioctl-interface is pretty
7+
low level from an application developer's perspective. This library
8+
provides a set of helper functions for making the usage of uinput
9+
easier. Libsuinput can be considered thin, because it operates on the
10+
same file descriptors as traditional ioctl commands.
11+
12+
Author: Tuomas Räsänen <tuomasjjrasanen@tjjr.fi>
1213
Homepage: <http://tjjr.fi/sw/libsuinput/>
1314

1415
How to install
1516
==============
1617

1718
Libsuinput uses libudev and therefore requires libudev development
18-
files, more specifically libudev.h, to get compiled. On Debian and
19-
its derivatives, the header file is packaged in libudev-dev.
19+
files, more specifically libudev.h, to get compiled. On Debian and its
20+
derivatives, the header file is packaged in libudev-dev.
2021

2122
After satisfying dependencies described above, the basic installation
2223
is easy. Just run the following command:

libsuinput/configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ AC_INIT([libsuinput],
55
[http://tjjr.fi/sw/libsuinput/])
66
AC_CONFIG_AUX_DIR([build-aux])
77
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
8+
AM_PROG_AR
89
AC_PROG_LIBTOOL
910
AC_PROG_CC
1011
AC_CONFIG_MACRO_DIR([m4])

libsuinput/examples/Makefile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
CFLAGS=-Wall -Wextra -Werror -pedantic -std=c89
2-
LDFLAGS=
3-
PROGRAMS=keyboard mouse
1+
CFLAGS = -Wall -Wextra -Werror -pedantic
2+
CFLAGS_ALL = $(CFLAGS)
3+
4+
LDFLAGS =
5+
LDFLAGS_ALL = $(LDFLAGS) -lsuinput
6+
7+
CPPFLAGS =
8+
CPPFLAGS_ALL = $(CPPFLAGS)
9+
10+
PROGRAMS = keyboard mouse
411

512
.PHONY: all clean
613

714
all: $(PROGRAMS)
815

9-
%: %.c
10-
gcc -o$@ $(CFLAGS) $(LDFLAGS) -lsuinput $^
16+
%.o : %.c
17+
$(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) -c -o $@ $<
18+
19+
$(PROGRAMS) : % : %.o
20+
$(CC) $(LDFLAGS_ALL) $(CFLAGS_ALL) -o $@ $<
1121

1222
clean:
1323
rm -f $(PROGRAMS)
24+
rm -f *.o

libsuinput/examples/keyboard.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,27 @@ int main(void)
2727
}
2828

2929
suinput_create(uinput_fd, &user_dev);
30+
sleep(1);
3031

31-
suinput_emit(uinput_fd, EV_KEY, KEY_H, 1); /* Press. */
32-
suinput_syn(uinput_fd); /* "Flushes" events written so far. */
33-
34-
suinput_emit(uinput_fd, EV_KEY, KEY_H, 0); /* Release */
35-
suinput_syn(uinput_fd);
36-
37-
suinput_emit(uinput_fd, EV_KEY, KEY_E, 1);
38-
suinput_syn(uinput_fd);
39-
40-
suinput_emit(uinput_fd, EV_KEY, KEY_E, 0);
41-
suinput_syn(uinput_fd);
42-
43-
suinput_emit(uinput_fd, EV_KEY, KEY_L, 1);
44-
suinput_syn(uinput_fd);
45-
46-
suinput_emit(uinput_fd, EV_KEY, KEY_L, 0);
32+
suinput_emit_click(uinput_fd, KEY_H);
4733
suinput_syn(uinput_fd);
34+
sleep(1);
4835

49-
suinput_emit(uinput_fd, EV_KEY, KEY_L, 1);
36+
suinput_emit_click(uinput_fd, KEY_E);
5037
suinput_syn(uinput_fd);
38+
sleep(1);
5139

52-
suinput_emit(uinput_fd, EV_KEY, KEY_L, 0);
40+
suinput_emit_click(uinput_fd, KEY_L);
5341
suinput_syn(uinput_fd);
42+
sleep(1);
5443

55-
suinput_emit(uinput_fd, EV_KEY, KEY_O, 1);
44+
suinput_emit_click(uinput_fd, KEY_L);
5645
suinput_syn(uinput_fd);
46+
sleep(1);
5747

58-
suinput_emit(uinput_fd, EV_KEY, KEY_O, 0);
48+
suinput_emit_click(uinput_fd, KEY_O);
5949
suinput_syn(uinput_fd);
50+
sleep(1);
6051

6152
suinput_destroy(uinput_fd);
6253

libsuinput/examples/mouse.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <err.h>
33
#include <string.h>
44
#include <unistd.h>
5+
#include <time.h>
56

67
#include <suinput.h>
78

@@ -35,16 +36,15 @@ int main(void)
3536

3637
/* Move pointer 20 * 5 units towards bottom-right. */
3738
for (i = 0; i < 20; ++i) {
39+
struct timespec sleeptime = {0, 50000000};
3840
suinput_emit(uinput_fd, EV_REL, REL_X, 5);
3941
suinput_emit(uinput_fd, EV_REL, REL_Y, 5);
4042
suinput_syn(uinput_fd);
41-
}
4243

43-
suinput_emit(uinput_fd, EV_KEY, BTN_LEFT, 1); /* Press. */
44-
suinput_syn(uinput_fd); /* "Flushes" events written so far. */
44+
nanosleep(&sleeptime, NULL);
45+
}
4546

46-
suinput_emit(uinput_fd, EV_KEY, BTN_LEFT, 0); /* Release. */
47-
suinput_syn(uinput_fd);
47+
suinput_emit_click(uinput_fd, BTN_LEFT);
4848

4949
suinput_destroy(uinput_fd);
5050

libsuinput/src/suinput.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
libsuinput - A set of uinput helper functions
3-
Copyright © 2011 Tuomas Jorma Juhani Räsänen <tuomasjjrasanen@tjjr.fi>
2+
libsuinput - thin userspace library on top of Linux uinput kernel module
3+
Copyright (C) 2013 Tuomas 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
@@ -53,6 +53,42 @@ int suinput_emit(int uinput_fd, uint16_t ev_type, uint16_t ev_code,
5353
return suinput_write_event(uinput_fd, &event);
5454
}
5555

56+
int suinput_emit_click(const int uinput_fd, const uint16_t key_code)
57+
{
58+
if (suinput_emit(uinput_fd, EV_KEY, key_code, 1) == -1)
59+
return -1;
60+
return suinput_emit(uinput_fd, EV_KEY, key_code, 0);
61+
}
62+
63+
int suinput_emit_combo(const int uinput_fd, const uint16_t *const key_codes,
64+
const size_t len)
65+
{
66+
int retval = 0;
67+
size_t i;
68+
69+
for (i = 0; i < len; ++i) {
70+
if (suinput_emit(uinput_fd, EV_KEY, key_codes[i], 1) == -1) {
71+
retval = -1;
72+
break; /* The combination or the device is
73+
somehow broken: there's no sense to
74+
press any of the rest of the
75+
keys. It's like pressing physical keys
76+
one by one and then discovering that
77+
one of the keys required for this
78+
combination is missing or broken. */
79+
}
80+
}
81+
82+
/* Try to release every pressed key, no matter what. */
83+
while (i--) {
84+
if (suinput_emit(uinput_fd, EV_KEY, key_codes[i], 0) == -1) {
85+
retval = -1;
86+
}
87+
}
88+
89+
return retval;
90+
}
91+
5692
int suinput_syn(int uinput_fd)
5793
{
5894
return suinput_emit(uinput_fd, EV_SYN, SYN_REPORT, 0);

libsuinput/src/suinput.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
libsuinput - A set of uinput helper functions
3-
Copyright © 2011 Tuomas Jorma Juhani Räsänen <tuomasjjrasanen@tjjr.fi>
2+
libsuinput - thin userspace library on top of Linux uinput kernel module
3+
Copyright (C) 2013 Tuomas 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
@@ -34,6 +34,10 @@ int suinput_write_event(int uinput_fd, const struct input_event *event_p);
3434
int suinput_emit(int uinput_fd, uint16_t ev_type, uint16_t ev_code,
3535
int32_t ev_value);
3636

37+
int suinput_emit_click(int uinput_fd, uint16_t key_code);
38+
39+
int suinput_emit_combo(int uinput_fd, const uint16_t *key_codes, size_t len);
40+
3741
int suinput_syn(int uinput_fd);
3842

3943
int suinput_destroy(int uinput_fd);

0 commit comments

Comments
 (0)