Update input event structures read from the kernel to match the 1.2 version of the driver.
There are no changes to the exposed interfaces of libinput.
Note that the patch goes along with the changes to libevdev and mtdev to support the updated kernel driver.
The associated kernel driver change is proposed at https://lkml.org/lkml/2016/10/17/1146 .
Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com --- include/linux/input.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- src/evdev.c | 4 ++-- 2 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/include/linux/input.h b/include/linux/input.h index 4bf3d6d..202798a 100644 --- a/include/linux/input.h +++ b/include/linux/input.h @@ -13,10 +13,29 @@ #include <sys/types.h> #include <linux/types.h>
-/* - * The event structure itself +/* The time structure for y2038 safe raw_input_event. + * The fields use unsigned types to extend times until + * year 2106 rather than 2038. */ +struct input_timeval { + __kernel_ulong_t tv_sec; + __kernel_ulong_t tv_usec; +}; + +struct raw_input_event { + struct input_timeval time; + __u16 type; + __u16 code; + __s32 value; +}; + +#ifndef __KERNEL__
+/* Userspace structure. + * Definition maintained here for userspace that is not yet updated to use + * struct raw_input_event. + * Not to be used anywhere within the kernel. + */ struct input_event { struct timeval time; __u16 type; @@ -24,11 +43,37 @@ struct input_event { __s32 value; };
+ +static inline void +raw_input_to_input_event(const struct raw_input_event *raw, struct input_event *ev) +{ + ev->time.tv_sec = raw->time.tv_sec; + ev->time.tv_usec = raw->time.tv_usec; + ev->type = raw->type; + ev->code = raw->code; + ev->value = raw->value; +} + +static inline void +input_to_raw_event(const struct input_event *ev, struct raw_input_event *raw) +{ + raw->time.tv_sec = ev->time.tv_sec; + raw->time.tv_usec = ev->time.tv_usec; + raw->type = ev->type; + raw->code = ev->code; + raw->value = ev->value; +} + +#endif + + /* * Protocol version. */
#define EV_VERSION 0x010001 +#define EV_VERSION_1_2 0x010002 +
/* * IOCTLs (0x00 - 0x7f) diff --git a/src/evdev.c b/src/evdev.c index f7f7230..5d47119 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -256,7 +256,7 @@ evdev_device_led_update(struct evdev_device *device, enum libinput_led leds) { LIBINPUT_LED_CAPS_LOCK, LED_CAPSL }, { LIBINPUT_LED_SCROLL_LOCK, LED_SCROLLL }, }; - struct input_event ev[ARRAY_LENGTH(map) + 1]; + struct raw_input_event ev[ARRAY_LENGTH(map) + 1]; unsigned int i;
if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD)) @@ -2665,7 +2665,7 @@ evdev_set_device_group(struct evdev_device *device, static inline void evdev_drain_fd(int fd) { - struct input_event ev[24]; + struct raw_input_event ev[24]; size_t sz = sizeof ev;
while (read(fd, &ev, sz) == (int)sz) {
On Wed, Oct 19, 2016 at 07:05:13PM -0700, Deepa Dinamani wrote:
Update input event structures read from the kernel to match the 1.2 version of the driver.
There are no changes to the exposed interfaces of libinput.
Note that the patch goes along with the changes to libevdev and mtdev to support the updated kernel driver.
The associated kernel driver change is proposed at https://lkml.org/lkml/2016/10/17/1146 .
Signed-off-by: Deepa Dinamani deepa.kernel@gmail.com
include/linux/input.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- src/evdev.c | 4 ++-- 2 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/include/linux/input.h b/include/linux/input.h index 4bf3d6d..202798a 100644 --- a/include/linux/input.h +++ b/include/linux/input.h @@ -13,10 +13,29 @@ #include <sys/types.h> #include <linux/types.h> -/*
- The event structure itself
+/* The time structure for y2038 safe raw_input_event.
- The fields use unsigned types to extend times until
*/
- year 2106 rather than 2038.
+struct input_timeval {
- __kernel_ulong_t tv_sec;
- __kernel_ulong_t tv_usec;
+};
+struct raw_input_event {
- struct input_timeval time;
- __u16 type;
- __u16 code;
- __s32 value;
+};
+#ifndef __KERNEL__ +/* Userspace structure.
- Definition maintained here for userspace that is not yet updated to use
- struct raw_input_event.
- Not to be used anywhere within the kernel.
- */
struct input_event { struct timeval time; __u16 type; @@ -24,11 +43,37 @@ struct input_event { __s32 value; };
+static inline void +raw_input_to_input_event(const struct raw_input_event *raw, struct input_event *ev) +{
- ev->time.tv_sec = raw->time.tv_sec;
- ev->time.tv_usec = raw->time.tv_usec;
- ev->type = raw->type;
- ev->code = raw->code;
- ev->value = raw->value;
+}
+static inline void +input_to_raw_event(const struct input_event *ev, struct raw_input_event *raw) +{
- raw->time.tv_sec = ev->time.tv_sec;
- raw->time.tv_usec = ev->time.tv_usec;
- raw->type = ev->type;
- raw->code = ev->code;
- raw->value = ev->value;
+}
+#endif
/*
- Protocol version.
*/ #define EV_VERSION 0x010001 +#define EV_VERSION_1_2 0x010002
/*
- IOCTLs (0x00 - 0x7f)
diff --git a/src/evdev.c b/src/evdev.c index f7f7230..5d47119 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -256,7 +256,7 @@ evdev_device_led_update(struct evdev_device *device, enum libinput_led leds) { LIBINPUT_LED_CAPS_LOCK, LED_CAPSL }, { LIBINPUT_LED_SCROLL_LOCK, LED_SCROLLL }, };
- struct input_event ev[ARRAY_LENGTH(map) + 1];
- struct raw_input_event ev[ARRAY_LENGTH(map) + 1]; unsigned int i;
if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD)) @@ -2665,7 +2665,7 @@ evdev_set_device_group(struct evdev_device *device, static inline void evdev_drain_fd(int fd) {
- struct input_event ev[24];
- struct raw_input_event ev[24];
don't we need some version detection here? what's the effect of writing new structs to old kernels, other than lighting up LEDs that shouldn't be lit?
Cheers, Peter
size_t sz = sizeof ev; while (read(fd, &ev, sz) == (int)sz) { -- 2.7.4