mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-02-19 03:00:32 +01:00
eis: streamline the event handlers a bit
Use a helper function to find the device, no need to duplicate these loops everywhere. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
bbbf2ff0f2
commit
86488fdc5a
1 changed files with 83 additions and 150 deletions
|
|
@ -78,6 +78,35 @@ eis_client_get_context(struct eis_client *client)
|
|||
return eis_client_parent(client);
|
||||
}
|
||||
|
||||
static struct eis_device *
|
||||
eis_client_find_device(struct eis_client *client, uint32_t deviceid)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid)
|
||||
return device;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct eis_seat *
|
||||
eis_client_find_seat(struct eis_client *client, uint32_t seatid)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
if (seat->id == seatid)
|
||||
return seat;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
client_send_disconnect(struct eis_client *client)
|
||||
{
|
||||
|
|
@ -208,103 +237,66 @@ eis_client_disconnect(struct eis_client *client)
|
|||
static int
|
||||
client_msg_close_device(struct eis_client *client, uint32_t deviceid)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
eis_device_closed_by_client(device);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
eis_device_closed_by_client(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
client_msg_bind_seat(struct eis_client *client, uint32_t seatid, uint32_t caps)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_seat *seat = eis_client_find_seat(client, seatid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
if (seat->id == seatid) {
|
||||
eis_seat_bind(seat, caps);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (seat)
|
||||
eis_seat_bind(seat, caps);
|
||||
|
||||
return -EINVAL;
|
||||
return seat ? 0 : -EINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
client_msg_unbind_seat(struct eis_client *client, uint32_t seatid)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_seat *seat = eis_client_find_seat(client, seatid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
if (seat->id == seatid) {
|
||||
eis_seat_unbind(seat);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (seat)
|
||||
eis_seat_unbind(seat);
|
||||
|
||||
return -EINVAL;
|
||||
return seat ? 0 : -EINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
client_msg_start_emulating(struct eis_client *client, uint32_t deviceid)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
eis_device_start_emulating(device);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
eis_device_start_emulating(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
client_msg_stop_emulating(struct eis_client *client, uint32_t deviceid)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
eis_device_stop_emulating(device);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
eis_device_stop_emulating(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
client_msg_frame(struct eis_client *client, uint32_t deviceid)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
return eis_device_frame(device);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
eis_device_frame(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -313,17 +305,11 @@ static int
|
|||
client_msg_pointer_rel(struct eis_client *client, uint32_t deviceid,
|
||||
double x, double y)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
return eis_device_pointer_rel(device, x, y);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
return eis_device_pointer_rel(device, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -331,17 +317,11 @@ static int
|
|||
client_msg_pointer_abs(struct eis_client *client, uint32_t deviceid,
|
||||
double x, double y)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
return eis_device_pointer_abs(device, x, y);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
return eis_device_pointer_abs(device, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -349,17 +329,11 @@ static int
|
|||
client_msg_pointer_button(struct eis_client *client, uint32_t deviceid,
|
||||
uint32_t button, bool state)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
return eis_device_pointer_button(device, button, state);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
return eis_device_pointer_button(device, button, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -367,17 +341,11 @@ static int
|
|||
client_msg_pointer_scroll(struct eis_client *client, uint32_t deviceid,
|
||||
double x, double y)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
return eis_device_pointer_scroll(device, x, y);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
return eis_device_pointer_scroll(device, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -385,17 +353,11 @@ static int
|
|||
client_msg_pointer_scroll_discrete(struct eis_client *client, uint32_t deviceid,
|
||||
int32_t x, int32_t y)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
return eis_device_pointer_scroll_discrete(device, x, y);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
return eis_device_pointer_scroll_discrete(device, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -403,20 +365,15 @@ static int
|
|||
client_msg_pointer_scroll_stop(struct eis_client *client, uint32_t deviceid,
|
||||
bool x, bool y, bool is_cancel)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
if (is_cancel)
|
||||
return eis_device_pointer_scroll_cancel(device, x, y);
|
||||
else
|
||||
return eis_device_pointer_scroll_stop(device, x, y);
|
||||
}
|
||||
}
|
||||
if (device) {
|
||||
if (is_cancel)
|
||||
return eis_device_pointer_scroll_cancel(device, x, y);
|
||||
else
|
||||
return eis_device_pointer_scroll_stop(device, x, y);
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -424,17 +381,11 @@ static int
|
|||
client_msg_keyboard_key(struct eis_client *client, uint32_t deviceid,
|
||||
uint32_t key, bool state)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
return eis_device_keyboard_key(device, key, state);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
return eis_device_keyboard_key(device, key, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -442,17 +393,11 @@ static int
|
|||
client_msg_touch_down(struct eis_client *client, uint32_t deviceid,
|
||||
uint32_t touchid, double x, double y)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
return eis_device_touch_down(device, touchid, x, y);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
return eis_device_touch_down(device, touchid, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -460,34 +405,22 @@ static int
|
|||
client_msg_touch_motion(struct eis_client *client, uint32_t deviceid,
|
||||
uint32_t touchid, double x, double y)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
return eis_device_touch_motion(device, touchid, x, y);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
return eis_device_touch_motion(device, touchid, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
client_msg_touch_up(struct eis_client *client, uint32_t deviceid, uint32_t touchid)
|
||||
{
|
||||
struct eis_seat *seat;
|
||||
struct eis_device *device = eis_client_find_device(client, deviceid);
|
||||
|
||||
list_for_each(seat, &client->seats, link) {
|
||||
struct eis_device *device;
|
||||
if (device)
|
||||
return eis_device_touch_up(device, touchid);
|
||||
|
||||
list_for_each(device, &seat->devices, link) {
|
||||
if (device->id == deviceid) {
|
||||
return eis_device_touch_up(device, touchid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue