mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-20 20:50:07 +01:00
Add queue_push_event as shortcut for the two-liner we use everywhere
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
0af21e0e74
commit
25cddcecd3
2 changed files with 38 additions and 43 deletions
|
|
@ -143,6 +143,16 @@ _libevdev_log_msg(const struct libevdev *dev,
|
||||||
extern enum libevdev_log_priority
|
extern enum libevdev_log_priority
|
||||||
_libevdev_log_priority(const struct libevdev *dev);
|
_libevdev_log_priority(const struct libevdev *dev);
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
init_event(struct libevdev *dev, struct input_event *ev, int type, int code, int value)
|
||||||
|
{
|
||||||
|
ev->input_event_sec = dev->last_event_time.tv_sec;
|
||||||
|
ev->input_event_usec = dev->last_event_time.tv_usec;
|
||||||
|
ev->type = type;
|
||||||
|
ev->code = code;
|
||||||
|
ev->value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a pointer to the next element in the queue, or NULL if the queue
|
* @return a pointer to the next element in the queue, or NULL if the queue
|
||||||
* is full.
|
* is full.
|
||||||
|
|
@ -156,6 +166,18 @@ queue_push(struct libevdev *dev)
|
||||||
return &dev->queue[dev->queue_next++];
|
return &dev->queue[dev->queue_next++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
queue_push_event(struct libevdev *dev, unsigned int type,
|
||||||
|
unsigned int code, int value)
|
||||||
|
{
|
||||||
|
struct input_event *ev = queue_push(dev);
|
||||||
|
|
||||||
|
if (ev)
|
||||||
|
init_event(dev, ev, type, code, value);
|
||||||
|
|
||||||
|
return ev != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set ev to the last element in the queue, removing it from the queue.
|
* Set ev to the last element in the queue, removing it from the queue.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -576,16 +576,6 @@ libevdev_get_fd(const struct libevdev* dev)
|
||||||
return dev->fd;
|
return dev->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
|
||||||
init_event(struct libevdev *dev, struct input_event *ev, int type, int code, int value)
|
|
||||||
{
|
|
||||||
ev->input_event_sec = dev->last_event_time.tv_sec;
|
|
||||||
ev->input_event_usec = dev->last_event_time.tv_usec;
|
|
||||||
ev->type = type;
|
|
||||||
ev->code = code;
|
|
||||||
ev->value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sync_key_state(struct libevdev *dev)
|
sync_key_state(struct libevdev *dev)
|
||||||
{
|
{
|
||||||
|
|
@ -601,10 +591,8 @@ sync_key_state(struct libevdev *dev)
|
||||||
int old, new;
|
int old, new;
|
||||||
old = bit_is_set(dev->key_values, i);
|
old = bit_is_set(dev->key_values, i);
|
||||||
new = bit_is_set(keystate, i);
|
new = bit_is_set(keystate, i);
|
||||||
if (old ^ new) {
|
if (old ^ new)
|
||||||
struct input_event *ev = queue_push(dev);
|
queue_push_event(dev, EV_KEY, i, new ? 1 : 0);
|
||||||
init_event(dev, ev, EV_KEY, i, new ? 1 : 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(dev->key_values, keystate, rc);
|
memcpy(dev->key_values, keystate, rc);
|
||||||
|
|
@ -629,10 +617,8 @@ sync_sw_state(struct libevdev *dev)
|
||||||
int old, new;
|
int old, new;
|
||||||
old = bit_is_set(dev->sw_values, i);
|
old = bit_is_set(dev->sw_values, i);
|
||||||
new = bit_is_set(swstate, i);
|
new = bit_is_set(swstate, i);
|
||||||
if (old ^ new) {
|
if (old ^ new)
|
||||||
struct input_event *ev = queue_push(dev);
|
queue_push_event(dev, EV_SW, i, new ? 1 : 0);
|
||||||
init_event(dev, ev, EV_SW, i, new ? 1 : 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(dev->sw_values, swstate, rc);
|
memcpy(dev->sw_values, swstate, rc);
|
||||||
|
|
@ -658,8 +644,7 @@ sync_led_state(struct libevdev *dev)
|
||||||
old = bit_is_set(dev->led_values, i);
|
old = bit_is_set(dev->led_values, i);
|
||||||
new = bit_is_set(ledstate, i);
|
new = bit_is_set(ledstate, i);
|
||||||
if (old ^ new) {
|
if (old ^ new) {
|
||||||
struct input_event *ev = queue_push(dev);
|
queue_push_event(dev, EV_LED, i, new ? 1 : 0);
|
||||||
init_event(dev, ev, EV_LED, i, new ? 1 : 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -689,9 +674,7 @@ sync_abs_state(struct libevdev *dev)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (dev->abs_info[i].value != abs_info.value) {
|
if (dev->abs_info[i].value != abs_info.value) {
|
||||||
struct input_event *ev = queue_push(dev);
|
queue_push_event(dev, EV_ABS, i, abs_info.value);
|
||||||
|
|
||||||
init_event(dev, ev, EV_ABS, i, abs_info.value);
|
|
||||||
dev->abs_info[i].value = abs_info.value;
|
dev->abs_info[i].value = abs_info.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -704,7 +687,6 @@ out:
|
||||||
static int
|
static int
|
||||||
sync_mt_state(struct libevdev *dev, int create_events)
|
sync_mt_state(struct libevdev *dev, int create_events)
|
||||||
{
|
{
|
||||||
struct input_event *ev;
|
|
||||||
struct input_absinfo abs_info;
|
struct input_absinfo abs_info;
|
||||||
int rc;
|
int rc;
|
||||||
int axis, slot;
|
int axis, slot;
|
||||||
|
|
@ -762,24 +744,20 @@ sync_mt_state(struct libevdev *dev, int create_events)
|
||||||
if (!bit_is_set(tracking_id_changes, slot))
|
if (!bit_is_set(tracking_id_changes, slot))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ev = queue_push(dev);
|
queue_push_event(dev, EV_ABS, ABS_MT_SLOT, slot);
|
||||||
init_event(dev, ev, EV_ABS, ABS_MT_SLOT, slot);
|
queue_push_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
|
||||||
ev = queue_push(dev);
|
|
||||||
init_event(dev, ev, EV_ABS, ABS_MT_TRACKING_ID, -1);
|
|
||||||
|
|
||||||
last_reported_slot = slot;
|
last_reported_slot = slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
ev = queue_push(dev);
|
queue_push_event(dev, EV_SYN, SYN_REPORT, 0);
|
||||||
init_event(dev, ev, EV_SYN, SYN_REPORT, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (slot = 0; slot < dev->num_slots; slot++) {
|
for (slot = 0; slot < dev->num_slots; slot++) {
|
||||||
if (!bit_is_set(slot_update, AXISBIT(slot, ABS_MT_SLOT)))
|
if (!bit_is_set(slot_update, AXISBIT(slot, ABS_MT_SLOT)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ev = queue_push(dev);
|
queue_push_event(dev, EV_ABS, ABS_MT_SLOT, slot);
|
||||||
init_event(dev, ev, EV_ABS, ABS_MT_SLOT, slot);
|
|
||||||
last_reported_slot = slot;
|
last_reported_slot = slot;
|
||||||
|
|
||||||
for (axis = ABS_MT_MIN; axis <= ABS_MT_MAX; axis++) {
|
for (axis = ABS_MT_MIN; axis <= ABS_MT_MAX; axis++) {
|
||||||
|
|
@ -787,10 +765,9 @@ sync_mt_state(struct libevdev *dev, int create_events)
|
||||||
!libevdev_has_event_code(dev, EV_ABS, axis))
|
!libevdev_has_event_code(dev, EV_ABS, axis))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (bit_is_set(slot_update, AXISBIT(slot, axis))) {
|
if (bit_is_set(slot_update, AXISBIT(slot, axis)))
|
||||||
ev = queue_push(dev);
|
queue_push_event(dev, EV_ABS, axis,
|
||||||
init_event(dev, ev, EV_ABS, axis, *slot_value(dev, slot, axis));
|
*slot_value(dev, slot, axis));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -803,10 +780,8 @@ sync_mt_state(struct libevdev *dev, int create_events)
|
||||||
|
|
||||||
dev->current_slot = abs_info.value;
|
dev->current_slot = abs_info.value;
|
||||||
|
|
||||||
if (dev->current_slot != last_reported_slot) {
|
if (dev->current_slot != last_reported_slot)
|
||||||
ev = queue_push(dev);
|
queue_push_event(dev, EV_ABS, ABS_MT_SLOT, dev->current_slot);
|
||||||
init_event(dev, ev, EV_ABS, ABS_MT_SLOT, dev->current_slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef AXISBIT
|
#undef AXISBIT
|
||||||
|
|
||||||
|
|
@ -879,7 +854,6 @@ static int
|
||||||
sync_state(struct libevdev *dev)
|
sync_state(struct libevdev *dev)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct input_event *ev;
|
|
||||||
|
|
||||||
/* see section "Discarding events before synchronizing" in
|
/* see section "Discarding events before synchronizing" in
|
||||||
* libevdev/libevdev.h */
|
* libevdev/libevdev.h */
|
||||||
|
|
@ -900,8 +874,7 @@ sync_state(struct libevdev *dev)
|
||||||
dev->queue_nsync = queue_num_elements(dev);
|
dev->queue_nsync = queue_num_elements(dev);
|
||||||
|
|
||||||
if (dev->queue_nsync > 0) {
|
if (dev->queue_nsync > 0) {
|
||||||
ev = queue_push(dev);
|
queue_push_event(dev, EV_SYN, SYN_REPORT, 0);
|
||||||
init_event(dev, ev, EV_SYN, SYN_REPORT, 0);
|
|
||||||
dev->queue_nsync++;
|
dev->queue_nsync++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue