2011-01-14 14:45:42 -05:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2010 Intel Corporation
|
2013-11-10 17:55:40 +01:00
|
|
|
* Copyright © 2013 Jonas Ådahl
|
2011-01-14 14:45:42 -05:00
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and
|
|
|
|
|
* its documentation for any purpose is hereby granted without fee, provided
|
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
|
* documentation, and that the name of the copyright holders not be used in
|
|
|
|
|
* advertising or publicity pertaining to distribution of the software
|
|
|
|
|
* without specific, written prior permission. The copyright holders make
|
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
|
|
|
|
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-22 18:03:19 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2013-10-15 14:29:56 +02:00
|
|
|
#include <errno.h>
|
2011-01-14 14:45:42 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2014-06-03 07:51:37 +10:00
|
|
|
#include "linux/input.h"
|
2011-01-14 14:45:42 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <fcntl.h>
|
2013-12-06 13:09:18 +10:00
|
|
|
#include <mtdev-plumbing.h>
|
2013-09-24 12:09:03 +01:00
|
|
|
#include <assert.h>
|
2014-02-19 08:45:57 +10:00
|
|
|
#include <time.h>
|
2014-05-18 19:20:39 +02:00
|
|
|
#include <math.h>
|
2011-01-14 14:45:42 -05:00
|
|
|
|
2013-11-10 17:55:40 +01:00
|
|
|
#include "libinput.h"
|
2011-12-19 01:14:03 +02:00
|
|
|
#include "evdev.h"
|
2014-05-18 19:20:39 +02:00
|
|
|
#include "filter.h"
|
2013-11-10 17:55:40 +01:00
|
|
|
#include "libinput-private.h"
|
2011-01-14 14:45:42 -05:00
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
#define DEFAULT_AXIS_STEP_DISTANCE 10
|
2012-10-03 22:56:58 +02:00
|
|
|
|
2012-08-03 14:39:05 +03:00
|
|
|
void
|
2013-11-10 17:55:40 +01:00
|
|
|
evdev_device_led_update(struct evdev_device *device, enum libinput_led leds)
|
2012-05-30 16:31:49 +01:00
|
|
|
{
|
|
|
|
|
static const struct {
|
2013-11-10 17:55:40 +01:00
|
|
|
enum libinput_led weston;
|
2012-05-30 16:31:49 +01:00
|
|
|
int evdev;
|
|
|
|
|
} map[] = {
|
2013-11-10 17:55:40 +01:00
|
|
|
{ LIBINPUT_LED_NUM_LOCK, LED_NUML },
|
|
|
|
|
{ LIBINPUT_LED_CAPS_LOCK, LED_CAPSL },
|
|
|
|
|
{ LIBINPUT_LED_SCROLL_LOCK, LED_SCROLLL },
|
2012-05-30 16:31:49 +01:00
|
|
|
};
|
2013-08-09 16:32:17 +02:00
|
|
|
struct input_event ev[ARRAY_LENGTH(map) + 1];
|
2012-05-30 16:31:49 +01:00
|
|
|
unsigned int i;
|
|
|
|
|
|
2013-12-16 15:07:59 -08:00
|
|
|
if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD))
|
2012-08-06 14:57:07 +03:00
|
|
|
return;
|
|
|
|
|
|
2012-05-30 16:31:49 +01:00
|
|
|
memset(ev, 0, sizeof(ev));
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(map); i++) {
|
|
|
|
|
ev[i].type = EV_LED;
|
|
|
|
|
ev[i].code = map[i].evdev;
|
|
|
|
|
ev[i].value = !!(leds & map[i].weston);
|
|
|
|
|
}
|
2013-08-09 16:32:17 +02:00
|
|
|
ev[i].type = EV_SYN;
|
|
|
|
|
ev[i].code = SYN_REPORT;
|
2012-05-30 16:31:49 +01:00
|
|
|
|
2012-08-06 14:57:07 +03:00
|
|
|
i = write(device->fd, ev, sizeof ev);
|
|
|
|
|
(void)i; /* no, we really don't care about the return value */
|
2012-05-30 16:31:49 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-24 12:09:03 +01:00
|
|
|
static void
|
|
|
|
|
transform_absolute(struct evdev_device *device, int32_t *x, int32_t *y)
|
|
|
|
|
{
|
2013-11-10 17:55:40 +01:00
|
|
|
if (!device->abs.apply_calibration) {
|
|
|
|
|
*x = device->abs.x;
|
|
|
|
|
*y = device->abs.y;
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
*x = device->abs.x * device->abs.calibration[0] +
|
|
|
|
|
device->abs.y * device->abs.calibration[1] +
|
|
|
|
|
device->abs.calibration[2];
|
|
|
|
|
|
|
|
|
|
*y = device->abs.x * device->abs.calibration[3] +
|
|
|
|
|
device->abs.y * device->abs.calibration[4] +
|
|
|
|
|
device->abs.calibration[5];
|
|
|
|
|
}
|
2013-09-24 12:09:03 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-19 11:11:36 +10:00
|
|
|
static inline double
|
|
|
|
|
scale_axis(const struct input_absinfo *absinfo, double val, double to_range)
|
|
|
|
|
{
|
|
|
|
|
return (val - absinfo->minimum) * to_range /
|
|
|
|
|
(absinfo->maximum - absinfo->minimum + 1);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
double
|
2014-01-25 11:53:53 +01:00
|
|
|
evdev_device_transform_x(struct evdev_device *device,
|
2014-06-02 23:09:27 +02:00
|
|
|
double x,
|
2014-01-25 11:53:53 +01:00
|
|
|
uint32_t width)
|
|
|
|
|
{
|
2014-06-19 11:11:36 +10:00
|
|
|
return scale_axis(device->abs.absinfo_x, x, width);
|
2014-01-25 11:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
double
|
2014-01-25 11:53:53 +01:00
|
|
|
evdev_device_transform_y(struct evdev_device *device,
|
2014-06-02 23:09:27 +02:00
|
|
|
double y,
|
2014-01-25 11:53:53 +01:00
|
|
|
uint32_t height)
|
|
|
|
|
{
|
2014-06-19 11:11:36 +10:00
|
|
|
return scale_axis(device->abs.absinfo_y, y, height);
|
2014-01-25 11:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-24 12:09:03 +01:00
|
|
|
static void
|
2014-04-08 12:29:45 +02:00
|
|
|
evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
|
2013-09-24 12:09:03 +01:00
|
|
|
{
|
2014-05-18 19:20:39 +02:00
|
|
|
struct motion_params motion;
|
2013-09-24 12:09:03 +01:00
|
|
|
int32_t cx, cy;
|
2014-06-02 23:09:27 +02:00
|
|
|
double x, y;
|
2013-09-24 12:09:03 +01:00
|
|
|
int slot;
|
2014-01-30 22:44:49 +01:00
|
|
|
int seat_slot;
|
2013-11-10 17:55:40 +01:00
|
|
|
struct libinput_device *base = &device->base;
|
2014-01-30 22:44:49 +01:00
|
|
|
struct libinput_seat *seat = base->seat;
|
2013-09-24 12:09:03 +01:00
|
|
|
|
|
|
|
|
slot = device->mt.slot;
|
|
|
|
|
|
|
|
|
|
switch (device->pending_event) {
|
|
|
|
|
case EVDEV_NONE:
|
|
|
|
|
return;
|
|
|
|
|
case EVDEV_RELATIVE_MOTION:
|
2014-06-02 23:09:27 +02:00
|
|
|
motion.dx = device->rel.dx;
|
|
|
|
|
motion.dy = device->rel.dy;
|
2013-09-24 12:09:03 +01:00
|
|
|
device->rel.dx = 0;
|
|
|
|
|
device->rel.dy = 0;
|
2014-05-18 19:20:39 +02:00
|
|
|
|
|
|
|
|
/* Apply pointer acceleration. */
|
|
|
|
|
filter_dispatch(device->pointer.filter, &motion, device, time);
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
if (motion.dx == 0.0 && motion.dy == 0.0)
|
2014-05-18 19:20:39 +02:00
|
|
|
break;
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
pointer_notify_motion(base, time, motion.dx, motion.dy);
|
2014-01-27 23:33:46 +01:00
|
|
|
break;
|
2013-09-24 12:09:03 +01:00
|
|
|
case EVDEV_ABSOLUTE_MT_DOWN:
|
2014-01-27 23:33:46 +01:00
|
|
|
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
|
|
|
|
|
break;
|
|
|
|
|
|
2014-03-24 23:37:09 +01:00
|
|
|
if (device->mt.slots[slot].seat_slot != -1) {
|
2014-05-21 14:36:01 +10:00
|
|
|
log_bug_kernel("%s: Driver sent multiple touch down for the "
|
|
|
|
|
"same slot", device->devnode);
|
2014-03-24 23:37:09 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 22:44:49 +01:00
|
|
|
seat_slot = ffs(~seat->slot_map) - 1;
|
|
|
|
|
device->mt.slots[slot].seat_slot = seat_slot;
|
|
|
|
|
|
|
|
|
|
if (seat_slot == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
seat->slot_map |= 1 << seat_slot;
|
2014-06-02 23:09:27 +02:00
|
|
|
x = device->mt.slots[slot].x;
|
|
|
|
|
y = device->mt.slots[slot].y;
|
2014-01-30 22:44:49 +01:00
|
|
|
|
2014-02-19 21:39:26 +01:00
|
|
|
touch_notify_touch_down(base, time, slot, seat_slot, x, y);
|
2014-01-27 23:33:46 +01:00
|
|
|
break;
|
2013-09-24 12:09:03 +01:00
|
|
|
case EVDEV_ABSOLUTE_MT_MOTION:
|
2014-01-27 23:33:46 +01:00
|
|
|
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
|
|
|
|
|
break;
|
|
|
|
|
|
2014-01-30 22:44:49 +01:00
|
|
|
seat_slot = device->mt.slots[slot].seat_slot;
|
2014-06-02 23:09:27 +02:00
|
|
|
x = device->mt.slots[slot].x;
|
|
|
|
|
y = device->mt.slots[slot].y;
|
2014-01-30 22:44:49 +01:00
|
|
|
|
|
|
|
|
if (seat_slot == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
2014-02-19 21:39:26 +01:00
|
|
|
touch_notify_touch_motion(base, time, slot, seat_slot, x, y);
|
2014-01-27 23:33:46 +01:00
|
|
|
break;
|
2013-09-24 12:09:03 +01:00
|
|
|
case EVDEV_ABSOLUTE_MT_UP:
|
2014-01-27 23:33:46 +01:00
|
|
|
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
|
|
|
|
|
break;
|
|
|
|
|
|
2014-01-30 22:44:49 +01:00
|
|
|
seat_slot = device->mt.slots[slot].seat_slot;
|
2014-03-24 23:37:09 +01:00
|
|
|
device->mt.slots[slot].seat_slot = -1;
|
2014-01-30 22:44:49 +01:00
|
|
|
|
|
|
|
|
if (seat_slot == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
seat->slot_map &= ~(1 << seat_slot);
|
|
|
|
|
|
2014-02-19 21:39:26 +01:00
|
|
|
touch_notify_touch_up(base, time, slot, seat_slot);
|
2014-01-27 23:33:46 +01:00
|
|
|
break;
|
2013-09-24 20:05:07 +01:00
|
|
|
case EVDEV_ABSOLUTE_TOUCH_DOWN:
|
2014-01-27 23:33:46 +01:00
|
|
|
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
|
|
|
|
|
break;
|
|
|
|
|
|
2014-03-24 23:37:09 +01:00
|
|
|
if (device->abs.seat_slot != -1) {
|
2014-05-21 14:36:01 +10:00
|
|
|
log_bug_kernel("%s: Driver sent multiple touch down for the "
|
|
|
|
|
"same slot", device->devnode);
|
2014-03-24 23:37:09 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 22:44:49 +01:00
|
|
|
seat_slot = ffs(~seat->slot_map) - 1;
|
|
|
|
|
device->abs.seat_slot = seat_slot;
|
|
|
|
|
|
|
|
|
|
if (seat_slot == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
seat->slot_map |= 1 << seat_slot;
|
|
|
|
|
|
2013-09-24 20:05:07 +01:00
|
|
|
transform_absolute(device, &cx, &cy);
|
2014-02-19 21:39:26 +01:00
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
touch_notify_touch_down(base, time, -1, seat_slot, cx, cy);
|
2014-01-27 23:33:46 +01:00
|
|
|
break;
|
2013-09-24 12:09:03 +01:00
|
|
|
case EVDEV_ABSOLUTE_MOTION:
|
|
|
|
|
transform_absolute(device, &cx, &cy);
|
2014-06-02 23:09:27 +02:00
|
|
|
x = cx;
|
|
|
|
|
y = cy;
|
2014-02-19 21:39:26 +01:00
|
|
|
|
2013-12-16 15:19:30 -08:00
|
|
|
if (device->seat_caps & EVDEV_DEVICE_TOUCH) {
|
2014-01-30 22:44:49 +01:00
|
|
|
seat_slot = device->abs.seat_slot;
|
|
|
|
|
|
|
|
|
|
if (seat_slot == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
2014-02-19 21:39:26 +01:00
|
|
|
touch_notify_touch_motion(base, time, -1, seat_slot, x, y);
|
2013-12-16 15:51:22 -08:00
|
|
|
} else if (device->seat_caps & EVDEV_DEVICE_POINTER) {
|
2014-02-19 21:39:26 +01:00
|
|
|
pointer_notify_motion_absolute(base, time, x, y);
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
2014-01-27 23:33:46 +01:00
|
|
|
break;
|
2013-09-24 20:05:07 +01:00
|
|
|
case EVDEV_ABSOLUTE_TOUCH_UP:
|
2014-01-27 23:33:46 +01:00
|
|
|
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
|
|
|
|
|
break;
|
|
|
|
|
|
2014-01-30 22:44:49 +01:00
|
|
|
seat_slot = device->abs.seat_slot;
|
2014-03-24 23:37:09 +01:00
|
|
|
device->abs.seat_slot = -1;
|
2014-01-30 22:44:49 +01:00
|
|
|
|
|
|
|
|
if (seat_slot == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
seat->slot_map &= ~(1 << seat_slot);
|
|
|
|
|
|
2014-02-19 21:39:26 +01:00
|
|
|
touch_notify_touch_up(base, time, -1, seat_slot);
|
2014-01-27 23:33:46 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0 && "Unknown pending event type");
|
|
|
|
|
break;
|
2013-09-24 12:09:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
device->pending_event = EVDEV_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-24 20:05:07 +01:00
|
|
|
static void
|
2014-06-09 22:26:22 +02:00
|
|
|
evdev_process_touch_button(struct evdev_device *device,
|
|
|
|
|
uint64_t time, int value)
|
2013-09-24 20:05:07 +01:00
|
|
|
{
|
|
|
|
|
if (device->pending_event != EVDEV_NONE &&
|
|
|
|
|
device->pending_event != EVDEV_ABSOLUTE_MOTION)
|
|
|
|
|
evdev_flush_pending_event(device, time);
|
|
|
|
|
|
|
|
|
|
device->pending_event = (value ?
|
|
|
|
|
EVDEV_ABSOLUTE_TOUCH_DOWN :
|
|
|
|
|
EVDEV_ABSOLUTE_TOUCH_UP);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-01 19:00:03 +03:00
|
|
|
static inline void
|
2014-06-09 22:26:22 +02:00
|
|
|
evdev_process_key(struct evdev_device *device,
|
|
|
|
|
struct input_event *e, uint64_t time)
|
2011-09-01 19:00:03 +03:00
|
|
|
{
|
2013-08-07 11:04:42 +10:00
|
|
|
/* ignore kernel key repeat */
|
2011-11-10 14:47:30 +02:00
|
|
|
if (e->value == 2)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-04-01 21:57:45 +02:00
|
|
|
if (e->code > KEY_MAX)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-09-24 20:05:07 +01:00
|
|
|
if (e->code == BTN_TOUCH) {
|
|
|
|
|
if (!device->is_mt)
|
|
|
|
|
evdev_process_touch_button(device, time, e->value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-24 12:09:03 +01:00
|
|
|
evdev_flush_pending_event(device, time);
|
|
|
|
|
|
2011-09-01 19:00:03 +03:00
|
|
|
switch (e->code) {
|
|
|
|
|
case BTN_LEFT:
|
|
|
|
|
case BTN_RIGHT:
|
|
|
|
|
case BTN_MIDDLE:
|
|
|
|
|
case BTN_SIDE:
|
|
|
|
|
case BTN_EXTRA:
|
|
|
|
|
case BTN_FORWARD:
|
|
|
|
|
case BTN_BACK:
|
|
|
|
|
case BTN_TASK:
|
2013-11-10 17:55:40 +01:00
|
|
|
pointer_notify_button(
|
|
|
|
|
&device->base,
|
|
|
|
|
time,
|
|
|
|
|
e->code,
|
2014-06-03 20:08:02 -04:00
|
|
|
e->value ? LIBINPUT_BUTTON_STATE_PRESSED :
|
|
|
|
|
LIBINPUT_BUTTON_STATE_RELEASED);
|
2011-09-01 19:00:03 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2014-04-01 21:57:45 +02:00
|
|
|
/* Only let KEY_* codes pass through. */
|
|
|
|
|
if (!(e->code <= KEY_MICMUTE ||
|
|
|
|
|
(e->code >= KEY_OK && e->code <= KEY_LIGHTS_TOGGLE)))
|
|
|
|
|
break;
|
|
|
|
|
|
2013-11-10 17:55:40 +01:00
|
|
|
keyboard_notify_key(
|
|
|
|
|
&device->base,
|
|
|
|
|
time,
|
|
|
|
|
e->code,
|
2014-06-17 07:55:35 +10:00
|
|
|
e->value ? LIBINPUT_KEY_STATE_PRESSED :
|
|
|
|
|
LIBINPUT_KEY_STATE_RELEASED);
|
2011-09-01 19:00:03 +03:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 19:34:09 +02:00
|
|
|
static void
|
2013-09-24 12:09:03 +01:00
|
|
|
evdev_process_touch(struct evdev_device *device,
|
|
|
|
|
struct input_event *e,
|
2014-04-08 12:29:45 +02:00
|
|
|
uint64_t time)
|
2011-12-21 19:34:09 +02:00
|
|
|
{
|
|
|
|
|
switch (e->code) {
|
|
|
|
|
case ABS_MT_SLOT:
|
2013-09-24 12:09:03 +01:00
|
|
|
evdev_flush_pending_event(device, time);
|
2011-12-21 22:18:36 -05:00
|
|
|
device->mt.slot = e->value;
|
2011-12-21 19:34:09 +02:00
|
|
|
break;
|
|
|
|
|
case ABS_MT_TRACKING_ID:
|
2013-09-24 12:09:03 +01:00
|
|
|
if (device->pending_event != EVDEV_NONE &&
|
|
|
|
|
device->pending_event != EVDEV_ABSOLUTE_MT_MOTION)
|
|
|
|
|
evdev_flush_pending_event(device, time);
|
2011-12-21 19:34:09 +02:00
|
|
|
if (e->value >= 0)
|
2013-09-24 12:09:03 +01:00
|
|
|
device->pending_event = EVDEV_ABSOLUTE_MT_DOWN;
|
2011-12-21 19:34:09 +02:00
|
|
|
else
|
2013-09-24 12:09:03 +01:00
|
|
|
device->pending_event = EVDEV_ABSOLUTE_MT_UP;
|
2011-12-21 19:34:09 +02:00
|
|
|
break;
|
|
|
|
|
case ABS_MT_POSITION_X:
|
2014-01-25 11:53:53 +01:00
|
|
|
device->mt.slots[device->mt.slot].x = e->value;
|
2013-09-24 12:09:03 +01:00
|
|
|
if (device->pending_event == EVDEV_NONE)
|
|
|
|
|
device->pending_event = EVDEV_ABSOLUTE_MT_MOTION;
|
2011-12-21 19:34:09 +02:00
|
|
|
break;
|
|
|
|
|
case ABS_MT_POSITION_Y:
|
2014-01-25 11:53:53 +01:00
|
|
|
device->mt.slots[device->mt.slot].y = e->value;
|
2013-09-24 12:09:03 +01:00
|
|
|
if (device->pending_event == EVDEV_NONE)
|
|
|
|
|
device->pending_event = EVDEV_ABSOLUTE_MT_MOTION;
|
2011-12-21 19:34:09 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-01 19:00:03 +03:00
|
|
|
static inline void
|
2012-08-06 14:57:08 +03:00
|
|
|
evdev_process_absolute_motion(struct evdev_device *device,
|
2011-12-21 22:18:36 -05:00
|
|
|
struct input_event *e)
|
2011-09-01 19:00:03 +03:00
|
|
|
{
|
|
|
|
|
switch (e->code) {
|
|
|
|
|
case ABS_X:
|
2014-01-25 11:53:53 +01:00
|
|
|
device->abs.x = e->value;
|
2013-09-24 12:09:03 +01:00
|
|
|
if (device->pending_event == EVDEV_NONE)
|
|
|
|
|
device->pending_event = EVDEV_ABSOLUTE_MOTION;
|
2011-09-01 19:00:03 +03:00
|
|
|
break;
|
|
|
|
|
case ABS_Y:
|
2014-01-25 11:53:53 +01:00
|
|
|
device->abs.y = e->value;
|
2013-09-24 12:09:03 +01:00
|
|
|
if (device->pending_event == EVDEV_NONE)
|
|
|
|
|
device->pending_event = EVDEV_ABSOLUTE_MOTION;
|
2011-09-01 19:00:03 +03:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
2012-08-06 14:57:08 +03:00
|
|
|
evdev_process_relative(struct evdev_device *device,
|
2014-04-08 12:29:45 +02:00
|
|
|
struct input_event *e, uint64_t time)
|
2011-09-01 19:00:03 +03:00
|
|
|
{
|
2013-11-10 17:55:40 +01:00
|
|
|
struct libinput_device *base = &device->base;
|
|
|
|
|
|
2011-09-01 19:00:03 +03:00
|
|
|
switch (e->code) {
|
|
|
|
|
case REL_X:
|
2013-09-24 12:09:03 +01:00
|
|
|
if (device->pending_event != EVDEV_RELATIVE_MOTION)
|
|
|
|
|
evdev_flush_pending_event(device, time);
|
2014-06-02 23:09:27 +02:00
|
|
|
device->rel.dx += e->value;
|
2013-09-24 12:09:03 +01:00
|
|
|
device->pending_event = EVDEV_RELATIVE_MOTION;
|
2011-09-01 19:00:03 +03:00
|
|
|
break;
|
|
|
|
|
case REL_Y:
|
2013-09-24 12:09:03 +01:00
|
|
|
if (device->pending_event != EVDEV_RELATIVE_MOTION)
|
|
|
|
|
evdev_flush_pending_event(device, time);
|
2014-06-02 23:09:27 +02:00
|
|
|
device->rel.dy += e->value;
|
2013-09-24 12:09:03 +01:00
|
|
|
device->pending_event = EVDEV_RELATIVE_MOTION;
|
2011-09-01 19:00:03 +03:00
|
|
|
break;
|
2012-03-22 10:47:01 -06:00
|
|
|
case REL_WHEEL:
|
2013-09-24 12:09:03 +01:00
|
|
|
evdev_flush_pending_event(device, time);
|
2014-01-21 15:48:06 +10:00
|
|
|
pointer_notify_axis(
|
|
|
|
|
base,
|
|
|
|
|
time,
|
2014-04-26 20:01:22 +10:00
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
|
2014-01-21 15:48:06 +10:00
|
|
|
-1 * e->value * DEFAULT_AXIS_STEP_DISTANCE);
|
2012-03-22 10:47:01 -06:00
|
|
|
break;
|
|
|
|
|
case REL_HWHEEL:
|
2013-09-24 12:09:03 +01:00
|
|
|
evdev_flush_pending_event(device, time);
|
2012-10-03 22:56:58 +02:00
|
|
|
switch (e->value) {
|
|
|
|
|
case -1:
|
|
|
|
|
/* Scroll left */
|
|
|
|
|
case 1:
|
|
|
|
|
/* Scroll right */
|
2013-11-10 17:55:40 +01:00
|
|
|
pointer_notify_axis(
|
|
|
|
|
base,
|
|
|
|
|
time,
|
2014-04-26 20:01:22 +10:00
|
|
|
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
|
2013-11-10 17:55:40 +01:00
|
|
|
e->value * DEFAULT_AXIS_STEP_DISTANCE);
|
2012-10-03 22:56:58 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
2011-09-01 19:00:03 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 19:34:09 +02:00
|
|
|
static inline void
|
2013-09-24 12:09:03 +01:00
|
|
|
evdev_process_absolute(struct evdev_device *device,
|
|
|
|
|
struct input_event *e,
|
2014-04-08 12:29:45 +02:00
|
|
|
uint64_t time)
|
2011-12-21 19:34:09 +02:00
|
|
|
{
|
2012-05-17 12:18:17 +02:00
|
|
|
if (device->is_mt) {
|
2013-09-24 12:09:03 +01:00
|
|
|
evdev_process_touch(device, e, time);
|
2011-12-21 19:34:09 +02:00
|
|
|
} else {
|
2011-12-21 22:18:36 -05:00
|
|
|
evdev_process_absolute_motion(device, e);
|
2011-12-21 19:34:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-20 10:15:00 +10:00
|
|
|
static inline int
|
|
|
|
|
evdev_need_touch_frame(struct evdev_device *device)
|
|
|
|
|
{
|
2014-01-27 23:33:46 +01:00
|
|
|
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2013-12-20 10:15:00 +10:00
|
|
|
switch (device->pending_event) {
|
|
|
|
|
case EVDEV_NONE:
|
|
|
|
|
case EVDEV_RELATIVE_MOTION:
|
|
|
|
|
break;
|
|
|
|
|
case EVDEV_ABSOLUTE_MT_DOWN:
|
|
|
|
|
case EVDEV_ABSOLUTE_MT_MOTION:
|
|
|
|
|
case EVDEV_ABSOLUTE_MT_UP:
|
|
|
|
|
case EVDEV_ABSOLUTE_TOUCH_DOWN:
|
|
|
|
|
case EVDEV_ABSOLUTE_TOUCH_UP:
|
|
|
|
|
case EVDEV_ABSOLUTE_MOTION:
|
2014-01-27 23:33:46 +01:00
|
|
|
return 1;
|
2013-12-20 10:15:00 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-17 12:18:16 +02:00
|
|
|
static void
|
|
|
|
|
fallback_process(struct evdev_dispatch *dispatch,
|
2012-08-06 14:57:08 +03:00
|
|
|
struct evdev_device *device,
|
2012-05-17 12:18:16 +02:00
|
|
|
struct input_event *event,
|
2014-04-08 12:29:45 +02:00
|
|
|
uint64_t time)
|
2012-05-17 12:18:16 +02:00
|
|
|
{
|
2013-12-20 10:15:00 +10:00
|
|
|
int need_frame = 0;
|
|
|
|
|
|
2012-05-17 12:18:16 +02:00
|
|
|
switch (event->type) {
|
|
|
|
|
case EV_REL:
|
|
|
|
|
evdev_process_relative(device, event, time);
|
|
|
|
|
break;
|
|
|
|
|
case EV_ABS:
|
2013-09-24 12:09:03 +01:00
|
|
|
evdev_process_absolute(device, event, time);
|
2012-05-17 12:18:16 +02:00
|
|
|
break;
|
|
|
|
|
case EV_KEY:
|
|
|
|
|
evdev_process_key(device, event, time);
|
|
|
|
|
break;
|
2013-02-27 15:26:23 -05:00
|
|
|
case EV_SYN:
|
2013-12-20 10:15:00 +10:00
|
|
|
need_frame = evdev_need_touch_frame(device);
|
2013-09-24 12:09:03 +01:00
|
|
|
evdev_flush_pending_event(device, time);
|
2013-12-20 10:15:00 +10:00
|
|
|
if (need_frame)
|
|
|
|
|
touch_notify_frame(&device->base, time);
|
2013-02-27 15:26:23 -05:00
|
|
|
break;
|
2012-05-17 12:18:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fallback_destroy(struct evdev_dispatch *dispatch)
|
|
|
|
|
{
|
|
|
|
|
free(dispatch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct evdev_dispatch_interface fallback_interface = {
|
|
|
|
|
fallback_process,
|
|
|
|
|
fallback_destroy
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct evdev_dispatch *
|
|
|
|
|
fallback_dispatch_create(void)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_dispatch *dispatch = malloc(sizeof *dispatch);
|
|
|
|
|
if (dispatch == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
dispatch->interface = &fallback_interface;
|
|
|
|
|
|
|
|
|
|
return dispatch;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 13:09:18 +10:00
|
|
|
static inline void
|
|
|
|
|
evdev_process_event(struct evdev_device *device, struct input_event *e)
|
2011-01-14 14:45:42 -05:00
|
|
|
{
|
2012-05-17 12:18:16 +02:00
|
|
|
struct evdev_dispatch *dispatch = device->dispatch;
|
2014-04-08 12:29:45 +02:00
|
|
|
uint64_t time = e->time.tv_sec * 1000ULL + e->time.tv_usec / 1000;
|
2011-01-14 14:45:42 -05:00
|
|
|
|
2013-12-06 13:09:18 +10:00
|
|
|
dispatch->interface->process(dispatch, device, e, time);
|
|
|
|
|
}
|
2011-01-14 14:45:42 -05:00
|
|
|
|
2013-12-06 13:09:18 +10:00
|
|
|
static inline void
|
|
|
|
|
evdev_device_dispatch_one(struct evdev_device *device,
|
|
|
|
|
struct input_event *ev)
|
|
|
|
|
{
|
|
|
|
|
if (!device->mtdev) {
|
|
|
|
|
evdev_process_event(device, ev);
|
|
|
|
|
} else {
|
|
|
|
|
mtdev_put_event(device->mtdev, ev);
|
|
|
|
|
if (libevdev_event_is_code(ev, EV_SYN, SYN_REPORT)) {
|
|
|
|
|
while (!mtdev_empty(device->mtdev)) {
|
|
|
|
|
struct input_event e;
|
|
|
|
|
mtdev_get_event(device->mtdev, &e);
|
|
|
|
|
evdev_process_event(device, &e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-14 14:45:42 -05:00
|
|
|
}
|
2012-03-20 19:52:57 -04:00
|
|
|
}
|
|
|
|
|
|
2013-12-06 13:09:18 +10:00
|
|
|
static int
|
|
|
|
|
evdev_sync_device(struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
struct input_event ev;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
rc = libevdev_next_event(device->evdev,
|
|
|
|
|
LIBEVDEV_READ_FLAG_SYNC, &ev);
|
|
|
|
|
if (rc < 0)
|
|
|
|
|
break;
|
|
|
|
|
evdev_device_dispatch_one(device, &ev);
|
|
|
|
|
} while (rc == LIBEVDEV_READ_STATUS_SYNC);
|
|
|
|
|
|
|
|
|
|
return rc == -EAGAIN ? 0 : rc;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
static void
|
|
|
|
|
evdev_device_dispatch(void *data)
|
2012-03-20 19:52:57 -04:00
|
|
|
{
|
2013-11-17 11:19:50 +01:00
|
|
|
struct evdev_device *device = data;
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
struct libinput *libinput = device->base.seat->libinput;
|
2013-12-06 13:09:18 +10:00
|
|
|
struct input_event ev;
|
|
|
|
|
int rc;
|
2012-03-20 19:52:57 -04:00
|
|
|
|
|
|
|
|
/* If the compositor is repainting, this function is called only once
|
|
|
|
|
* per frame and we have to process all the events available on the
|
|
|
|
|
* fd, otherwise there will be input lag. */
|
|
|
|
|
do {
|
2013-12-06 13:09:18 +10:00
|
|
|
rc = libevdev_next_event(device->evdev,
|
|
|
|
|
LIBEVDEV_READ_FLAG_NORMAL, &ev);
|
|
|
|
|
if (rc == LIBEVDEV_READ_STATUS_SYNC) {
|
|
|
|
|
/* send one more sync event so we handle all
|
|
|
|
|
currently pending events before we sync up
|
|
|
|
|
to the current state */
|
|
|
|
|
ev.code = SYN_REPORT;
|
|
|
|
|
evdev_device_dispatch_one(device, &ev);
|
|
|
|
|
|
|
|
|
|
rc = evdev_sync_device(device);
|
|
|
|
|
if (rc == 0)
|
|
|
|
|
rc = LIBEVDEV_READ_STATUS_SUCCESS;
|
|
|
|
|
} else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) {
|
|
|
|
|
evdev_device_dispatch_one(device, &ev);
|
2012-03-20 19:52:57 -04:00
|
|
|
}
|
2013-12-06 13:09:18 +10:00
|
|
|
} while (rc == LIBEVDEV_READ_STATUS_SUCCESS);
|
2012-03-20 19:52:57 -04:00
|
|
|
|
2013-12-06 13:09:18 +10:00
|
|
|
if (rc != -EAGAIN && rc != -EINTR) {
|
|
|
|
|
libinput_remove_source(libinput, device->source);
|
|
|
|
|
device->source = NULL;
|
|
|
|
|
}
|
2011-01-14 14:45:42 -05:00
|
|
|
}
|
|
|
|
|
|
2014-05-18 19:20:39 +02:00
|
|
|
static int
|
|
|
|
|
configure_pointer_acceleration(struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
device->pointer.filter =
|
|
|
|
|
create_pointer_accelator_filter(
|
|
|
|
|
pointer_accel_profile_smooth_simple);
|
|
|
|
|
if (!device->pointer.filter)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-19 17:07:40 +03:00
|
|
|
static int
|
2013-12-16 11:01:56 -08:00
|
|
|
evdev_configure_device(struct evdev_device *device)
|
2011-08-19 15:06:20 +03:00
|
|
|
{
|
2014-03-24 23:12:36 +01:00
|
|
|
struct libevdev *evdev = device->evdev;
|
2013-12-06 12:01:47 +10:00
|
|
|
const struct input_absinfo *absinfo;
|
2014-06-19 11:17:10 +10:00
|
|
|
struct input_absinfo fixed;
|
2013-12-16 15:37:16 -08:00
|
|
|
int has_abs, has_rel, has_mt;
|
2013-12-16 15:19:30 -08:00
|
|
|
int has_button, has_keyboard, has_touch;
|
2014-04-22 23:02:14 +02:00
|
|
|
struct mt_slot *slots;
|
|
|
|
|
int num_slots;
|
|
|
|
|
int active_slot;
|
|
|
|
|
int slot;
|
2012-05-30 16:31:48 +01:00
|
|
|
unsigned int i;
|
2011-08-19 17:07:40 +03:00
|
|
|
|
2013-12-16 11:25:19 -08:00
|
|
|
has_rel = 0;
|
2011-08-19 17:07:40 +03:00
|
|
|
has_abs = 0;
|
2013-12-16 13:42:40 -08:00
|
|
|
has_mt = 0;
|
2013-12-16 14:43:29 -08:00
|
|
|
has_button = 0;
|
2013-12-16 15:07:59 -08:00
|
|
|
has_keyboard = 0;
|
2013-12-16 15:19:30 -08:00
|
|
|
has_touch = 0;
|
2011-08-19 15:06:20 +03:00
|
|
|
|
2014-03-24 23:12:36 +01:00
|
|
|
if (libevdev_has_event_type(evdev, EV_ABS)) {
|
2013-08-13 14:55:39 -07:00
|
|
|
|
2014-03-24 23:12:36 +01:00
|
|
|
if ((absinfo = libevdev_get_abs_info(evdev, ABS_X))) {
|
2014-06-19 11:17:10 +10:00
|
|
|
if (absinfo->resolution == 0) {
|
|
|
|
|
fixed = *absinfo;
|
|
|
|
|
fixed.resolution = 1;
|
|
|
|
|
libevdev_set_abs_info(evdev, ABS_X, &fixed);
|
|
|
|
|
}
|
2014-06-19 11:11:36 +10:00
|
|
|
device->abs.absinfo_x = absinfo;
|
2013-12-16 13:42:40 -08:00
|
|
|
has_abs = 1;
|
2011-08-19 15:06:20 +03:00
|
|
|
}
|
2014-03-24 23:12:36 +01:00
|
|
|
if ((absinfo = libevdev_get_abs_info(evdev, ABS_Y))) {
|
2014-06-19 11:17:10 +10:00
|
|
|
if (absinfo->resolution == 0) {
|
|
|
|
|
fixed = *absinfo;
|
|
|
|
|
fixed.resolution = 1;
|
|
|
|
|
libevdev_set_abs_info(evdev, ABS_Y, &fixed);
|
|
|
|
|
}
|
2014-06-19 11:11:36 +10:00
|
|
|
device->abs.absinfo_y = absinfo;
|
2013-12-16 13:42:40 -08:00
|
|
|
has_abs = 1;
|
2011-08-19 15:06:20 +03:00
|
|
|
}
|
2013-08-08 12:03:08 +10:00
|
|
|
/* We only handle the slotted Protocol B in weston.
|
|
|
|
|
Devices with ABS_MT_POSITION_* but not ABS_MT_SLOT
|
|
|
|
|
require mtdev for conversion. */
|
2014-03-24 23:12:36 +01:00
|
|
|
if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) &&
|
|
|
|
|
libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y)) {
|
|
|
|
|
absinfo = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
|
2014-06-19 11:17:10 +10:00
|
|
|
if (absinfo->resolution == 0) {
|
|
|
|
|
fixed = *absinfo;
|
|
|
|
|
fixed.resolution = 1;
|
|
|
|
|
libevdev_set_abs_info(evdev,
|
|
|
|
|
ABS_MT_POSITION_X,
|
|
|
|
|
&fixed);
|
|
|
|
|
}
|
2014-06-19 11:11:36 +10:00
|
|
|
device->abs.absinfo_x = absinfo;
|
2014-03-24 23:12:36 +01:00
|
|
|
absinfo = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
|
2014-06-19 11:17:10 +10:00
|
|
|
if (absinfo->resolution == 0) {
|
|
|
|
|
fixed = *absinfo;
|
|
|
|
|
fixed.resolution = 1;
|
|
|
|
|
libevdev_set_abs_info(evdev,
|
|
|
|
|
ABS_MT_POSITION_Y,
|
|
|
|
|
&fixed);
|
|
|
|
|
}
|
2014-06-19 11:11:36 +10:00
|
|
|
device->abs.absinfo_y = absinfo;
|
2011-12-21 19:34:09 +02:00
|
|
|
device->is_mt = 1;
|
2013-12-16 15:19:30 -08:00
|
|
|
has_touch = 1;
|
2013-12-16 13:42:40 -08:00
|
|
|
has_mt = 1;
|
2013-08-07 11:04:45 +10:00
|
|
|
|
2014-03-24 23:12:36 +01:00
|
|
|
if (!libevdev_has_event_code(evdev,
|
|
|
|
|
EV_ABS, ABS_MT_SLOT)) {
|
2013-08-07 11:04:45 +10:00
|
|
|
device->mtdev = mtdev_new_open(device->fd);
|
2013-12-16 15:19:30 -08:00
|
|
|
if (!device->mtdev)
|
2014-02-06 09:26:00 +10:00
|
|
|
return -1;
|
2014-04-22 23:02:14 +02:00
|
|
|
|
|
|
|
|
num_slots = device->mtdev->caps.slot.maximum;
|
|
|
|
|
if (device->mtdev->caps.slot.minimum < 0 ||
|
|
|
|
|
num_slots <= 0)
|
|
|
|
|
return -1;
|
|
|
|
|
active_slot = device->mtdev->caps.slot.value;
|
2013-08-07 11:04:46 +10:00
|
|
|
} else {
|
2014-04-22 23:02:14 +02:00
|
|
|
num_slots = libevdev_get_num_slots(device->evdev);
|
|
|
|
|
active_slot = libevdev_get_current_slot(evdev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slots = calloc(num_slots, sizeof(struct mt_slot));
|
|
|
|
|
if (!slots)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
for (slot = 0; slot < num_slots; ++slot) {
|
|
|
|
|
slots[slot].seat_slot = -1;
|
|
|
|
|
slots[slot].x = 0;
|
|
|
|
|
slots[slot].y = 0;
|
2013-08-07 11:04:45 +10:00
|
|
|
}
|
2014-04-22 23:02:14 +02:00
|
|
|
device->mt.slots = slots;
|
|
|
|
|
device->mt.slots_len = num_slots;
|
|
|
|
|
device->mt.slot = active_slot;
|
2011-12-21 19:34:09 +02:00
|
|
|
}
|
2011-08-19 15:06:20 +03:00
|
|
|
}
|
2014-03-24 23:12:36 +01:00
|
|
|
if (libevdev_has_event_code(evdev, EV_REL, REL_X) ||
|
|
|
|
|
libevdev_has_event_code(evdev, EV_REL, REL_Y))
|
2014-04-21 19:20:44 +02:00
|
|
|
has_rel = 1;
|
2013-12-06 12:01:47 +10:00
|
|
|
|
2014-03-24 23:12:36 +01:00
|
|
|
if (libevdev_has_event_type(evdev, EV_KEY)) {
|
2014-05-29 15:43:38 +10:00
|
|
|
if (!libevdev_has_property(evdev, INPUT_PROP_DIRECT) &&
|
|
|
|
|
libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_FINGER) &&
|
2014-03-24 23:12:36 +01:00
|
|
|
!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN) &&
|
2013-12-16 13:42:40 -08:00
|
|
|
(has_abs || has_mt)) {
|
2014-02-17 15:40:09 +10:00
|
|
|
device->dispatch = evdev_mt_touchpad_create(device);
|
2014-04-11 16:27:01 -07:00
|
|
|
log_info("input device '%s', %s is a touchpad\n",
|
|
|
|
|
device->devname, device->devnode);
|
2013-08-07 11:04:49 +10:00
|
|
|
}
|
2012-05-30 16:31:48 +01:00
|
|
|
for (i = KEY_ESC; i < KEY_MAX; i++) {
|
|
|
|
|
if (i >= BTN_MISC && i < KEY_OK)
|
|
|
|
|
continue;
|
2014-03-24 23:12:36 +01:00
|
|
|
if (libevdev_has_event_code(evdev, EV_KEY, i)) {
|
2013-12-16 15:07:59 -08:00
|
|
|
has_keyboard = 1;
|
2012-05-30 16:31:48 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-24 23:12:36 +01:00
|
|
|
if (libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH))
|
2013-12-16 15:19:30 -08:00
|
|
|
has_touch = 1;
|
2013-10-14 15:28:01 -07:00
|
|
|
for (i = BTN_MISC; i < BTN_JOYSTICK; i++) {
|
2014-03-24 23:12:36 +01:00
|
|
|
if (libevdev_has_event_code(evdev, EV_KEY, i)) {
|
2013-12-16 14:43:29 -08:00
|
|
|
has_button = 1;
|
2012-05-30 16:31:48 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-19 15:06:20 +03:00
|
|
|
}
|
2014-03-24 23:12:36 +01:00
|
|
|
if (libevdev_has_event_type(evdev, EV_LED))
|
2013-12-16 15:07:59 -08:00
|
|
|
has_keyboard = 1;
|
2011-08-19 17:07:40 +03:00
|
|
|
|
2014-04-11 16:27:01 -07:00
|
|
|
if ((has_abs || has_rel) && has_button) {
|
2014-05-18 19:20:39 +02:00
|
|
|
if (configure_pointer_acceleration(device) == -1)
|
|
|
|
|
return -1;
|
|
|
|
|
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
device->seat_caps |= EVDEV_DEVICE_POINTER;
|
2014-05-18 19:20:39 +02:00
|
|
|
|
2014-04-11 16:27:01 -07:00
|
|
|
log_info("input device '%s', %s is a pointer caps =%s%s%s\n",
|
|
|
|
|
device->devname, device->devnode,
|
|
|
|
|
has_abs ? " absolute-motion" : "",
|
|
|
|
|
has_rel ? " relative-motion": "",
|
|
|
|
|
has_button ? " button" : "");
|
|
|
|
|
}
|
|
|
|
|
if (has_keyboard) {
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
device->seat_caps |= EVDEV_DEVICE_KEYBOARD;
|
2014-04-11 16:27:01 -07:00
|
|
|
log_info("input device '%s', %s is a keyboard\n",
|
|
|
|
|
device->devname, device->devnode);
|
|
|
|
|
}
|
|
|
|
|
if (has_touch && !has_button) {
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
device->seat_caps |= EVDEV_DEVICE_TOUCH;
|
2014-04-11 16:27:01 -07:00
|
|
|
log_info("input device '%s', %s is a touch device\n",
|
|
|
|
|
device->devname, device->devnode);
|
|
|
|
|
}
|
2013-12-16 11:01:56 -08:00
|
|
|
|
|
|
|
|
return 0;
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct evdev_device *
|
|
|
|
|
evdev_device_create(struct libinput_seat *seat,
|
|
|
|
|
const char *devnode,
|
2014-01-30 14:54:31 +10:00
|
|
|
const char *sysname)
|
2011-01-14 14:45:42 -05:00
|
|
|
{
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
struct libinput *libinput = seat->libinput;
|
2012-08-06 14:57:08 +03:00
|
|
|
struct evdev_device *device;
|
2013-12-06 12:01:47 +10:00
|
|
|
int rc;
|
2014-01-30 14:54:31 +10:00
|
|
|
int fd;
|
2014-02-10 15:40:49 +10:00
|
|
|
int unhandled_device = 0;
|
2014-01-30 14:54:31 +10:00
|
|
|
|
|
|
|
|
/* Use non-blocking mode so that we can loop on read on
|
|
|
|
|
* evdev_device_data() until all events on the fd are
|
|
|
|
|
* read. mtdev_get() also expects this. */
|
|
|
|
|
fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK);
|
|
|
|
|
if (fd < 0) {
|
|
|
|
|
log_info("opening input device '%s' failed (%s).\n",
|
|
|
|
|
devnode, strerror(-fd));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-01-14 14:45:42 -05:00
|
|
|
|
2013-08-08 11:57:05 +10:00
|
|
|
device = zalloc(sizeof *device);
|
2011-01-14 14:45:42 -05:00
|
|
|
if (device == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
libinput_device_init(&device->base, seat);
|
2011-09-01 13:25:50 -04:00
|
|
|
|
2013-12-06 12:01:47 +10:00
|
|
|
rc = libevdev_new_from_fd(fd, &device->evdev);
|
|
|
|
|
if (rc != 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2014-02-19 08:45:57 +10:00
|
|
|
libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC);
|
|
|
|
|
|
2013-10-17 23:04:05 +02:00
|
|
|
device->seat_caps = 0;
|
2011-12-21 19:34:09 +02:00
|
|
|
device->is_mt = 0;
|
2012-03-16 17:33:03 -03:00
|
|
|
device->mtdev = NULL;
|
2013-11-10 17:55:40 +01:00
|
|
|
device->devnode = strdup(devnode);
|
2013-12-15 17:50:04 +01:00
|
|
|
device->sysname = strdup(sysname);
|
2011-12-21 22:18:36 -05:00
|
|
|
device->rel.dx = 0;
|
|
|
|
|
device->rel.dy = 0;
|
2014-03-24 23:37:09 +01:00
|
|
|
device->abs.seat_slot = -1;
|
2012-05-17 12:18:16 +02:00
|
|
|
device->dispatch = NULL;
|
2013-11-10 17:55:40 +01:00
|
|
|
device->fd = fd;
|
2013-09-24 12:09:03 +01:00
|
|
|
device->pending_event = EVDEV_NONE;
|
2013-12-06 12:01:47 +10:00
|
|
|
device->devname = libevdev_get_name(device->evdev);
|
2012-08-03 14:39:07 +03:00
|
|
|
|
2014-01-22 23:48:39 +01:00
|
|
|
libinput_seat_ref(seat);
|
|
|
|
|
|
2013-12-16 11:01:56 -08:00
|
|
|
if (evdev_configure_device(device) == -1)
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
if (device->seat_caps == 0) {
|
2014-02-10 15:40:49 +10:00
|
|
|
unhandled_device = 1;
|
2014-01-22 23:43:45 +01:00
|
|
|
goto err;
|
2013-02-16 14:29:24 -05:00
|
|
|
}
|
|
|
|
|
|
2012-05-17 12:18:16 +02:00
|
|
|
/* If the dispatch was not set up use the fallback. */
|
|
|
|
|
if (device->dispatch == NULL)
|
|
|
|
|
device->dispatch = fallback_dispatch_create();
|
|
|
|
|
if (device->dispatch == NULL)
|
2013-08-07 11:04:48 +10:00
|
|
|
goto err;
|
2012-05-17 12:18:16 +02:00
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
device->source =
|
|
|
|
|
libinput_add_fd(libinput, fd, evdev_device_dispatch, device);
|
|
|
|
|
if (!device->source)
|
|
|
|
|
goto err;
|
|
|
|
|
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
list_insert(seat->devices_list.prev, &device->base.link);
|
|
|
|
|
notify_added_device(&device->base);
|
|
|
|
|
|
|
|
|
|
return device;
|
2011-10-28 13:15:25 -04:00
|
|
|
|
2013-08-07 11:04:48 +10:00
|
|
|
err:
|
2014-01-30 14:54:31 +10:00
|
|
|
if (fd >= 0)
|
|
|
|
|
close_restricted(libinput, fd);
|
2013-08-07 11:04:48 +10:00
|
|
|
evdev_device_destroy(device);
|
2014-02-10 15:40:49 +10:00
|
|
|
|
|
|
|
|
return unhandled_device ? EVDEV_UNHANDLED_DEVICE : NULL;
|
2011-01-14 14:45:42 -05:00
|
|
|
}
|
|
|
|
|
|
2013-11-10 17:55:40 +01:00
|
|
|
int
|
|
|
|
|
evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size)
|
|
|
|
|
{
|
2014-03-13 15:54:47 +10:00
|
|
|
int len;
|
|
|
|
|
|
2013-11-10 17:55:40 +01:00
|
|
|
memset(keys, 0, size);
|
2014-03-13 15:54:47 +10:00
|
|
|
len = ioctl(device->fd, EVIOCGKEY(size), keys);
|
|
|
|
|
|
|
|
|
|
return (len == -1) ? -errno : len;
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
const char *
|
|
|
|
|
evdev_device_get_output(struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
return device->output_name;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-15 17:50:04 +01:00
|
|
|
const char *
|
|
|
|
|
evdev_device_get_sysname(struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
return device->sysname;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 17:55:40 +01:00
|
|
|
void
|
|
|
|
|
evdev_device_calibrate(struct evdev_device *device, float calibration[6])
|
|
|
|
|
{
|
|
|
|
|
device->abs.apply_calibration = 1;
|
2013-12-05 18:32:36 +10:00
|
|
|
memcpy(device->abs.calibration, calibration, sizeof device->abs.calibration);
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-15 17:45:02 +01:00
|
|
|
int
|
|
|
|
|
evdev_device_has_capability(struct evdev_device *device,
|
|
|
|
|
enum libinput_device_capability capability)
|
|
|
|
|
{
|
|
|
|
|
switch (capability) {
|
|
|
|
|
case LIBINPUT_DEVICE_CAP_POINTER:
|
|
|
|
|
return !!(device->seat_caps & EVDEV_DEVICE_POINTER);
|
|
|
|
|
case LIBINPUT_DEVICE_CAP_KEYBOARD:
|
|
|
|
|
return !!(device->seat_caps & EVDEV_DEVICE_KEYBOARD);
|
|
|
|
|
case LIBINPUT_DEVICE_CAP_TOUCH:
|
|
|
|
|
return !!(device->seat_caps & EVDEV_DEVICE_TOUCH);
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-17 15:45:07 +10:00
|
|
|
int
|
|
|
|
|
evdev_device_get_size(struct evdev_device *device,
|
|
|
|
|
double *width,
|
|
|
|
|
double *height)
|
|
|
|
|
{
|
|
|
|
|
const struct input_absinfo *x, *y;
|
|
|
|
|
|
|
|
|
|
x = libevdev_get_abs_info(device->evdev, ABS_X);
|
|
|
|
|
y = libevdev_get_abs_info(device->evdev, ABS_Y);
|
|
|
|
|
|
|
|
|
|
if (!x || !y || !x->resolution || !y->resolution)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
*width = evdev_convert_to_mm(x, x->maximum);
|
|
|
|
|
*height = evdev_convert_to_mm(y, y->maximum);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-03 14:39:05 +03:00
|
|
|
void
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
evdev_device_remove(struct evdev_device *device)
|
2012-08-03 14:38:57 +03:00
|
|
|
{
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
if (device->source)
|
|
|
|
|
libinput_remove_source(device->base.seat->libinput,
|
|
|
|
|
device->source);
|
|
|
|
|
|
|
|
|
|
if (device->mtdev)
|
|
|
|
|
mtdev_close_delete(device->mtdev);
|
2014-01-30 14:54:31 +10:00
|
|
|
close_restricted(device->base.seat->libinput, device->fd);
|
2014-02-21 16:13:02 +10:00
|
|
|
device->fd = -1;
|
Port udev-seat to be used in libinput
This patch ports udev-seat from weston to libinput, including adapting
libinput internals and API to provide seat and device discovery.
The public API is extended with device discovery, object reference, a
seat object. As libinput takes care of creating and destroying its
objects user data getter/setter is added in order to make it possible
for the client to directly associate an object application side with an
object library side.
Device discovery API is made up of the 'seat added', 'seat removed',
'device added' and 'device removed' events. The seat added/removed
events contains a pointer to a libinput_seat struct, while the device
added/removed events contains a pointer to a libinput_device event.
The objects are reference counted with libinput holding one reference by
default. The application can increase the reference count with
libinput_seat_ref() and libinput_device_ref() and decrease the reference
count with libinput_seat_unref() and libinput_device_unref().
The basic event struct is changed to have a 'target' union parameter
that can be either a libinput, libinput_seat or libinput_device struct
pointer.
There is one known problem with the current API that is the potentially
racy initialization.
The problem is when a device is both discovered and lost during initial
dispatchig, causing libinput to first queue a 'added' message, creating
the device with default reference count 1, then before going back to the
application queuing a 'removed' message, while at same time decreasing
reference count of the device to 0, causing it o be destroyed. The queue
will at this state contain two messages with pointers to free:ed memory.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-11-23 13:04:32 +01:00
|
|
|
list_remove(&device->base.link);
|
|
|
|
|
|
|
|
|
|
notify_removed_device(&device->base);
|
|
|
|
|
libinput_device_unref(&device->base);
|
2013-11-17 16:59:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
evdev_device_destroy(struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_dispatch *dispatch;
|
2013-10-17 23:04:05 +02:00
|
|
|
|
2012-08-03 14:38:57 +03:00
|
|
|
dispatch = device->dispatch;
|
|
|
|
|
if (dispatch)
|
|
|
|
|
dispatch->interface->destroy(dispatch);
|
|
|
|
|
|
2014-05-18 19:20:39 +02:00
|
|
|
motion_filter_destroy(device->pointer.filter);
|
2014-01-22 23:48:39 +01:00
|
|
|
libinput_seat_unref(device->base.seat);
|
2013-12-06 12:01:47 +10:00
|
|
|
libevdev_free(device->evdev);
|
2014-04-22 23:02:14 +02:00
|
|
|
free(device->mt.slots);
|
2012-08-03 14:38:57 +03:00
|
|
|
free(device->devnode);
|
2013-12-15 17:50:04 +01:00
|
|
|
free(device->sysname);
|
2012-08-03 14:38:57 +03:00
|
|
|
free(device);
|
|
|
|
|
}
|