2013-11-10 17:55:40 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 Jonas Ådahl
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2013-12-05 17:26:40 +10:00
|
|
|
#include <errno.h>
|
2013-11-16 19:32:46 +01:00
|
|
|
#include <stdio.h>
|
2013-11-10 17:55:40 +01:00
|
|
|
#include <stdlib.h>
|
2013-11-16 19:32:46 +01:00
|
|
|
#include <string.h>
|
2013-11-17 11:19:50 +01:00
|
|
|
#include <sys/epoll.h>
|
|
|
|
|
#include <unistd.h>
|
2013-11-17 16:59:09 +01:00
|
|
|
#include <assert.h>
|
2013-11-10 17:55:40 +01:00
|
|
|
|
|
|
|
|
#include "libinput.h"
|
|
|
|
|
#include "libinput-private.h"
|
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
|
|
|
#include "evdev.h"
|
2014-06-06 17:01:05 +02:00
|
|
|
#include "timer.h"
|
2013-11-10 17:55:40 +01:00
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
struct libinput_source {
|
|
|
|
|
libinput_source_dispatch_t dispatch;
|
|
|
|
|
void *user_data;
|
|
|
|
|
int fd;
|
|
|
|
|
struct list link;
|
|
|
|
|
};
|
|
|
|
|
|
2013-12-08 12:36:27 +01:00
|
|
|
struct libinput_event {
|
|
|
|
|
enum libinput_event_type type;
|
2014-01-17 17:59:30 +10:00
|
|
|
struct libinput_device *device;
|
2013-12-08 12:36:27 +01:00
|
|
|
};
|
|
|
|
|
|
2014-01-15 17:10:30 +10:00
|
|
|
struct libinput_event_device_notify {
|
2013-12-08 12:36:27 +01:00
|
|
|
struct libinput_event base;
|
|
|
|
|
};
|
|
|
|
|
|
2013-12-19 16:40:48 +10:00
|
|
|
struct libinput_event_keyboard {
|
2013-12-08 12:36:27 +01:00
|
|
|
struct libinput_event base;
|
|
|
|
|
uint32_t time;
|
|
|
|
|
uint32_t key;
|
2014-04-01 21:57:45 +02:00
|
|
|
uint32_t seat_key_count;
|
2014-06-17 07:55:35 +10:00
|
|
|
enum libinput_key_state state;
|
2013-12-08 12:36:27 +01:00
|
|
|
};
|
|
|
|
|
|
2013-12-19 13:15:28 +10:00
|
|
|
struct libinput_event_pointer {
|
2013-12-08 12:36:27 +01:00
|
|
|
struct libinput_event base;
|
|
|
|
|
uint32_t time;
|
2014-06-02 23:09:27 +02:00
|
|
|
double x;
|
|
|
|
|
double y;
|
2013-12-08 12:36:27 +01:00
|
|
|
uint32_t button;
|
2014-04-01 21:57:45 +02:00
|
|
|
uint32_t seat_button_count;
|
2014-06-03 20:08:02 -04:00
|
|
|
enum libinput_button_state state;
|
2013-12-08 12:36:27 +01:00
|
|
|
enum libinput_pointer_axis axis;
|
2014-06-02 23:09:27 +02:00
|
|
|
double value;
|
2013-12-08 12:36:27 +01:00
|
|
|
};
|
|
|
|
|
|
2013-12-19 17:16:19 +10:00
|
|
|
struct libinput_event_touch {
|
2013-12-08 12:36:27 +01:00
|
|
|
struct libinput_event base;
|
|
|
|
|
uint32_t time;
|
2014-02-12 20:52:14 +01:00
|
|
|
int32_t slot;
|
2014-01-30 22:44:49 +01:00
|
|
|
int32_t seat_slot;
|
2014-06-02 23:09:27 +02:00
|
|
|
double x;
|
|
|
|
|
double y;
|
2013-12-08 12:36:27 +01:00
|
|
|
};
|
|
|
|
|
|
2014-02-12 14:20:18 +10:00
|
|
|
static void
|
2014-06-18 19:51:19 +10:00
|
|
|
libinput_default_log_func(struct libinput *libinput,
|
|
|
|
|
enum libinput_log_priority priority,
|
2014-02-12 14:20:18 +10:00
|
|
|
const char *format, va_list args)
|
|
|
|
|
{
|
|
|
|
|
const char *prefix;
|
|
|
|
|
|
|
|
|
|
switch(priority) {
|
|
|
|
|
case LIBINPUT_LOG_PRIORITY_DEBUG: prefix = "debug"; break;
|
|
|
|
|
case LIBINPUT_LOG_PRIORITY_INFO: prefix = "info"; break;
|
|
|
|
|
case LIBINPUT_LOG_PRIORITY_ERROR: prefix = "error"; break;
|
|
|
|
|
default: prefix="<invalid priority>"; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "libinput %s: ", prefix);
|
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-10 15:08:03 +02:00
|
|
|
void
|
2014-06-18 19:51:19 +10:00
|
|
|
log_msg_va(struct libinput *libinput,
|
|
|
|
|
enum libinput_log_priority priority,
|
2014-06-10 15:08:03 +02:00
|
|
|
const char *format,
|
|
|
|
|
va_list args)
|
|
|
|
|
{
|
2014-06-18 19:51:19 +10:00
|
|
|
if (libinput->log_handler &&
|
|
|
|
|
libinput->log_priority <= priority)
|
|
|
|
|
libinput->log_handler(libinput, priority, format, args);
|
2014-06-10 15:08:03 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-12 14:20:18 +10:00
|
|
|
void
|
2014-06-18 19:51:19 +10:00
|
|
|
log_msg(struct libinput *libinput,
|
|
|
|
|
enum libinput_log_priority priority,
|
|
|
|
|
const char *format, ...)
|
2014-02-12 14:20:18 +10:00
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
|
2014-06-10 15:08:03 +02:00
|
|
|
va_start(args, format);
|
2014-06-18 19:51:19 +10:00
|
|
|
log_msg_va(libinput, priority, format, args);
|
2014-06-10 15:08:03 +02:00
|
|
|
va_end(args);
|
2014-02-12 14:20:18 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT void
|
2014-06-18 19:51:19 +10:00
|
|
|
libinput_log_set_priority(struct libinput *libinput,
|
|
|
|
|
enum libinput_log_priority priority)
|
2014-02-12 14:20:18 +10:00
|
|
|
{
|
2014-06-18 19:51:19 +10:00
|
|
|
libinput->log_priority = priority;
|
2014-02-12 14:20:18 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT enum libinput_log_priority
|
2014-06-18 19:51:19 +10:00
|
|
|
libinput_log_get_priority(const struct libinput *libinput)
|
2014-02-12 14:20:18 +10:00
|
|
|
{
|
2014-06-18 19:51:19 +10:00
|
|
|
return libinput->log_priority;
|
2014-02-12 14:20:18 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT void
|
2014-06-18 19:51:19 +10:00
|
|
|
libinput_log_set_handler(struct libinput *libinput,
|
|
|
|
|
libinput_log_handler log_handler)
|
2014-02-12 14:20:18 +10:00
|
|
|
{
|
2014-06-18 19:51:19 +10:00
|
|
|
libinput->log_handler = log_handler;
|
2014-02-12 14:20:18 +10: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
|
|
|
static void
|
|
|
|
|
libinput_post_event(struct libinput *libinput,
|
|
|
|
|
struct libinput_event *event);
|
|
|
|
|
|
2013-12-08 12:36:27 +01:00
|
|
|
LIBINPUT_EXPORT enum libinput_event_type
|
|
|
|
|
libinput_event_get_type(struct libinput_event *event)
|
|
|
|
|
{
|
|
|
|
|
return event->type;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 11:33:09 +01:00
|
|
|
LIBINPUT_EXPORT struct libinput *
|
2013-12-19 11:22:53 +10:00
|
|
|
libinput_event_get_context(struct libinput_event *event)
|
|
|
|
|
{
|
2014-01-17 17:59:30 +10:00
|
|
|
return event->device->seat->libinput;
|
2013-12-08 12:36:27 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-25 11:33:09 +01:00
|
|
|
LIBINPUT_EXPORT struct libinput_device *
|
2014-01-17 17:59:30 +10:00
|
|
|
libinput_event_get_device(struct libinput_event *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->device;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 11:33:09 +01:00
|
|
|
LIBINPUT_EXPORT struct libinput_event_pointer *
|
2013-12-20 09:22:32 +10:00
|
|
|
libinput_event_get_pointer_event(struct libinput_event *event)
|
|
|
|
|
{
|
|
|
|
|
switch (event->type) {
|
|
|
|
|
case LIBINPUT_EVENT_NONE:
|
|
|
|
|
abort(); /* not used as actual event type */
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_REMOVED:
|
|
|
|
|
case LIBINPUT_EVENT_KEYBOARD_KEY:
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_BUTTON:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_AXIS:
|
2014-01-25 11:33:09 +01:00
|
|
|
return (struct libinput_event_pointer *) event;
|
2014-02-19 21:39:26 +01:00
|
|
|
case LIBINPUT_EVENT_TOUCH_DOWN:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_UP:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_MOTION:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_CANCEL:
|
2013-12-20 10:15:00 +10:00
|
|
|
case LIBINPUT_EVENT_TOUCH_FRAME:
|
2013-12-20 09:22:32 +10:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 11:33:09 +01:00
|
|
|
LIBINPUT_EXPORT struct libinput_event_keyboard *
|
2013-12-20 09:22:32 +10:00
|
|
|
libinput_event_get_keyboard_event(struct libinput_event *event)
|
|
|
|
|
{
|
|
|
|
|
switch (event->type) {
|
|
|
|
|
case LIBINPUT_EVENT_NONE:
|
|
|
|
|
abort(); /* not used as actual event type */
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_REMOVED:
|
|
|
|
|
break;
|
|
|
|
|
case LIBINPUT_EVENT_KEYBOARD_KEY:
|
2014-01-25 11:33:09 +01:00
|
|
|
return (struct libinput_event_keyboard *) event;
|
2013-12-20 09:22:32 +10:00
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_BUTTON:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_AXIS:
|
2014-02-19 21:39:26 +01:00
|
|
|
case LIBINPUT_EVENT_TOUCH_DOWN:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_UP:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_MOTION:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_CANCEL:
|
2013-12-20 10:15:00 +10:00
|
|
|
case LIBINPUT_EVENT_TOUCH_FRAME:
|
2013-12-20 09:22:32 +10:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 11:33:09 +01:00
|
|
|
LIBINPUT_EXPORT struct libinput_event_touch *
|
2013-12-20 09:22:32 +10:00
|
|
|
libinput_event_get_touch_event(struct libinput_event *event)
|
|
|
|
|
{
|
|
|
|
|
switch (event->type) {
|
|
|
|
|
case LIBINPUT_EVENT_NONE:
|
|
|
|
|
abort(); /* not used as actual event type */
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_REMOVED:
|
|
|
|
|
case LIBINPUT_EVENT_KEYBOARD_KEY:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_BUTTON:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_AXIS:
|
|
|
|
|
break;
|
2014-02-19 21:39:26 +01:00
|
|
|
case LIBINPUT_EVENT_TOUCH_DOWN:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_UP:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_MOTION:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_CANCEL:
|
2013-12-20 10:15:00 +10:00
|
|
|
case LIBINPUT_EVENT_TOUCH_FRAME:
|
2014-01-25 11:33:09 +01:00
|
|
|
return (struct libinput_event_touch *) event;
|
2013-12-20 09:22:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 11:33:09 +01:00
|
|
|
LIBINPUT_EXPORT struct libinput_event_device_notify *
|
2013-12-20 09:22:32 +10:00
|
|
|
libinput_event_get_device_notify_event(struct libinput_event *event)
|
|
|
|
|
{
|
|
|
|
|
switch (event->type) {
|
|
|
|
|
case LIBINPUT_EVENT_NONE:
|
|
|
|
|
abort(); /* not used as actual event type */
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_ADDED:
|
|
|
|
|
case LIBINPUT_EVENT_DEVICE_REMOVED:
|
2014-01-25 11:33:09 +01:00
|
|
|
return (struct libinput_event_device_notify *) event;
|
2013-12-20 09:22:32 +10:00
|
|
|
case LIBINPUT_EVENT_KEYBOARD_KEY:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_BUTTON:
|
|
|
|
|
case LIBINPUT_EVENT_POINTER_AXIS:
|
2014-02-19 21:39:26 +01:00
|
|
|
case LIBINPUT_EVENT_TOUCH_DOWN:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_UP:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_MOTION:
|
|
|
|
|
case LIBINPUT_EVENT_TOUCH_CANCEL:
|
2013-12-20 10:15:00 +10:00
|
|
|
case LIBINPUT_EVENT_TOUCH_FRAME:
|
2013-12-20 09:22:32 +10:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-08 12:36:27 +01:00
|
|
|
LIBINPUT_EXPORT uint32_t
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_keyboard_get_time(struct libinput_event_keyboard *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT uint32_t
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_keyboard_get_key(struct libinput_event_keyboard *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->key;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-17 07:55:35 +10:00
|
|
|
LIBINPUT_EXPORT enum libinput_key_state
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_keyboard_get_key_state(struct libinput_event_keyboard *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->state;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 21:57:45 +02:00
|
|
|
LIBINPUT_EXPORT uint32_t
|
|
|
|
|
libinput_event_keyboard_get_seat_key_count(
|
|
|
|
|
struct libinput_event_keyboard *event)
|
|
|
|
|
{
|
|
|
|
|
return event->seat_key_count;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-08 12:36:27 +01:00
|
|
|
LIBINPUT_EXPORT uint32_t
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_pointer_get_time(struct libinput_event_pointer *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->time;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_pointer_get_dx(struct libinput_event_pointer *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
2013-12-19 13:15:28 +10:00
|
|
|
return event->x;
|
2013-12-08 12:36:27 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_pointer_get_dy(struct libinput_event_pointer *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
2013-12-19 13:15:28 +10:00
|
|
|
return event->y;
|
2013-12-08 12:36:27 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_pointer_get_absolute_x(struct libinput_event_pointer *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
2014-06-19 11:30:21 +10:00
|
|
|
struct evdev_device *device =
|
|
|
|
|
(struct evdev_device *) event->base.device;
|
|
|
|
|
|
|
|
|
|
return evdev_convert_to_mm(device->abs.absinfo_x, event->x);
|
2013-12-08 12:36:27 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_pointer_get_absolute_y(struct libinput_event_pointer *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
2014-06-19 11:30:21 +10:00
|
|
|
struct evdev_device *device =
|
|
|
|
|
(struct evdev_device *) event->base.device;
|
|
|
|
|
|
|
|
|
|
return evdev_convert_to_mm(device->abs.absinfo_y, event->y);
|
2013-12-08 12:36:27 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-01-25 11:53:53 +01:00
|
|
|
libinput_event_pointer_get_absolute_x_transformed(
|
|
|
|
|
struct libinput_event_pointer *event,
|
|
|
|
|
uint32_t width)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_device *device =
|
|
|
|
|
(struct evdev_device *) event->base.device;
|
|
|
|
|
|
|
|
|
|
return evdev_device_transform_x(device, event->x, width);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-01-25 11:53:53 +01:00
|
|
|
libinput_event_pointer_get_absolute_y_transformed(
|
|
|
|
|
struct libinput_event_pointer *event,
|
|
|
|
|
uint32_t height)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_device *device =
|
|
|
|
|
(struct evdev_device *) event->base.device;
|
|
|
|
|
|
|
|
|
|
return evdev_device_transform_y(device, event->y, height);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-08 12:36:27 +01:00
|
|
|
LIBINPUT_EXPORT uint32_t
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_pointer_get_button(struct libinput_event_pointer *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->button;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-03 20:08:02 -04:00
|
|
|
LIBINPUT_EXPORT enum libinput_button_state
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_pointer_get_button_state(struct libinput_event_pointer *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->state;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 21:57:45 +02:00
|
|
|
LIBINPUT_EXPORT uint32_t
|
|
|
|
|
libinput_event_pointer_get_seat_button_count(
|
|
|
|
|
struct libinput_event_pointer *event)
|
|
|
|
|
{
|
|
|
|
|
return event->seat_button_count;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-08 12:36:27 +01:00
|
|
|
LIBINPUT_EXPORT enum libinput_pointer_axis
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_pointer_get_axis(struct libinput_event_pointer *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->axis;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT uint32_t
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_touch_get_time(struct libinput_event_touch *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->time;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-12 20:52:14 +01:00
|
|
|
LIBINPUT_EXPORT int32_t
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_touch_get_slot(struct libinput_event_touch *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
|
|
|
|
return event->slot;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 22:44:49 +01:00
|
|
|
LIBINPUT_EXPORT int32_t
|
|
|
|
|
libinput_event_touch_get_seat_slot(struct libinput_event_touch *event)
|
|
|
|
|
{
|
|
|
|
|
return event->seat_slot;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_touch_get_x(struct libinput_event_touch *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
2014-06-19 11:30:21 +10:00
|
|
|
struct evdev_device *device =
|
|
|
|
|
(struct evdev_device *) event->base.device;
|
|
|
|
|
|
|
|
|
|
return evdev_convert_to_mm(device->abs.absinfo_x, event->x);
|
2013-12-08 12:36:27 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_touch_get_x_transformed(struct libinput_event_touch *event,
|
|
|
|
|
uint32_t width)
|
2014-01-25 11:53:53 +01:00
|
|
|
{
|
|
|
|
|
struct evdev_device *device =
|
|
|
|
|
(struct evdev_device *) event->base.device;
|
|
|
|
|
|
|
|
|
|
return evdev_device_transform_x(device, event->x, width);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_touch_get_y_transformed(struct libinput_event_touch *event,
|
|
|
|
|
uint32_t height)
|
2014-01-25 11:53:53 +01:00
|
|
|
{
|
|
|
|
|
struct evdev_device *device =
|
|
|
|
|
(struct evdev_device *) event->base.device;
|
|
|
|
|
|
|
|
|
|
return evdev_device_transform_y(device, event->y, height);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-02 23:09:27 +02:00
|
|
|
LIBINPUT_EXPORT double
|
2014-02-11 23:29:34 +01:00
|
|
|
libinput_event_touch_get_y(struct libinput_event_touch *event)
|
2013-12-08 12:36:27 +01:00
|
|
|
{
|
2014-06-19 11:30:21 +10:00
|
|
|
struct evdev_device *device =
|
|
|
|
|
(struct evdev_device *) event->base.device;
|
|
|
|
|
|
|
|
|
|
return evdev_convert_to_mm(device->abs.absinfo_y, event->y);
|
2013-12-08 12:36:27 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
struct libinput_source *
|
|
|
|
|
libinput_add_fd(struct libinput *libinput,
|
|
|
|
|
int fd,
|
|
|
|
|
libinput_source_dispatch_t dispatch,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_source *source;
|
|
|
|
|
struct epoll_event ep;
|
|
|
|
|
|
|
|
|
|
source = malloc(sizeof *source);
|
|
|
|
|
if (!source)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
source->dispatch = dispatch;
|
|
|
|
|
source->user_data = user_data;
|
|
|
|
|
source->fd = fd;
|
|
|
|
|
|
|
|
|
|
memset(&ep, 0, sizeof ep);
|
|
|
|
|
ep.events = EPOLLIN;
|
|
|
|
|
ep.data.ptr = source;
|
|
|
|
|
|
|
|
|
|
if (epoll_ctl(libinput->epoll_fd, EPOLL_CTL_ADD, fd, &ep) < 0) {
|
|
|
|
|
close(source->fd);
|
|
|
|
|
free(source);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
libinput_remove_source(struct libinput *libinput,
|
|
|
|
|
struct libinput_source *source)
|
|
|
|
|
{
|
|
|
|
|
epoll_ctl(libinput->epoll_fd, EPOLL_CTL_DEL, source->fd, NULL);
|
|
|
|
|
source->fd = -1;
|
|
|
|
|
list_insert(&libinput->source_destroy_list, &source->link);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
int
|
|
|
|
|
libinput_init(struct libinput *libinput,
|
|
|
|
|
const struct libinput_interface *interface,
|
2013-12-13 11:37:31 +10:00
|
|
|
const struct libinput_interface_backend *interface_backend,
|
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
|
|
|
void *user_data)
|
2013-11-17 11:19:50 +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
|
|
|
libinput->epoll_fd = epoll_create1(EPOLL_CLOEXEC);;
|
|
|
|
|
if (libinput->epoll_fd < 0)
|
|
|
|
|
return -1;
|
2013-11-17 11:19:50 +01:00
|
|
|
|
2013-12-24 13:50:10 +10:00
|
|
|
libinput->events_len = 4;
|
|
|
|
|
libinput->events = zalloc(libinput->events_len * sizeof(*libinput->events));
|
|
|
|
|
if (!libinput->events) {
|
|
|
|
|
close(libinput->epoll_fd);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-18 19:51:19 +10:00
|
|
|
libinput->log_handler = libinput_default_log_func;
|
|
|
|
|
libinput->log_priority = LIBINPUT_LOG_PRIORITY_ERROR;
|
2013-11-17 19:31:34 +01:00
|
|
|
libinput->interface = interface;
|
2013-12-13 11:37:31 +10:00
|
|
|
libinput->interface_backend = interface_backend;
|
2013-11-17 19:31:34 +01:00
|
|
|
libinput->user_data = user_data;
|
2014-06-25 00:06:58 +02:00
|
|
|
libinput->refcount = 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_init(&libinput->source_destroy_list);
|
|
|
|
|
list_init(&libinput->seat_list);
|
2013-11-17 19:31:34 +01:00
|
|
|
|
2014-06-06 17:01:05 +02:00
|
|
|
if (libinput_timer_subsys_init(libinput) != 0) {
|
|
|
|
|
free(libinput->events);
|
|
|
|
|
close(libinput->epoll_fd);
|
|
|
|
|
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
|
|
|
return 0;
|
2013-11-17 11:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-31 16:11:03 +01:00
|
|
|
static void
|
|
|
|
|
libinput_device_destroy(struct libinput_device *device);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
libinput_seat_destroy(struct libinput_seat *seat);
|
|
|
|
|
|
2014-01-07 15:45:55 +10:00
|
|
|
static void
|
|
|
|
|
libinput_drop_destroyed_sources(struct libinput *libinput)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_source *source, *next;
|
|
|
|
|
|
|
|
|
|
list_for_each_safe(source, next, &libinput->source_destroy_list, link)
|
|
|
|
|
free(source);
|
|
|
|
|
list_init(&libinput->source_destroy_list);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 00:06:58 +02:00
|
|
|
LIBINPUT_EXPORT struct libinput *
|
|
|
|
|
libinput_ref(struct libinput *libinput)
|
|
|
|
|
{
|
|
|
|
|
libinput->refcount++;
|
|
|
|
|
return libinput;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT struct libinput *
|
|
|
|
|
libinput_unref(struct libinput *libinput)
|
2013-11-17 11:19:50 +01:00
|
|
|
{
|
|
|
|
|
struct libinput_event *event;
|
2013-12-16 22:52:05 +01:00
|
|
|
struct libinput_device *device, *next_device;
|
|
|
|
|
struct libinput_seat *seat, *next_seat;
|
2013-11-17 11:19:50 +01:00
|
|
|
|
2013-12-24 11:00:37 +10:00
|
|
|
if (libinput == NULL)
|
2014-06-25 00:06:58 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
assert(libinput->refcount > 0);
|
|
|
|
|
libinput->refcount--;
|
|
|
|
|
if (libinput->refcount > 0)
|
|
|
|
|
return libinput;
|
2013-12-24 11:00:37 +10:00
|
|
|
|
2014-01-07 14:54:55 +10:00
|
|
|
libinput_suspend(libinput);
|
|
|
|
|
|
2013-12-13 11:37:31 +10:00
|
|
|
libinput->interface_backend->destroy(libinput);
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
while ((event = libinput_get_event(libinput)))
|
2013-12-30 22:11:33 +01:00
|
|
|
libinput_event_destroy(event);
|
2014-01-07 15:45:55 +10:00
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
free(libinput->events);
|
|
|
|
|
|
2013-12-16 22:52:05 +01:00
|
|
|
list_for_each_safe(seat, next_seat, &libinput->seat_list, link) {
|
|
|
|
|
list_for_each_safe(device, next_device,
|
|
|
|
|
&seat->devices_list,
|
|
|
|
|
link)
|
2013-12-31 16:11:03 +01:00
|
|
|
libinput_device_destroy(device);
|
2013-12-16 22:52:05 +01:00
|
|
|
|
2013-12-31 16:11:03 +01:00
|
|
|
libinput_seat_destroy(seat);
|
2013-12-16 22:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-06 17:01:05 +02:00
|
|
|
libinput_timer_subsys_destroy(libinput);
|
|
|
|
|
libinput_drop_destroyed_sources(libinput);
|
2013-11-17 11:19:50 +01:00
|
|
|
close(libinput->epoll_fd);
|
|
|
|
|
free(libinput);
|
2014-06-25 00:06:58 +02:00
|
|
|
|
|
|
|
|
return NULL;
|
2013-11-17 11:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-21 13:56:12 +10:00
|
|
|
LIBINPUT_EXPORT void
|
|
|
|
|
libinput_event_destroy(struct libinput_event *event)
|
2013-12-07 16:41:43 +01:00
|
|
|
{
|
2014-01-21 13:56:12 +10:00
|
|
|
if (event == NULL)
|
|
|
|
|
return;
|
2013-12-13 17:49:38 +10:00
|
|
|
|
2014-01-22 23:45:44 +01:00
|
|
|
if (event->device)
|
2013-12-19 11:42:55 +10:00
|
|
|
libinput_device_unref(event->device);
|
2013-12-07 16:41:43 +01:00
|
|
|
|
|
|
|
|
free(event);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
int
|
|
|
|
|
open_restricted(struct libinput *libinput,
|
|
|
|
|
const char *path, int flags)
|
|
|
|
|
{
|
|
|
|
|
return libinput->interface->open_restricted(path,
|
|
|
|
|
flags,
|
|
|
|
|
libinput->user_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
close_restricted(struct libinput *libinput, int fd)
|
|
|
|
|
{
|
|
|
|
|
return libinput->interface->close_restricted(fd, libinput->user_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
libinput_seat_init(struct libinput_seat *seat,
|
|
|
|
|
struct libinput *libinput,
|
2014-01-15 17:04:00 +10:00
|
|
|
const char *physical_name,
|
|
|
|
|
const char *logical_name,
|
2013-12-13 11:37:31 +10:00
|
|
|
libinput_seat_destroy_func destroy)
|
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
|
|
|
{
|
|
|
|
|
seat->refcount = 1;
|
|
|
|
|
seat->libinput = libinput;
|
2014-01-15 17:04:00 +10:00
|
|
|
seat->physical_name = strdup(physical_name);
|
|
|
|
|
seat->logical_name = strdup(logical_name);
|
2013-12-13 11:37:31 +10:00
|
|
|
seat->destroy = destroy;
|
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_init(&seat->devices_list);
|
2014-02-10 11:40:55 +10:00
|
|
|
list_insert(&libinput->seat_list, &seat->link);
|
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
|
|
|
}
|
|
|
|
|
|
2014-06-25 00:06:57 +02:00
|
|
|
LIBINPUT_EXPORT struct libinput_seat *
|
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_seat_ref(struct libinput_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
seat->refcount++;
|
2014-06-25 00:06:57 +02:00
|
|
|
return seat;
|
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
|
|
|
}
|
|
|
|
|
|
2013-12-31 16:11:03 +01:00
|
|
|
static void
|
|
|
|
|
libinput_seat_destroy(struct libinput_seat *seat)
|
|
|
|
|
{
|
2013-12-13 11:37:31 +10:00
|
|
|
list_remove(&seat->link);
|
2014-01-15 17:04:00 +10:00
|
|
|
free(seat->logical_name);
|
|
|
|
|
free(seat->physical_name);
|
2013-12-13 11:37:31 +10:00
|
|
|
seat->destroy(seat);
|
2013-12-31 16:11:03 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-25 00:06:57 +02:00
|
|
|
LIBINPUT_EXPORT struct libinput_seat *
|
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_seat_unref(struct libinput_seat *seat)
|
|
|
|
|
{
|
2014-01-08 16:40:14 +10:00
|
|
|
assert(seat->refcount > 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
|
|
|
seat->refcount--;
|
2014-06-25 00:06:57 +02:00
|
|
|
if (seat->refcount == 0) {
|
2013-12-31 16:11:03 +01:00
|
|
|
libinput_seat_destroy(seat);
|
2014-06-25 00:06:57 +02:00
|
|
|
return NULL;
|
|
|
|
|
} else {
|
|
|
|
|
return seat;
|
|
|
|
|
}
|
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_EXPORT void
|
|
|
|
|
libinput_seat_set_user_data(struct libinput_seat *seat, void *user_data)
|
|
|
|
|
{
|
|
|
|
|
seat->user_data = user_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT void *
|
|
|
|
|
libinput_seat_get_user_data(struct libinput_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
return seat->user_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT const char *
|
2014-01-15 17:04:00 +10:00
|
|
|
libinput_seat_get_physical_name(struct libinput_seat *seat)
|
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
|
|
|
{
|
2014-01-15 17:04:00 +10:00
|
|
|
return seat->physical_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT const char *
|
|
|
|
|
libinput_seat_get_logical_name(struct libinput_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
return seat->logical_name;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
libinput_device_init(struct libinput_device *device,
|
|
|
|
|
struct libinput_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
device->seat = seat;
|
|
|
|
|
device->refcount = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 00:06:57 +02:00
|
|
|
LIBINPUT_EXPORT struct libinput_device *
|
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_ref(struct libinput_device *device)
|
|
|
|
|
{
|
|
|
|
|
device->refcount++;
|
2014-06-25 00:06:57 +02:00
|
|
|
return device;
|
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
|
|
|
}
|
|
|
|
|
|
2013-12-31 16:11:03 +01:00
|
|
|
static void
|
|
|
|
|
libinput_device_destroy(struct libinput_device *device)
|
|
|
|
|
{
|
|
|
|
|
evdev_device_destroy((struct evdev_device *) device);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 00:06:57 +02:00
|
|
|
LIBINPUT_EXPORT struct libinput_device *
|
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_unref(struct libinput_device *device)
|
|
|
|
|
{
|
2014-01-08 16:40:14 +10:00
|
|
|
assert(device->refcount > 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
|
|
|
device->refcount--;
|
2014-06-25 00:06:57 +02:00
|
|
|
if (device->refcount == 0) {
|
2013-12-31 16:11:03 +01:00
|
|
|
libinput_device_destroy(device);
|
2014-06-25 00:06:57 +02:00
|
|
|
return NULL;
|
|
|
|
|
} else {
|
|
|
|
|
return device;
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
LIBINPUT_EXPORT int
|
|
|
|
|
libinput_get_fd(struct libinput *libinput)
|
|
|
|
|
{
|
|
|
|
|
return libinput->epoll_fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT int
|
|
|
|
|
libinput_dispatch(struct libinput *libinput)
|
|
|
|
|
{
|
2014-01-07 15:45:55 +10:00
|
|
|
struct libinput_source *source;
|
2013-11-17 11:19:50 +01:00
|
|
|
struct epoll_event ep[32];
|
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
|
|
count = epoll_wait(libinput->epoll_fd, ep, ARRAY_LENGTH(ep), 0);
|
|
|
|
|
if (count < 0)
|
2013-12-05 17:26:40 +10:00
|
|
|
return -errno;
|
2013-11-17 11:19:50 +01:00
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
|
source = ep[i].data.ptr;
|
|
|
|
|
if (source->fd == -1)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
source->dispatch(source->user_data);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-07 15:45:55 +10:00
|
|
|
libinput_drop_destroyed_sources(libinput);
|
2013-11-17 11:19:50 +01:00
|
|
|
|
2013-12-30 22:08:35 +01:00
|
|
|
return 0;
|
2013-11-17 11:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
2014-04-01 21:57:45 +02:00
|
|
|
static uint32_t
|
|
|
|
|
update_seat_key_count(struct libinput_seat *seat,
|
|
|
|
|
int32_t key,
|
2014-06-17 07:55:35 +10:00
|
|
|
enum libinput_key_state state)
|
2014-04-01 21:57:45 +02:00
|
|
|
{
|
|
|
|
|
assert(key >= 0 && key <= KEY_MAX);
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
2014-06-17 07:55:35 +10:00
|
|
|
case LIBINPUT_KEY_STATE_PRESSED:
|
2014-04-01 21:57:45 +02:00
|
|
|
return ++seat->button_count[key];
|
2014-06-17 07:55:35 +10:00
|
|
|
case LIBINPUT_KEY_STATE_RELEASED:
|
2014-04-01 21:57:45 +02:00
|
|
|
/* We might not have received the first PRESSED event. */
|
|
|
|
|
if (seat->button_count[key] == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return --seat->button_count[key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
|
update_seat_button_count(struct libinput_seat *seat,
|
|
|
|
|
int32_t button,
|
2014-06-03 20:08:02 -04:00
|
|
|
enum libinput_button_state state)
|
2014-04-01 21:57:45 +02:00
|
|
|
{
|
|
|
|
|
assert(button >= 0 && button <= KEY_MAX);
|
|
|
|
|
|
|
|
|
|
switch (state) {
|
2014-06-03 20:08:02 -04:00
|
|
|
case LIBINPUT_BUTTON_STATE_PRESSED:
|
2014-04-01 21:57:45 +02:00
|
|
|
return ++seat->button_count[button];
|
2014-06-03 20:08:02 -04:00
|
|
|
case LIBINPUT_BUTTON_STATE_RELEASED:
|
2014-04-01 21:57:45 +02:00
|
|
|
/* We might not have received the first PRESSED event. */
|
|
|
|
|
if (seat->button_count[button] == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return --seat->button_count[button];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-16 19:32:46 +01:00
|
|
|
static void
|
2013-11-17 11:19:50 +01:00
|
|
|
init_event_base(struct libinput_event *event,
|
2014-01-17 17:59:30 +10:00
|
|
|
struct libinput_device *device,
|
2013-12-19 11:42:55 +10:00
|
|
|
enum libinput_event_type type)
|
2013-11-17 11:19:50 +01:00
|
|
|
{
|
|
|
|
|
event->type = type;
|
2014-01-17 17:59:30 +10:00
|
|
|
event->device = device;
|
2013-11-17 11:19:50 +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
|
|
|
static void
|
2014-01-17 17:59:30 +10:00
|
|
|
post_base_event(struct libinput_device *device,
|
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
|
|
|
enum libinput_event_type type,
|
|
|
|
|
struct libinput_event *event)
|
|
|
|
|
{
|
2014-01-17 17:59:30 +10:00
|
|
|
struct libinput *libinput = device->seat->libinput;
|
2013-12-19 11:42:55 +10:00
|
|
|
init_event_base(event, device, type);
|
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_post_event(libinput, event);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
static void
|
|
|
|
|
post_device_event(struct libinput_device *device,
|
|
|
|
|
enum libinput_event_type type,
|
|
|
|
|
struct libinput_event *event)
|
|
|
|
|
{
|
2013-12-19 11:42:55 +10:00
|
|
|
init_event_base(event, device, type);
|
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_post_event(device->seat->libinput, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
notify_added_device(struct libinput_device *device)
|
|
|
|
|
{
|
2014-01-15 17:10:30 +10:00
|
|
|
struct libinput_event_device_notify *added_device_event;
|
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
|
|
|
|
2014-01-22 11:01:24 +10:00
|
|
|
added_device_event = zalloc(sizeof *added_device_event);
|
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 (!added_device_event)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-01-17 17:59:30 +10:00
|
|
|
post_base_event(device,
|
2013-12-19 12:04:24 +10:00
|
|
|
LIBINPUT_EVENT_DEVICE_ADDED,
|
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
|
|
|
&added_device_event->base);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
notify_removed_device(struct libinput_device *device)
|
|
|
|
|
{
|
2014-01-15 17:10:30 +10:00
|
|
|
struct libinput_event_device_notify *removed_device_event;
|
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
|
|
|
|
2014-01-22 11:01:24 +10:00
|
|
|
removed_device_event = zalloc(sizeof *removed_device_event);
|
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 (!removed_device_event)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-01-17 17:59:30 +10:00
|
|
|
post_base_event(device,
|
2013-12-19 12:04:24 +10:00
|
|
|
LIBINPUT_EVENT_DEVICE_REMOVED,
|
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
|
|
|
&removed_device_event->base);
|
2013-11-17 11:19:50 +01:00
|
|
|
}
|
2013-11-16 19:32:46 +01:00
|
|
|
|
2013-11-10 17:55:40 +01:00
|
|
|
void
|
|
|
|
|
keyboard_notify_key(struct libinput_device *device,
|
|
|
|
|
uint32_t time,
|
|
|
|
|
uint32_t key,
|
2014-06-17 07:55:35 +10:00
|
|
|
enum libinput_key_state state)
|
2013-11-10 17:55:40 +01:00
|
|
|
{
|
2013-12-19 16:40:48 +10:00
|
|
|
struct libinput_event_keyboard *key_event;
|
2014-04-01 21:57:45 +02:00
|
|
|
uint32_t seat_key_count;
|
2013-11-16 19:32:46 +01:00
|
|
|
|
2014-01-22 11:01:24 +10:00
|
|
|
key_event = zalloc(sizeof *key_event);
|
2013-11-16 19:32:46 +01:00
|
|
|
if (!key_event)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-04-01 21:57:45 +02:00
|
|
|
seat_key_count = update_seat_key_count(device->seat, key, state);
|
|
|
|
|
|
2013-12-19 16:40:48 +10:00
|
|
|
*key_event = (struct libinput_event_keyboard) {
|
2013-11-16 19:32:46 +01:00
|
|
|
.time = time,
|
|
|
|
|
.key = key,
|
|
|
|
|
.state = state,
|
2014-04-01 21:57:45 +02:00
|
|
|
.seat_key_count = seat_key_count,
|
2013-11-16 19:32:46 +01:00
|
|
|
};
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
post_device_event(device,
|
|
|
|
|
LIBINPUT_EVENT_KEYBOARD_KEY,
|
|
|
|
|
&key_event->base);
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pointer_notify_motion(struct libinput_device *device,
|
|
|
|
|
uint32_t time,
|
2014-06-02 23:09:27 +02:00
|
|
|
double dx,
|
|
|
|
|
double dy)
|
2013-11-10 17:55:40 +01:00
|
|
|
{
|
2013-12-19 13:15:28 +10:00
|
|
|
struct libinput_event_pointer *motion_event;
|
2013-11-16 19:32:46 +01:00
|
|
|
|
2014-01-22 11:01:24 +10:00
|
|
|
motion_event = zalloc(sizeof *motion_event);
|
2013-11-16 19:32:46 +01:00
|
|
|
if (!motion_event)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-12-19 13:15:28 +10:00
|
|
|
*motion_event = (struct libinput_event_pointer) {
|
2013-11-16 19:32:46 +01:00
|
|
|
.time = time,
|
2013-12-19 13:15:28 +10:00
|
|
|
.x = dx,
|
|
|
|
|
.y = dy,
|
2013-11-16 19:32:46 +01:00
|
|
|
};
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
post_device_event(device,
|
|
|
|
|
LIBINPUT_EVENT_POINTER_MOTION,
|
|
|
|
|
&motion_event->base);
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pointer_notify_motion_absolute(struct libinput_device *device,
|
|
|
|
|
uint32_t time,
|
2014-06-02 23:09:27 +02:00
|
|
|
double x,
|
|
|
|
|
double y)
|
2013-11-10 17:55:40 +01:00
|
|
|
{
|
2013-12-19 13:15:28 +10:00
|
|
|
struct libinput_event_pointer *motion_absolute_event;
|
2013-11-16 19:32:46 +01:00
|
|
|
|
2014-01-22 11:01:24 +10:00
|
|
|
motion_absolute_event = zalloc(sizeof *motion_absolute_event);
|
2013-11-16 19:32:46 +01:00
|
|
|
if (!motion_absolute_event)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-12-19 13:15:28 +10:00
|
|
|
*motion_absolute_event = (struct libinput_event_pointer) {
|
2013-11-16 19:32:46 +01:00
|
|
|
.time = time,
|
|
|
|
|
.x = x,
|
|
|
|
|
.y = y,
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
post_device_event(device,
|
|
|
|
|
LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE,
|
|
|
|
|
&motion_absolute_event->base);
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pointer_notify_button(struct libinput_device *device,
|
|
|
|
|
uint32_t time,
|
|
|
|
|
int32_t button,
|
2014-06-03 20:08:02 -04:00
|
|
|
enum libinput_button_state state)
|
2013-11-10 17:55:40 +01:00
|
|
|
{
|
2013-12-19 13:15:28 +10:00
|
|
|
struct libinput_event_pointer *button_event;
|
2014-04-01 21:57:45 +02:00
|
|
|
int32_t seat_button_count;
|
2013-11-16 19:32:46 +01:00
|
|
|
|
2014-01-22 11:01:24 +10:00
|
|
|
button_event = zalloc(sizeof *button_event);
|
2013-11-16 19:32:46 +01:00
|
|
|
if (!button_event)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-04-01 21:57:45 +02:00
|
|
|
seat_button_count = update_seat_button_count(device->seat,
|
|
|
|
|
button,
|
|
|
|
|
state);
|
|
|
|
|
|
2013-12-19 13:15:28 +10:00
|
|
|
*button_event = (struct libinput_event_pointer) {
|
2013-11-16 19:32:46 +01:00
|
|
|
.time = time,
|
|
|
|
|
.button = button,
|
|
|
|
|
.state = state,
|
2014-04-01 21:57:45 +02:00
|
|
|
.seat_button_count = seat_button_count,
|
2013-11-16 19:32:46 +01:00
|
|
|
};
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
post_device_event(device,
|
|
|
|
|
LIBINPUT_EVENT_POINTER_BUTTON,
|
|
|
|
|
&button_event->base);
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pointer_notify_axis(struct libinput_device *device,
|
|
|
|
|
uint32_t time,
|
|
|
|
|
enum libinput_pointer_axis axis,
|
2014-06-02 23:09:27 +02:00
|
|
|
double value)
|
2013-11-10 17:55:40 +01:00
|
|
|
{
|
2013-12-19 13:15:28 +10:00
|
|
|
struct libinput_event_pointer *axis_event;
|
2013-11-16 19:32:46 +01:00
|
|
|
|
2014-01-22 11:01:24 +10:00
|
|
|
axis_event = zalloc(sizeof *axis_event);
|
2013-11-16 19:32:46 +01:00
|
|
|
if (!axis_event)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-12-19 13:15:28 +10:00
|
|
|
*axis_event = (struct libinput_event_pointer) {
|
2013-11-16 19:32:46 +01:00
|
|
|
.time = time,
|
|
|
|
|
.axis = axis,
|
|
|
|
|
.value = value,
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
post_device_event(device,
|
|
|
|
|
LIBINPUT_EVENT_POINTER_AXIS,
|
|
|
|
|
&axis_event->base);
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2014-02-19 21:39:26 +01:00
|
|
|
touch_notify_touch_down(struct libinput_device *device,
|
|
|
|
|
uint32_t time,
|
|
|
|
|
int32_t slot,
|
|
|
|
|
int32_t seat_slot,
|
2014-06-02 23:09:27 +02:00
|
|
|
double x,
|
|
|
|
|
double y)
|
2014-02-19 21:39:26 +01:00
|
|
|
{
|
|
|
|
|
struct libinput_event_touch *touch_event;
|
|
|
|
|
|
|
|
|
|
touch_event = zalloc(sizeof *touch_event);
|
|
|
|
|
if (!touch_event)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
*touch_event = (struct libinput_event_touch) {
|
|
|
|
|
.time = time,
|
|
|
|
|
.slot = slot,
|
|
|
|
|
.seat_slot = seat_slot,
|
|
|
|
|
.x = x,
|
|
|
|
|
.y = y,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
post_device_event(device,
|
|
|
|
|
LIBINPUT_EVENT_TOUCH_DOWN,
|
|
|
|
|
&touch_event->base);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
touch_notify_touch_motion(struct libinput_device *device,
|
|
|
|
|
uint32_t time,
|
|
|
|
|
int32_t slot,
|
|
|
|
|
int32_t seat_slot,
|
2014-06-02 23:09:27 +02:00
|
|
|
double x,
|
|
|
|
|
double y)
|
2013-11-10 17:55:40 +01:00
|
|
|
{
|
2013-12-19 17:16:19 +10:00
|
|
|
struct libinput_event_touch *touch_event;
|
2013-11-16 19:32:46 +01:00
|
|
|
|
2014-01-22 11:01:24 +10:00
|
|
|
touch_event = zalloc(sizeof *touch_event);
|
2013-11-16 19:32:46 +01:00
|
|
|
if (!touch_event)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-12-19 17:16:19 +10:00
|
|
|
*touch_event = (struct libinput_event_touch) {
|
2013-11-16 19:32:46 +01:00
|
|
|
.time = time,
|
|
|
|
|
.slot = slot,
|
2014-01-30 22:44:49 +01:00
|
|
|
.seat_slot = seat_slot,
|
2013-11-16 19:32:46 +01:00
|
|
|
.x = x,
|
|
|
|
|
.y = y,
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
post_device_event(device,
|
2014-02-19 21:39:26 +01:00
|
|
|
LIBINPUT_EVENT_TOUCH_MOTION,
|
|
|
|
|
&touch_event->base);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
touch_notify_touch_up(struct libinput_device *device,
|
|
|
|
|
uint32_t time,
|
|
|
|
|
int32_t slot,
|
|
|
|
|
int32_t seat_slot)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event_touch *touch_event;
|
|
|
|
|
|
|
|
|
|
touch_event = zalloc(sizeof *touch_event);
|
|
|
|
|
if (!touch_event)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
*touch_event = (struct libinput_event_touch) {
|
|
|
|
|
.time = time,
|
|
|
|
|
.slot = slot,
|
|
|
|
|
.seat_slot = seat_slot,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
post_device_event(device,
|
|
|
|
|
LIBINPUT_EVENT_TOUCH_UP,
|
2013-11-17 11:19:50 +01:00
|
|
|
&touch_event->base);
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-20 10:15:00 +10:00
|
|
|
void
|
|
|
|
|
touch_notify_frame(struct libinput_device *device,
|
|
|
|
|
uint32_t time)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event_touch *touch_event;
|
|
|
|
|
|
|
|
|
|
touch_event = zalloc(sizeof *touch_event);
|
|
|
|
|
if (!touch_event)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
*touch_event = (struct libinput_event_touch) {
|
|
|
|
|
.time = time,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
post_device_event(device,
|
|
|
|
|
LIBINPUT_EVENT_TOUCH_FRAME,
|
|
|
|
|
&touch_event->base);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
static void
|
2013-11-17 11:19:50 +01:00
|
|
|
libinput_post_event(struct libinput *libinput,
|
|
|
|
|
struct libinput_event *event)
|
2013-11-10 17:55:40 +01:00
|
|
|
{
|
2013-11-17 11:19:50 +01:00
|
|
|
struct libinput_event **events = libinput->events;
|
|
|
|
|
size_t events_len = libinput->events_len;
|
|
|
|
|
size_t events_count = libinput->events_count;
|
2013-11-16 19:32:46 +01:00
|
|
|
size_t move_len;
|
|
|
|
|
size_t new_out;
|
|
|
|
|
|
|
|
|
|
events_count++;
|
|
|
|
|
if (events_count > events_len) {
|
2013-12-24 13:50:10 +10:00
|
|
|
events_len *= 2;
|
2013-11-16 19:32:46 +01:00
|
|
|
events = realloc(events, events_len * sizeof *events);
|
|
|
|
|
if (!events) {
|
|
|
|
|
fprintf(stderr, "Failed to reallocate event ring "
|
|
|
|
|
"buffer");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
if (libinput->events_count > 0 && libinput->events_in == 0) {
|
|
|
|
|
libinput->events_in = libinput->events_len;
|
|
|
|
|
} else if (libinput->events_count > 0 &&
|
|
|
|
|
libinput->events_out >= libinput->events_in) {
|
|
|
|
|
move_len = libinput->events_len - libinput->events_out;
|
2013-11-16 19:32:46 +01:00
|
|
|
new_out = events_len - move_len;
|
|
|
|
|
memmove(events + new_out,
|
2013-12-24 13:46:20 +10:00
|
|
|
events + libinput->events_out,
|
2013-11-16 19:32:46 +01:00
|
|
|
move_len * sizeof *events);
|
2013-11-17 11:19:50 +01:00
|
|
|
libinput->events_out = new_out;
|
2013-11-16 19:32:46 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
libinput->events = events;
|
|
|
|
|
libinput->events_len = events_len;
|
2013-11-16 19:32:46 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-22 23:45:44 +01:00
|
|
|
if (event->device)
|
2013-12-19 11:42:55 +10:00
|
|
|
libinput_device_ref(event->device);
|
2013-12-07 16:41:43 +01:00
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
libinput->events_count = events_count;
|
|
|
|
|
events[libinput->events_in] = event;
|
|
|
|
|
libinput->events_in = (libinput->events_in + 1) % libinput->events_len;
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-16 19:32:46 +01:00
|
|
|
LIBINPUT_EXPORT struct libinput_event *
|
2013-11-17 11:19:50 +01:00
|
|
|
libinput_get_event(struct libinput *libinput)
|
2013-11-10 17:55:40 +01:00
|
|
|
{
|
2013-11-16 19:32:46 +01:00
|
|
|
struct libinput_event *event;
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
if (libinput->events_count == 0)
|
2013-11-16 19:32:46 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
event = libinput->events[libinput->events_out];
|
|
|
|
|
libinput->events_out =
|
|
|
|
|
(libinput->events_out + 1) % libinput->events_len;
|
|
|
|
|
libinput->events_count--;
|
2013-11-16 19:32:46 +01:00
|
|
|
|
|
|
|
|
return event;
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-13 17:58:50 +10:00
|
|
|
LIBINPUT_EXPORT enum libinput_event_type
|
|
|
|
|
libinput_next_event_type(struct libinput *libinput)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
|
|
|
|
|
if (libinput->events_count == 0)
|
|
|
|
|
return LIBINPUT_EVENT_NONE;
|
|
|
|
|
|
|
|
|
|
event = libinput->events[libinput->events_out];
|
|
|
|
|
return event->type;
|
|
|
|
|
}
|
|
|
|
|
|
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_EXPORT void *
|
|
|
|
|
libinput_get_user_data(struct libinput *libinput)
|
|
|
|
|
{
|
|
|
|
|
return libinput->user_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT int
|
|
|
|
|
libinput_resume(struct libinput *libinput)
|
|
|
|
|
{
|
2013-12-13 11:37:31 +10:00
|
|
|
return libinput->interface_backend->resume(libinput);
|
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
|
|
|
}
|
|
|
|
|
|
2013-11-17 16:59:09 +01:00
|
|
|
LIBINPUT_EXPORT 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
|
|
|
libinput_suspend(struct libinput *libinput)
|
2013-11-17 16:59:09 +01:00
|
|
|
{
|
2013-12-13 11:37:31 +10:00
|
|
|
libinput->interface_backend->suspend(libinput);
|
2013-11-17 16:59:09 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-10 17:55:40 +01:00
|
|
|
LIBINPUT_EXPORT 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
|
|
|
libinput_device_set_user_data(struct libinput_device *device, void *user_data)
|
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
|
|
|
device->user_data = user_data;
|
2013-11-10 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-17 11:19:50 +01:00
|
|
|
LIBINPUT_EXPORT void *
|
|
|
|
|
libinput_device_get_user_data(struct libinput_device *device)
|
|
|
|
|
{
|
2013-11-17 19:31:34 +01:00
|
|
|
return device->user_data;
|
2013-11-17 11:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-15 17:50:04 +01:00
|
|
|
LIBINPUT_EXPORT const char *
|
|
|
|
|
libinput_device_get_sysname(struct libinput_device *device)
|
|
|
|
|
{
|
|
|
|
|
return evdev_device_get_sysname((struct evdev_device *) device);
|
|
|
|
|
}
|
|
|
|
|
|
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_EXPORT const char *
|
|
|
|
|
libinput_device_get_output_name(struct libinput_device *device)
|
|
|
|
|
{
|
|
|
|
|
return evdev_device_get_output((struct evdev_device *) device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT struct libinput_seat *
|
|
|
|
|
libinput_device_get_seat(struct libinput_device *device)
|
|
|
|
|
{
|
|
|
|
|
return device->seat;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 17:55:40 +01:00
|
|
|
LIBINPUT_EXPORT void
|
|
|
|
|
libinput_device_led_update(struct libinput_device *device,
|
|
|
|
|
enum libinput_led leds)
|
|
|
|
|
{
|
|
|
|
|
evdev_device_led_update((struct evdev_device *) device, leds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT int
|
|
|
|
|
libinput_device_get_keys(struct libinput_device *device,
|
|
|
|
|
char *keys, size_t size)
|
|
|
|
|
{
|
|
|
|
|
return evdev_device_get_keys((struct evdev_device *) device,
|
|
|
|
|
keys,
|
|
|
|
|
size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT void
|
|
|
|
|
libinput_device_calibrate(struct libinput_device *device,
|
|
|
|
|
float calibration[6])
|
|
|
|
|
{
|
|
|
|
|
evdev_device_calibrate((struct evdev_device *) device, calibration);
|
|
|
|
|
}
|
2013-12-15 17:45:02 +01:00
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT int
|
|
|
|
|
libinput_device_has_capability(struct libinput_device *device,
|
|
|
|
|
enum libinput_device_capability capability)
|
|
|
|
|
{
|
|
|
|
|
return evdev_device_has_capability((struct evdev_device *) device,
|
|
|
|
|
capability);
|
|
|
|
|
}
|
2014-03-25 13:55:47 +10:00
|
|
|
|
2014-06-17 15:45:07 +10:00
|
|
|
LIBINPUT_EXPORT int
|
|
|
|
|
libinput_device_get_size(struct libinput_device *device,
|
|
|
|
|
double *width,
|
|
|
|
|
double *height)
|
|
|
|
|
{
|
|
|
|
|
return evdev_device_get_size((struct evdev_device *)device,
|
|
|
|
|
width,
|
|
|
|
|
height);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 13:55:47 +10:00
|
|
|
LIBINPUT_EXPORT struct libinput_event *
|
|
|
|
|
libinput_event_device_notify_get_base_event(struct libinput_event_device_notify *event)
|
|
|
|
|
{
|
|
|
|
|
return &event->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT struct libinput_event *
|
|
|
|
|
libinput_event_keyboard_get_base_event(struct libinput_event_keyboard *event)
|
|
|
|
|
{
|
|
|
|
|
return &event->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT struct libinput_event *
|
|
|
|
|
libinput_event_pointer_get_base_event(struct libinput_event_pointer *event)
|
|
|
|
|
{
|
|
|
|
|
return &event->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIBINPUT_EXPORT struct libinput_event *
|
|
|
|
|
libinput_event_touch_get_base_event(struct libinput_event_touch *event)
|
|
|
|
|
{
|
|
|
|
|
return &event->base;
|
|
|
|
|
}
|