Commit graph

235 commits

Author SHA1 Message Date
Peter Hutterer
ad709cf953 Log to stderr by default
The logging we do use atm inside the library is largely
to spot application errors. Log that to stderr by default so
it doesn't get lost.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-10 09:37:59 +10:00
Peter Hutterer
4b5ffa6bea Warn if there are multiple devices with the same syspath
Change to the previous code in that we continue looking at devices
even after we've found one. However, this way we can warn
the user when we can't guarantee syspath correctness.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-03 17:01:42 +10:00
Peter Hutterer
a6e25fab76 Log a few errors, specifically application bugs
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-03 17:01:40 +10:00
Peter Hutterer
55d67a340b Drop per-device logging function, use per-library one instead
There's no need to have separate logging function for each device created.
More likely, libevdev will be hooked up once into the logging system and
expected to deal with it.

Plus, this allows us to log from the uinput code where we don't
have the context anyway.

Requires a rename to libevdev_set_log_function to avoid ABI breaks, and
while we're breaking the ABI make the logging function more sophisticated
to log line, number, etc.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-09-03 16:58:54 +10:00
Peter Hutterer
37d37cdaea uinput: don't try to set the syspath twice
If we have it, stop searching for it. Otherwise a second device with the
same name would overwrite the first, causing a leak.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 13:17:58 +10:00
Peter Hutterer
22d2a735c4 Return -EBADF for functions that need the fd initialized
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 13:17:56 +10:00
Peter Hutterer
2c101977b7 Return EBADF when trying to read from an uninitalized device
All other functions that check the fd for validity return EBADF, which also makes it
easier to debug if the actual device goes away.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 13:17:26 +10:00
Peter Hutterer
9675287062 Use ENOMEM instead of ENOSPC
From errno(3):
   ENOMEM          Not enough space (POSIX.1)
   ENOSPC          No space left on device (POSIX.1)

when we run out memory the reason is a failed malloc, for which ENOMEM
seems more appropriate.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 12:27:23 +10:00
Peter Hutterer
69f89c8877 test: update to test for the various _MAX values
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 09:40:41 +10:00
Peter Hutterer
4417a6a1c1 memcpy instead of invidual bittoggle
The ioctls return the number of bytes copied into the destination, so just
copy them into the device state instead of individually flipping bits.

For easier review: rc is the return value of the EVIOCG* ioctl, which is
the number of bytes copied.

state variables must be initialized to 0 now, in case the kernel's FOO_MAX
is smaller than libevdev's FOO_MAX. If not initialized to 0, the bytes
between the two max values is undefined and we may end up generating bogus
events.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-31 09:40:17 +10:00
Peter Hutterer
e372c4a6bd test: add a test for uinput device properties
Specifically, test for INPUT_PROP_MAX, which is a valid property value

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-30 17:41:02 +10:00
Peter Hutterer
b77fea9c89 Fix off-by-one errors when dealing with *_MAX values.
LED_MAX, KEY_MAX, ABS_MT_MAX, etc. are all valid event codes

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-30 17:40:54 +10:00
Peter Hutterer
a8871e7aea Use AC_USE_SYSTEM_EXTENSIONS
Defines _GNU_SOURCE for us.
http://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Posix-Variants.html

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:54:50 +10:00
Peter Hutterer
da425202c1 test: fix ev_rep test for new uinput implementation
We can actually set EV_REP values now, though with limitations

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-29 13:54:49 +10:00
Peter Hutterer
cc2eaec4ed test: switch udev backend over to new libevdev-uinput bits
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:54:49 +10:00
Peter Hutterer
21356cca57 test: add uinput creation tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-29 13:54:49 +10:00
Peter Hutterer
1acbfb3579 Add support for uinput device creation
This lets libevdev provide a relatively generic interface for the
creation of uinput devices so we don't need to duplicate this across
multiple projects.

Most of this is lifted from the current test implementation, with a
couple of minor changes.

EV_REP needs special handling:
   Kernel allows to set the EV_REP bit, it doesn't set REP_* bits (which we
   wrap anyway) but it will also set the default values (500, 33).

Device node is guessed based on the sysfs path:
   The sysfs path contains a eventN file, that corresponds to our
   /dev/input/eventN number. Use it so clients can quickly get the device
   node, without a libudev dependency.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:54:46 +10:00
Peter Hutterer
1b7c46b2f1 Fix two signed vs unsigned int warnings
dev->num_slots is -1 if we don't have ABS_MT_SLOT.

Set dev->grabbed to the right field type.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:20:07 +10:00
Peter Hutterer
30a65d20e9 Actually use the gcc CFLAGS set in configure
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:02:53 +10:00
Peter Hutterer
7060206aca Mark all external symbols with LIBEVDEV_EXPORT
GCC_CFLAGS was set by configure, but never actually used. So we didn't build with hidden symbols,
rather just weeded them out later through libtool.

Do this properly now, mark the symbols as visibility default.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:02:53 +10:00
Peter Hutterer
a29d7dba14 Fix some compiler warnings about maybe uninitialized values
These are just to shut the compiler up, in all three cases we only access
the respective values if they're defined.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:02:53 +10:00
Peter Hutterer
9b924d26eb configure.ac: Drop a superfluous variable
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 13:02:50 +10:00
Peter Hutterer
f58fb680f5 Add C++ header guards
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 11:36:20 +10:00
Peter Hutterer
dd4a1a49de test: add test for libevdev_is_event_code(EV_SYN...)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 11:36:20 +10:00
Peter Hutterer
13ba7712a6 Simplify getter/setter macros
Now that we've dropped the deprecated API, we can simplify the macros a bit.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 11:36:20 +10:00
Peter Hutterer
b7501655c0 Drop deprecated API
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-29 11:36:20 +10:00
Peter Hutterer
d9e633cf66 Fix a few signed/unsigned int comparisons
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-29 11:36:20 +10:00
Peter Hutterer
40fda4b2d4 Add a note that libevdev_is_event_type/code have compile-time ranges
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-29 11:36:20 +10:00
Peter Hutterer
fed9963973 libevdev_is_event_type() needs to check for < EV_CNT
EV_MAX is a valid (though unused) value.

Reported-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 11:36:20 +10:00
Peter Hutterer
ce7e2f1516 Rewrite libevdev_is_event_code to avoid signed/unsigned comparison
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 11:36:20 +10:00
Peter Hutterer
fa4cadae60 Use libevdev_get_event_type_max from libevdev_get_event_code_name
This will check for invalid types for us, and we can do a better check
for signed/unsigned comparison.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 11:36:20 +10:00
Peter Hutterer
4b715dd928 Axis values must be int, not unsigned int
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 11:36:20 +10:00
Peter Hutterer
0309ca0ee5 Ignore -Woverride-init in event-names.h
Having the declarations in the form of [0...EV_MAX] = NULL together
with the actual definitions causes warnings for every true definition if
-Woverride-init is enabled.

We can drop them for most as they're zero, but still need them for
ev_max (which defaults to -1), not zero. So use the GCC pragma to
disable the warnings for this file.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 11:36:20 +10:00
Peter Hutterer
a3e8a240ab Change event name generate script to be python 2/3 compatible
Python 3 doesn't have a print statement, only a print function.

Fixed with:
  2to3 make-event-names.py | git apply

Print as function requires Python 2.6 which is reasonable enough given
that even RHEL6 ships that.

Even though it's not needed for 2.6, use
	from __future__ import print_function
to avoid accidentally introducing a print statement in the future.
With this line, print "blah" is now a syntax error in python 2.
This line was added manually, after the 2to3 conversion.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-29 11:35:18 +10:00
Peter Hutterer
144b731202 doc: actually package generated documentation
Previous find command wouldn't actually list the generated documentation
files, so they'd be missing in the tarball.

...and add a dist-hook to make sure this won't happen during release.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-29 11:13:49 +10:00
Peter Hutterer
b20becc942 Add support for EV_SW
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-29 11:13:47 +10:00
Peter Hutterer
8b435a8534 Avoid under-allocation of array for syncing key/led state
No functional effect as the size would end up being the same anyway
due to the values of KEY_MAX and LED_MAX.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-28 11:01:24 +10:00
Peter Hutterer
4123927cf0 Remove unneeded include of linux/uinput.h
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-26 13:10:05 +10:00
Peter Hutterer
bd35bd53f0 Merge branch 'led-handling' 2013-08-26 09:53:10 +10:00
Peter Hutterer
f9fef9fd04 Rename enums to match lower_case format
This is technically an API, but not an ABI change.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by:  David Herrmann <dh.herrmann@gmail.com>
2013-08-26 09:52:34 +10:00
Peter Hutterer
edc31cf12e Store the abs value after handling mt events
This way any ABS_MT_ event value that comes in will also be stored in abs_info.
That always corresponds to "current slot", so if a user calls
libevdev_set_event_value() or libevdev_get_event_value() they're actually
modifying the current slot value.

When the current slot changes, sync the state back into the absinfo values.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-26 09:52:33 +10:00
polyphemus
f29e4118fc write EV_SYN input_event along with led events to device
Other clients of an evdev device need to have the events they receive
be separated, in moment in time, from other events by an EV_SYN/
SYN_REPORT. This is the responsibility of the client who writes events
into the stream.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-26 09:52:27 +10:00
Martin Minarik
411031178e Fix build without MSC_TIMESTAMP
To build with older input.h

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-26 08:10:11 +10:00
David Herrmann
4ca248c044 Pass --no-print-directory to make
The "Entering/Leaving directroy /xyz" messages only add noise to
make-output. Even without we still get short hints which directory is
currently processed. Compare the two outputs below:

With --no-print-directory added:
  make --no-print-directory all-recursive
  Making all in doc
  doxygen libevdev.doxygen
  Making all in libevdev
  python2 ./make-event-names.py --output=c > event-names.h
  make  all-am
    CC       libevdev.lo
    CCLD     libevdev.la
  Making all in tools
    CC       libevdev-events.o
    CCLD     libevdev-events
  Making all in test
    CC       test-main.o
    CC       test-event-names.o
    CC       test-libevdev-init.o
    CC       test-libevdev-has-event.o
    CC       test-int-queue.o
    CC       test-libevdev-events.o
    CC       libevdev.o
    CC       test-common-uinput.o
    CC       test-common.o
    CCLD     test-libevdev

Without it:
  make  all-recursive
  make[1]: Entering directory `/home/david/dev/libevdev'
  Making all in doc
  make[2]: Entering directory `/home/david/dev/libevdev/doc'
  doxygen libevdev.doxygen
  make[2]: Leaving directory `/home/david/dev/libevdev/doc'
  Making all in libevdev
  make[2]: Entering directory `/home/david/dev/libevdev/libevdev'
  python2 ./make-event-names.py --output=c > event-names.h
  make  all-am
  make[3]: Entering directory `/home/david/dev/libevdev/libevdev'
    CC       libevdev.lo
    CCLD     libevdev.la
  make[3]: Leaving directory `/home/david/dev/libevdev/libevdev'
  make[2]: Leaving directory `/home/david/dev/libevdev/libevdev'
  Making all in tools
  make[2]: Entering directory `/home/david/dev/libevdev/tools'
    CC       libevdev-events.o
    CCLD     libevdev-events
  make[2]: Leaving directory `/home/david/dev/libevdev/tools'
  Making all in test
  make[2]: Entering directory `/home/david/dev/libevdev/test'
    CC       test-main.o
    CC       test-event-names.o
    CC       test-libevdev-init.o
    CC       test-libevdev-has-event.o
    CC       test-int-queue.o
    CC       test-libevdev-events.o
    CC       libevdev.o
    CC       test-common-uinput.o
    CC       test-common.o
    CCLD     test-libevdev
  make[2]: Leaving directory `/home/david/dev/libevdev/test'
  make[2]: Entering directory `/home/david/dev/libevdev'
  make[2]: Leaving directory `/home/david/dev/libevdev'
  make[1]: Leaving directory `/home/david/dev/libevdev'

We don't really win any useful information from these messages.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-26 07:59:07 +10:00
David Herrmann
0e1693ece3 Remove deprecated SYMBOL_CACHE_SIZE from doxygen.in
SYMBOL_CACHE_SIZE was removed in newer doxygen releases. We use the
default value, so simply drop it.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-22 16:24:07 +10:00
David Herrmann
d9c9322c06 Add -I m4 to ACLOCAL_AMFLAGS
We put m4 files into a separate directory. If we ever put our own files in
there, we need to include it. Furthermore, this suppresses annoying
autotools warnings.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-22 16:24:03 +10:00
Peter Hutterer
4d4293a65b Add functions to toggle LEDs on the device
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-15 10:32:40 +10:00
Peter Hutterer
bfb6c1c6c5 Keep the LED state and sync it after SYN_DROPPED
This enables libevdev_get_event_value(dev, EV_LED, LED_NUML); to check
if a LED is on or off.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-15 10:32:40 +10:00
Peter Hutterer
74d9b4c72d Add setters for an event or slot value
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-15 10:32:37 +10:00
Peter Hutterer
62db838128 Rename libevdev_kernel_set_abs_value to libevdev_kernel_set_abs_info
Keep it in line with the non-kernel setter

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2013-08-14 10:23:15 +10:00