mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-05-09 09:48:03 +02:00
Remove now-obsolete proto files
This commit is contained in:
parent
b309798bf1
commit
1e0796f432
5 changed files with 0 additions and 1380 deletions
|
|
@ -1,556 +0,0 @@
|
|||
/* SPDX-License-Identifier: MIT */
|
||||
/*
|
||||
* Copyright © 2020 Red Hat, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "util-object.h"
|
||||
#include "util-io.h"
|
||||
|
||||
#include "ei.pb-c.h"
|
||||
#include "libei-proto.h"
|
||||
#include "brei-shared.h"
|
||||
|
||||
static void servermessage_cleanup(ServerMessage **m) {
|
||||
if (*m)
|
||||
server_message__free_unpacked(*m, NULL);
|
||||
}
|
||||
#define _cleanup_servermessage_ _cleanup_(servermessage_cleanup)
|
||||
|
||||
|
||||
int
|
||||
ei_proto_handle_message(struct ei *ei,
|
||||
const struct ei_proto_interface *interface,
|
||||
struct brei_message *bmsg)
|
||||
{
|
||||
_cleanup_servermessage_ ServerMessage *proto = server_message__unpack(NULL,
|
||||
bmsg->len,
|
||||
(const unsigned char*)bmsg->data);
|
||||
if (!proto)
|
||||
return -EAGAIN;
|
||||
|
||||
#define call(field, ...) \
|
||||
({ \
|
||||
int r = (interface->field == NULL) ? -EPROTO : interface->field(__VA_ARGS__); \
|
||||
log_debug(ei, "message type '" #field "': errno %d (%s)", -r, strerror(-r)); \
|
||||
r; \
|
||||
})
|
||||
|
||||
int rc;
|
||||
switch (proto->msg_case) {
|
||||
case SERVER_MESSAGE__MSG_CONNECTED:
|
||||
rc = call(connected, ei);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_DISCONNECTED:
|
||||
rc = call(disconnected, ei);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_SEAT_ADDED:
|
||||
rc = call(seat_added, ei,
|
||||
proto->seat_added->seatid,
|
||||
proto->seat_added->capabilities, proto->seat_added->name);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_SEAT_REMOVED:
|
||||
rc = call(seat_removed, ei,
|
||||
proto->seat_removed->seatid);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_DEVICE_ADDED:
|
||||
rc = call(device_added, ei,
|
||||
proto->device_added->deviceid,
|
||||
proto->device_added->capabilities,
|
||||
proto->device_added->name,
|
||||
proto->device_added->seatid,
|
||||
proto->device_added->type,
|
||||
proto->device_added->width,
|
||||
proto->device_added->height);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_DEVICE_DONE:
|
||||
rc = call(device_done, ei,
|
||||
proto->device_done->deviceid);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_DEVICE_KEYMAP:
|
||||
{
|
||||
int fd = brei_message_take_fd(bmsg);
|
||||
rc = call(device_keymap, ei,
|
||||
proto->device_keymap->deviceid,
|
||||
proto->device_keymap->keymap_type,
|
||||
proto->device_keymap->keymap_size, fd);
|
||||
xclose(fd);
|
||||
}
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_DEVICE_REGION:
|
||||
rc = call(device_region, ei,
|
||||
proto->device_region->deviceid,
|
||||
proto->device_region->offset_x,
|
||||
proto->device_region->offset_y,
|
||||
proto->device_region->width,
|
||||
proto->device_region->height,
|
||||
proto->device_region->scale);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_KEYBOARD_MODIFIERS:
|
||||
rc = call(keyboard_modifiers, ei,
|
||||
proto->keyboard_modifiers->deviceid,
|
||||
proto->keyboard_modifiers->depressed,
|
||||
proto->keyboard_modifiers->locked,
|
||||
proto->keyboard_modifiers->latched,
|
||||
proto->keyboard_modifiers->group);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_DEVICE_REMOVED:
|
||||
rc = call(device_removed, ei,
|
||||
proto->device_removed->deviceid);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_DEVICE_RESUMED:
|
||||
rc = call(device_resumed, ei,
|
||||
proto->device_resumed->deviceid);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_DEVICE_PAUSED:
|
||||
rc = call(device_paused, ei,
|
||||
proto->device_paused->deviceid);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_VERSION:
|
||||
rc = call(version, ei, proto->version->version);
|
||||
break;
|
||||
/* Events */
|
||||
case SERVER_MESSAGE__MSG_START_EMULATING:
|
||||
rc = call(start_emulating, ei,
|
||||
proto->start_emulating->deviceid,
|
||||
proto->start_emulating->sequence);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_STOP_EMULATING:
|
||||
rc = call(stop_emulating, ei,
|
||||
proto->stop_emulating->deviceid);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_POINTER_RELATIVE:
|
||||
rc = call(rel, ei,
|
||||
proto->pointer_relative->deviceid,
|
||||
proto->pointer_relative->x,
|
||||
proto->pointer_relative->y);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_POINTER_ABSOLUTE:
|
||||
rc = call(abs, ei,
|
||||
proto->pointer_absolute->deviceid,
|
||||
proto->pointer_absolute->x,
|
||||
proto->pointer_absolute->y);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_POINTER_BUTTON:
|
||||
rc = call(button, ei,
|
||||
proto->pointer_button->deviceid,
|
||||
proto->pointer_button->button,
|
||||
proto->pointer_button->state);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_POINTER_SCROLL:
|
||||
rc = call(scroll, ei,
|
||||
proto->pointer_scroll->deviceid,
|
||||
proto->pointer_scroll->x,
|
||||
proto->pointer_scroll->y);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_POINTER_SCROLL_STOP:
|
||||
rc = call(scroll_stop, ei,
|
||||
proto->pointer_scroll_stop->deviceid,
|
||||
proto->pointer_scroll_stop->x,
|
||||
proto->pointer_scroll_stop->y,
|
||||
proto->pointer_scroll_stop->is_cancel);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_POINTER_SCROLL_DISCRETE:
|
||||
rc = call(scroll_discrete, ei,
|
||||
proto->pointer_scroll_discrete->deviceid,
|
||||
proto->pointer_scroll_discrete->x,
|
||||
proto->pointer_scroll_discrete->y);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_KEYBOARD_KEY:
|
||||
rc = call(key, ei,
|
||||
proto->keyboard_key->deviceid,
|
||||
proto->keyboard_key->key,
|
||||
proto->keyboard_key->state);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_TOUCH_DOWN:
|
||||
rc = call(touch_down, ei,
|
||||
proto->touch_down->deviceid,
|
||||
proto->touch_down->touchid,
|
||||
proto->touch_down->x,
|
||||
proto->touch_down->y);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_TOUCH_MOTION:
|
||||
rc = call(touch_motion, ei,
|
||||
proto->touch_motion->deviceid,
|
||||
proto->touch_motion->touchid,
|
||||
proto->touch_motion->x,
|
||||
proto->touch_motion->y);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_TOUCH_UP:
|
||||
rc = call(touch_up, ei,
|
||||
proto->touch_up->deviceid,
|
||||
proto->touch_up->touchid);
|
||||
break;
|
||||
case SERVER_MESSAGE__MSG_FRAME:
|
||||
rc = call(frame, ei, proto->frame->deviceid, proto->frame->timestamp);
|
||||
break;
|
||||
default:
|
||||
rc = -EBADMSG;
|
||||
break;
|
||||
}
|
||||
|
||||
return rc < 0 ? rc : (int)bmsg->len;
|
||||
}
|
||||
|
||||
static inline void
|
||||
log_wire_message(struct ei *ei, const ClientMessage *msg, int error)
|
||||
{
|
||||
const char *message = NULL;
|
||||
|
||||
#define MSG_STRING_CASE(_name) \
|
||||
case CLIENT_MESSAGE__MSG_##_name: message = #_name; break;
|
||||
|
||||
switch (msg->msg_case) {
|
||||
#if PROTOBUF_C_VERSION_NUMBER >= 1004000
|
||||
case _CLIENT_MESSAGE__MSG__CASE_IS_INT_SIZE:
|
||||
#else
|
||||
case _CLIENT_MESSAGE__MSG_IS_INT_SIZE:
|
||||
#endif
|
||||
/* protobuf-internal thing */
|
||||
return;
|
||||
case CLIENT_MESSAGE__MSG__NOT_SET:
|
||||
abort();
|
||||
MSG_STRING_CASE(CONNECT);
|
||||
MSG_STRING_CASE(CONNECT_DONE);
|
||||
MSG_STRING_CASE(DISCONNECT);
|
||||
MSG_STRING_CASE(BIND_SEAT);
|
||||
MSG_STRING_CASE(CLOSE_DEVICE);
|
||||
MSG_STRING_CASE(GET_VERSION);
|
||||
/* events */
|
||||
MSG_STRING_CASE(START_EMULATING);
|
||||
MSG_STRING_CASE(STOP_EMULATING);
|
||||
MSG_STRING_CASE(POINTER_RELATIVE);
|
||||
MSG_STRING_CASE(POINTER_ABSOLUTE);
|
||||
MSG_STRING_CASE(POINTER_BUTTON);
|
||||
MSG_STRING_CASE(POINTER_SCROLL);
|
||||
MSG_STRING_CASE(POINTER_SCROLL_STOP);
|
||||
MSG_STRING_CASE(POINTER_SCROLL_DISCRETE);
|
||||
MSG_STRING_CASE(KEYBOARD_KEY);
|
||||
MSG_STRING_CASE(TOUCH_DOWN);
|
||||
MSG_STRING_CASE(TOUCH_MOTION);
|
||||
MSG_STRING_CASE(TOUCH_UP);
|
||||
MSG_STRING_CASE(FRAME);
|
||||
}
|
||||
if (message == NULL)
|
||||
assert(!"Unimplemented message type");
|
||||
|
||||
log_debug(ei, "sending wire message %s (%s)", message,
|
||||
strerror(-error));
|
||||
|
||||
#undef MSG_STRING_CASE
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_msg(struct ei *ei, const ClientMessage *msg)
|
||||
{
|
||||
size_t msglen = client_message__get_packed_size(msg);
|
||||
uint8_t buf[4 + msglen];
|
||||
*(uint32_t*)buf = msglen;
|
||||
client_message__pack(msg, buf + 4);
|
||||
|
||||
int rc = min(0, xsend(source_get_fd(ei->source), buf, sizeof(buf)));
|
||||
|
||||
log_wire_message(ei, msg, rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
_unused_ static int
|
||||
ei_proto_send_msg_with_fds(struct ei *ei, const ClientMessage *msg, int *fds)
|
||||
{
|
||||
size_t msglen = client_message__get_packed_size(msg);
|
||||
uint8_t buf[4 + msglen];
|
||||
*(uint32_t*)buf = msglen;
|
||||
client_message__pack(msg, buf + 4);
|
||||
|
||||
int rc = min(0, xsend_with_fd(source_get_fd(ei->source), buf, sizeof(buf), fds));
|
||||
log_wire_message(ei, msg, rc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#define prepare_msg(_type, _struct, _field) \
|
||||
ClientMessage msg = CLIENT_MESSAGE__INIT; \
|
||||
_struct _field = _type##__INIT; \
|
||||
msg.msg_case = CLIENT_MESSAGE__MSG_##_type; \
|
||||
msg._field = &_field
|
||||
|
||||
static int
|
||||
ei_proto_send_get_version(struct ei *ei)
|
||||
{
|
||||
prepare_msg(GET_VERSION, GetVersion, get_version);
|
||||
|
||||
get_version.ei = "EI";
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_connect(struct ei *ei, uint32_t version)
|
||||
{
|
||||
prepare_msg(CONNECT, Connect, connect);
|
||||
|
||||
connect.name = ei->name;
|
||||
connect.is_sender = ei->is_sender;
|
||||
connect.version = version;
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_connect_done(struct ei *ei)
|
||||
{
|
||||
prepare_msg(CONNECT_DONE, ConnectDone, connect_done);
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_disconnect(struct ei *ei)
|
||||
{
|
||||
prepare_msg(DISCONNECT, Disconnect, disconnect);
|
||||
|
||||
return ei_proto_send_msg(ei, &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_bind_seat(struct ei_seat *seat, uint32_t capabilities)
|
||||
{
|
||||
prepare_msg(BIND_SEAT, BindSeat, bind_seat);
|
||||
|
||||
bind_seat.seatid = seat->id;
|
||||
bind_seat.capabilities = capabilities;
|
||||
|
||||
return ei_proto_send_msg(ei_seat_get_context(seat), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_close_device(struct ei_device *device)
|
||||
{
|
||||
prepare_msg(CLOSE_DEVICE, CloseDevice, close_device);
|
||||
|
||||
close_device.deviceid = device->id;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_start_emulating(struct ei_device *device, uint32_t sequence)
|
||||
{
|
||||
prepare_msg(START_EMULATING, StartEmulating, start_emulating);
|
||||
|
||||
start_emulating.deviceid = device->id;
|
||||
start_emulating.sequence = sequence;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_stop_emulating(struct ei_device *device)
|
||||
{
|
||||
prepare_msg(STOP_EMULATING, StopEmulating, stop_emulating);
|
||||
|
||||
stop_emulating.deviceid = device->id;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_rel(struct ei_device *device, double x, double y)
|
||||
{
|
||||
prepare_msg(POINTER_RELATIVE, PointerRelative, pointer_relative);
|
||||
|
||||
pointer_relative.deviceid = device->id;
|
||||
pointer_relative.x = x;
|
||||
pointer_relative.y = y;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_abs(struct ei_device *device, double x, double y)
|
||||
{
|
||||
prepare_msg(POINTER_ABSOLUTE, PointerAbsolute, pointer_absolute);
|
||||
|
||||
pointer_absolute.deviceid = device->id;
|
||||
pointer_absolute.x = x;
|
||||
pointer_absolute.y = y;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_button(struct ei_device *device, uint32_t b, bool is_press)
|
||||
{
|
||||
prepare_msg(POINTER_BUTTON, PointerButton, pointer_button);
|
||||
|
||||
pointer_button.deviceid = device->id;
|
||||
pointer_button.button = b;
|
||||
pointer_button.state = is_press;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_scroll(struct ei_device *device, double x, double y)
|
||||
{
|
||||
prepare_msg(POINTER_SCROLL, PointerScroll, pointer_scroll);
|
||||
|
||||
pointer_scroll.deviceid = device->id;
|
||||
pointer_scroll.x = x;
|
||||
pointer_scroll.y = y;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_scroll_stop(struct ei_device *device, bool x, bool y)
|
||||
{
|
||||
prepare_msg(POINTER_SCROLL_STOP, PointerScrollStop, pointer_scroll_stop);
|
||||
|
||||
pointer_scroll_stop.deviceid = device->id;
|
||||
pointer_scroll_stop.x = x;
|
||||
pointer_scroll_stop.y = y;
|
||||
pointer_scroll_stop.is_cancel = false;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_scroll_cancel(struct ei_device *device, bool x, bool y)
|
||||
{
|
||||
prepare_msg(POINTER_SCROLL_STOP, PointerScrollStop, pointer_scroll_stop);
|
||||
|
||||
pointer_scroll_stop.deviceid = device->id;
|
||||
pointer_scroll_stop.x = x;
|
||||
pointer_scroll_stop.y = y;
|
||||
pointer_scroll_stop.is_cancel = true;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_scroll_discrete(struct ei_device *device, int32_t x, int32_t y)
|
||||
{
|
||||
prepare_msg(POINTER_SCROLL_DISCRETE, PointerScrollDiscrete, pointer_scroll_discrete);
|
||||
|
||||
pointer_scroll_discrete.deviceid = device->id;
|
||||
pointer_scroll_discrete.x = x;
|
||||
pointer_scroll_discrete.y = y;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_key(struct ei_device *device, uint32_t k, bool is_press)
|
||||
{
|
||||
prepare_msg(KEYBOARD_KEY, KeyboardKey, keyboard_key);
|
||||
|
||||
keyboard_key.deviceid = device->id;
|
||||
keyboard_key.key = k;
|
||||
keyboard_key.state = is_press;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ei_proto_send_touch_down(struct ei_device *device, uint32_t tid, double x, double y)
|
||||
{
|
||||
prepare_msg(TOUCH_DOWN, TouchDown, touch_down);
|
||||
|
||||
touch_down.deviceid = device->id;
|
||||
touch_down.touchid = tid;
|
||||
touch_down.x = x;
|
||||
touch_down.y = y;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_touch_motion(struct ei_device *device, uint32_t tid, double x, double y)
|
||||
{
|
||||
prepare_msg(TOUCH_MOTION, TouchMotion, touch_motion);
|
||||
|
||||
touch_motion.deviceid = device->id;
|
||||
touch_motion.touchid = tid;
|
||||
touch_motion.x = x;
|
||||
touch_motion.y = y;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_touch_up(struct ei_device *device, uint32_t tid)
|
||||
{
|
||||
prepare_msg(TOUCH_UP, TouchUp, touch_up);
|
||||
|
||||
touch_up.deviceid = device->id;
|
||||
touch_up.touchid = tid;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
ei_proto_send_frame(struct ei_device *device, uint64_t time)
|
||||
{
|
||||
prepare_msg(FRAME, Frame, frame);
|
||||
|
||||
frame.deviceid = device->id;
|
||||
frame.timestamp = time;
|
||||
|
||||
return ei_proto_send_msg(ei_device_get_context(device), &msg);
|
||||
}
|
||||
|
||||
static const struct ei_proto_requests requests = {
|
||||
.connect = ei_proto_send_connect,
|
||||
.connect_done = ei_proto_send_connect_done,
|
||||
.disconnect = ei_proto_send_disconnect,
|
||||
.bind_seat = ei_proto_send_bind_seat,
|
||||
.close_device = ei_proto_send_close_device,
|
||||
.get_version = ei_proto_send_get_version,
|
||||
|
||||
/* events */
|
||||
.start_emulating = ei_proto_send_start_emulating,
|
||||
.stop_emulating = ei_proto_send_stop_emulating,
|
||||
.rel = ei_proto_send_rel,
|
||||
.abs = ei_proto_send_abs,
|
||||
.button = ei_proto_send_button,
|
||||
.scroll = ei_proto_send_scroll,
|
||||
.scroll_stop = ei_proto_send_scroll_stop,
|
||||
.scroll_cancel = ei_proto_send_scroll_cancel,
|
||||
.scroll_discrete = ei_proto_send_scroll_discrete,
|
||||
.key = ei_proto_send_key,
|
||||
.touch_down = ei_proto_send_touch_down,
|
||||
.touch_motion = ei_proto_send_touch_motion,
|
||||
.touch_up = ei_proto_send_touch_up,
|
||||
.frame = ei_proto_send_frame,
|
||||
};
|
||||
|
||||
const struct ei_proto_requests *
|
||||
ei_proto_get_requests(void)
|
||||
{
|
||||
return &requests;
|
||||
}
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
/* SPDX-License-Identifier: MIT */
|
||||
/*
|
||||
* Copyright © 2020 Red Hat, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "util-macros.h"
|
||||
#include "util-mem.h"
|
||||
|
||||
#include "brei-shared.h"
|
||||
#include "libei-private.h"
|
||||
|
||||
/* callbacks invoked during ei_proto_parse_message() */
|
||||
struct ei_proto_interface {
|
||||
int (*connected)(struct ei *ei);
|
||||
int (*disconnected)(struct ei *ei);
|
||||
int (*seat_added)(struct ei *ei, uint32_t seatid,
|
||||
uint32_t capabilities, const char *name);
|
||||
int (*seat_removed)(struct ei *ei, uint32_t seatid);
|
||||
int (*device_added)(struct ei *ei, uint32_t deviceid, uint32_t seatid,
|
||||
const char *name, uint32_t capabilities, uint32_t type,
|
||||
uint32_t width, uint32_t height);
|
||||
int (*device_removed)(struct ei *ei, uint32_t deviceid);
|
||||
int (*device_paused)(struct ei *ei, uint32_t deviceid);
|
||||
int (*device_resumed)(struct ei *ei, uint32_t deviceid);
|
||||
int (*device_done)(struct ei *ei, uint32_t deviceid);
|
||||
int (*device_region)(struct ei *ei, uint32_t deviceid,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h,
|
||||
double scale);
|
||||
int (*device_keymap)(struct ei *ei, uint32_t deviceid,
|
||||
enum ei_keymap_type keymap_type,
|
||||
size_t keymap_size, int keymap_fd);
|
||||
int (*keyboard_modifiers)(struct ei *ei, uint32_t deviceid,
|
||||
uint32_t depressed, uint32_t latched,
|
||||
uint32_t locked, uint32_t group);
|
||||
int (*version)(struct ei *ei, uint32_t version);
|
||||
|
||||
/* events */
|
||||
int (*start_emulating)(struct ei *ei, uint32_t deviceid, uint32_t sequence);
|
||||
int (*stop_emulating)(struct ei *ei, uint32_t deviceid);
|
||||
int (*rel)(struct ei *ei, uint32_t deviceid, double x, double y);
|
||||
int (*abs)(struct ei *ei, uint32_t deviceid, double x, double y);
|
||||
int (*button)(struct ei *ei, uint32_t deviceid, uint32_t button, bool is_press);
|
||||
int (*key)(struct ei *ei, uint32_t deviceid, uint32_t key, bool is_press);
|
||||
int (*scroll)(struct ei *ei, uint32_t deviceid, double x, double y);
|
||||
int (*scroll_stop)(struct ei *ei, uint32_t deviceid, bool x, bool y, bool is_cancel);
|
||||
int (*scroll_discrete)(struct ei *ei, uint32_t deviceid, int32_t x, int32_t y);
|
||||
int (*touch_down)(struct ei *ei, uint32_t deviceid,
|
||||
uint32_t tid, double x, double y);
|
||||
int (*touch_motion)(struct ei *ei, uint32_t deviceid,
|
||||
uint32_t tid, double x, double y);
|
||||
int (*touch_up)(struct ei *ei, uint32_t deviceid, uint32_t tid);
|
||||
int (*frame) (struct ei *ei, uint32_t deviceid, uint64_t time);
|
||||
};
|
||||
|
||||
struct ei_proto_requests {
|
||||
int (*connect)(struct ei *ei, uint32_t version);
|
||||
int (*connect_done)(struct ei *ei);
|
||||
int (*disconnect)(struct ei *ei);
|
||||
int (*bind_seat)(struct ei_seat *seat, enum ei_device_capability cap);
|
||||
int (*unbind_seat)(struct ei_seat *seat, enum ei_device_capability cap);
|
||||
int (*close_device)(struct ei_device *device);
|
||||
int (*get_version)(struct ei *ei);
|
||||
int (*start_emulating)(struct ei_device *device, uint32_t sequence);
|
||||
int (*stop_emulating)(struct ei_device *device);
|
||||
|
||||
int (*rel)(struct ei_device *device, double x, double y);
|
||||
int (*abs)(struct ei_device *device, double x, double y);
|
||||
int (*button)(struct ei_device *device, uint32_t b, bool is_press);
|
||||
int (*key)(struct ei_device *device, uint32_t k, bool is_press);
|
||||
int (*scroll)(struct ei_device *device, double x, double y);
|
||||
int (*scroll_stop)(struct ei_device *device, bool x, bool y);
|
||||
int (*scroll_cancel)(struct ei_device *device, bool x, bool y);
|
||||
int (*scroll_discrete)(struct ei_device *device, int32_t x, int32_t y);
|
||||
int (*touch_down)(struct ei_device *device,
|
||||
uint32_t tid, double x, double y);
|
||||
int (*touch_motion)(struct ei_device *device,
|
||||
uint32_t tid, double x, double y);
|
||||
int (*touch_up)(struct ei_device *device, uint32_t tid);
|
||||
int (*frame)(struct ei_device *device, uint64_t time);
|
||||
};
|
||||
|
||||
int
|
||||
ei_proto_handle_message(struct ei *ei,
|
||||
const struct ei_proto_interface *interface,
|
||||
struct brei_message *message);
|
||||
|
||||
const struct ei_proto_requests *
|
||||
ei_proto_get_requests(void);
|
||||
|
|
@ -41,7 +41,6 @@
|
|||
#include "util-version.h"
|
||||
|
||||
#include "libeis-private.h"
|
||||
#include "libeis-proto.h"
|
||||
#include "brei-shared.h"
|
||||
#include "eis-proto.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,607 +0,0 @@
|
|||
/* SPDX-License-Identifier: MIT */
|
||||
/*
|
||||
* Copyright © 2020 Red Hat, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "util-object.h"
|
||||
#include "util-io.h"
|
||||
#include "util-strings.h"
|
||||
#include "util-tristate.h"
|
||||
|
||||
#include "ei.pb-c.h"
|
||||
#include "libeis-proto.h"
|
||||
#include "brei-shared.h"
|
||||
|
||||
static inline void
|
||||
log_wire_message(struct eis *eis, const ServerMessage *msg)
|
||||
{
|
||||
const char *message = NULL;
|
||||
|
||||
#define MSG_STRING_CASE(_name) \
|
||||
case SERVER_MESSAGE__MSG_##_name: message = #_name; break;
|
||||
|
||||
switch (msg->msg_case) {
|
||||
#if PROTOBUF_C_VERSION_NUMBER >= 1004000
|
||||
case _SERVER_MESSAGE__MSG__CASE_IS_INT_SIZE:
|
||||
#else
|
||||
case _SERVER_MESSAGE__MSG_IS_INT_SIZE:
|
||||
#endif
|
||||
/* protobuf-internal thing */
|
||||
return;
|
||||
case SERVER_MESSAGE__MSG__NOT_SET:
|
||||
assert(!"SERVER_MESSAGE__MSG__NOT_SET");
|
||||
MSG_STRING_CASE(CONNECTED);
|
||||
MSG_STRING_CASE(DISCONNECTED);
|
||||
MSG_STRING_CASE(SEAT_ADDED);
|
||||
MSG_STRING_CASE(SEAT_REMOVED);
|
||||
MSG_STRING_CASE(DEVICE_ADDED);
|
||||
MSG_STRING_CASE(DEVICE_DONE);
|
||||
MSG_STRING_CASE(DEVICE_KEYMAP);
|
||||
MSG_STRING_CASE(DEVICE_REGION);
|
||||
MSG_STRING_CASE(DEVICE_REMOVED);
|
||||
MSG_STRING_CASE(DEVICE_RESUMED);
|
||||
MSG_STRING_CASE(DEVICE_PAUSED);
|
||||
MSG_STRING_CASE(KEYBOARD_MODIFIERS);
|
||||
MSG_STRING_CASE(VERSION);
|
||||
/* events */
|
||||
MSG_STRING_CASE(START_EMULATING);
|
||||
MSG_STRING_CASE(STOP_EMULATING);
|
||||
MSG_STRING_CASE(POINTER_RELATIVE);
|
||||
MSG_STRING_CASE(POINTER_ABSOLUTE);
|
||||
MSG_STRING_CASE(POINTER_BUTTON);
|
||||
MSG_STRING_CASE(POINTER_SCROLL);
|
||||
MSG_STRING_CASE(POINTER_SCROLL_STOP);
|
||||
MSG_STRING_CASE(POINTER_SCROLL_DISCRETE);
|
||||
MSG_STRING_CASE(KEYBOARD_KEY);
|
||||
MSG_STRING_CASE(TOUCH_DOWN);
|
||||
MSG_STRING_CASE(TOUCH_MOTION);
|
||||
MSG_STRING_CASE(TOUCH_UP);
|
||||
MSG_STRING_CASE(FRAME);
|
||||
break;
|
||||
}
|
||||
if (message == NULL)
|
||||
assert(!"Unimplemented message type");
|
||||
|
||||
log_debug(eis, "sending wire message %s", message);
|
||||
|
||||
#undef MSG_STRING_CASE
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_msg(struct eis_client *client, const ServerMessage *msg)
|
||||
{
|
||||
log_wire_message(eis_client_get_context(client), msg);
|
||||
|
||||
size_t msglen = server_message__get_packed_size(msg);
|
||||
uint8_t buf[4 + msglen];
|
||||
*(uint32_t*)buf = msglen;
|
||||
server_message__pack(msg, buf + 4);
|
||||
return min(0, xsend(source_get_fd(client->source), buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_msg_with_fds(struct eis_client *client, const ServerMessage *msg, int *fds)
|
||||
{
|
||||
log_wire_message(eis_client_get_context(client), msg);
|
||||
|
||||
size_t msglen = server_message__get_packed_size(msg);
|
||||
uint8_t buf[4 + msglen];
|
||||
*(uint32_t*)buf = msglen;
|
||||
server_message__pack(msg, buf + 4);
|
||||
|
||||
return min(0, xsend_with_fd(source_get_fd(client->source), buf, sizeof(buf), fds));
|
||||
}
|
||||
|
||||
#define prepare_msg(_type, _struct, _field) \
|
||||
ServerMessage msg = SERVER_MESSAGE__INIT; \
|
||||
_struct _field = _type##__INIT; \
|
||||
msg.msg_case = SERVER_MESSAGE__MSG_##_type; \
|
||||
msg._field = &_field
|
||||
|
||||
static int
|
||||
eis_proto_send_version(struct eis_client *client, uint32_t v)
|
||||
{
|
||||
prepare_msg(VERSION, Version, version);
|
||||
version.version = v;
|
||||
version.eis = "EIS";
|
||||
|
||||
return eis_proto_send_msg(client, &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_disconnected(struct eis_client *client)
|
||||
{
|
||||
prepare_msg(DISCONNECTED, Disconnected, disconnected);
|
||||
|
||||
return eis_proto_send_msg(client, &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_connected(struct eis_client *client)
|
||||
{
|
||||
prepare_msg(CONNECTED, Connected, connected);
|
||||
|
||||
return eis_proto_send_msg(client, &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_seat_added(struct eis_seat *seat)
|
||||
{
|
||||
prepare_msg(SEAT_ADDED, SeatAdded, seat_added);
|
||||
|
||||
seat_added.seatid = seat->id;
|
||||
seat_added.name = seat->name;
|
||||
seat_added.capabilities = seat->capabilities_mask;
|
||||
|
||||
return eis_proto_send_msg(eis_seat_get_client(seat), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_seat_removed(struct eis_seat *seat)
|
||||
{
|
||||
prepare_msg(SEAT_REMOVED, SeatRemoved, seat_removed);
|
||||
|
||||
seat_removed.seatid = seat->id;
|
||||
|
||||
return eis_proto_send_msg(eis_seat_get_client(seat), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_device_added(struct eis_device *device)
|
||||
{
|
||||
prepare_msg(DEVICE_ADDED, DeviceAdded, device_added);
|
||||
|
||||
struct eis_seat *seat = eis_device_get_seat(device);
|
||||
device_added.deviceid = device->id;
|
||||
device_added.seatid = seat->id;
|
||||
device_added.name = device->name;
|
||||
device_added.capabilities = device->capabilities;
|
||||
device_added.type = device->type;
|
||||
device_added.width = device->width;
|
||||
device_added.height = device->height;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_device_keymap(struct eis_device *device)
|
||||
{
|
||||
prepare_msg(DEVICE_KEYMAP, DeviceKeymap, device_keymap);
|
||||
|
||||
int fds[2] = {-1, -1};
|
||||
|
||||
if (!device->keymap)
|
||||
return 0;
|
||||
|
||||
struct eis_keymap *k = device->keymap;
|
||||
device_keymap.deviceid = device->id;
|
||||
device_keymap.keymap_type = k->type;
|
||||
device_keymap.keymap_size = k->size;
|
||||
fds[0] = k->fd;
|
||||
|
||||
|
||||
return eis_proto_send_msg_with_fds(eis_device_get_client(device), &msg, fds);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_device_done(struct eis_device *device)
|
||||
{
|
||||
prepare_msg(DEVICE_DONE, DeviceDone, device_done);
|
||||
|
||||
device_done.deviceid = device->id;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_device_region(struct eis_device *device, const struct eis_region *r)
|
||||
{
|
||||
prepare_msg(DEVICE_REGION, DeviceRegion, device_region);
|
||||
|
||||
device_region.deviceid = device->id;
|
||||
device_region.offset_x = r->x;
|
||||
device_region.offset_y = r->y;
|
||||
device_region.width = r->width;
|
||||
device_region.height = r->height;
|
||||
device_region.scale = r->physical_scale;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_keyboard_modifiers(struct eis_device *device, const struct eis_xkb_modifiers *mods)
|
||||
{
|
||||
prepare_msg(KEYBOARD_MODIFIERS, KeyboardModifiers, keyboard_modifiers);
|
||||
|
||||
keyboard_modifiers.deviceid = device->id;
|
||||
keyboard_modifiers.depressed = mods->depressed;
|
||||
keyboard_modifiers.locked = mods->locked;
|
||||
keyboard_modifiers.latched = mods->latched;
|
||||
keyboard_modifiers.group = mods->group;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
eis_proto_send_device_removed(struct eis_device *device)
|
||||
{
|
||||
prepare_msg(DEVICE_REMOVED, DeviceRemoved, device_removed);
|
||||
|
||||
device_removed.deviceid = device->id;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_device_paused(struct eis_device *device)
|
||||
{
|
||||
prepare_msg(DEVICE_PAUSED, DevicePaused, device_paused);
|
||||
|
||||
device_paused.deviceid = device->id;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_device_resumed(struct eis_device *device)
|
||||
{
|
||||
prepare_msg(DEVICE_RESUMED, DeviceResumed, device_resumed);
|
||||
|
||||
device_resumed.deviceid = device->id;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_start_emulating(struct eis_device *device, uint32_t deviceid, uint32_t sequence)
|
||||
{
|
||||
prepare_msg(START_EMULATING, StartEmulating, start_emulating);
|
||||
|
||||
start_emulating.deviceid = device->id;
|
||||
start_emulating.sequence = sequence;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_stop_emulating(struct eis_device *device, uint32_t deviceid)
|
||||
{
|
||||
prepare_msg(STOP_EMULATING, StopEmulating, stop_emulating);
|
||||
|
||||
stop_emulating.deviceid = device->id;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_rel(struct eis_device *device, uint32_t deviceid, double x, double y)
|
||||
{
|
||||
prepare_msg(POINTER_RELATIVE, PointerRelative, pointer_relative);
|
||||
|
||||
pointer_relative.deviceid = device->id;
|
||||
pointer_relative.x = x;
|
||||
pointer_relative.y = y;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_abs(struct eis_device *device, uint32_t deviceid, double x, double y)
|
||||
{
|
||||
prepare_msg(POINTER_ABSOLUTE, PointerAbsolute, pointer_absolute);
|
||||
|
||||
pointer_absolute.deviceid = device->id;
|
||||
pointer_absolute.x = x;
|
||||
pointer_absolute.y = y;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_button(struct eis_device *device, uint32_t deviceid,
|
||||
uint32_t button, bool is_press)
|
||||
{
|
||||
prepare_msg(POINTER_BUTTON, PointerButton, pointer_button);
|
||||
|
||||
pointer_button.deviceid = device->id;
|
||||
pointer_button.button = button;
|
||||
pointer_button.state = is_press;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_key(struct eis_device *device, uint32_t deviceid,
|
||||
uint32_t key, bool is_press)
|
||||
{
|
||||
prepare_msg(KEYBOARD_KEY, KeyboardKey, keyboard_key);
|
||||
|
||||
keyboard_key.deviceid = device->id;
|
||||
keyboard_key.key = key;
|
||||
keyboard_key.state = is_press;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_scroll(struct eis_device *device, uint32_t deviceid,
|
||||
double x, double y)
|
||||
{
|
||||
prepare_msg(POINTER_SCROLL, PointerScroll, pointer_scroll);
|
||||
|
||||
pointer_scroll.deviceid = device->id;
|
||||
pointer_scroll.x = x;
|
||||
pointer_scroll.y = y;
|
||||
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_scroll_stop(struct eis_device *device, uint32_t deviceid,
|
||||
bool x, bool y, bool is_cancel)
|
||||
{
|
||||
prepare_msg(POINTER_SCROLL_STOP, PointerScrollStop, pointer_scroll_stop);
|
||||
|
||||
pointer_scroll_stop.deviceid = device->id;
|
||||
pointer_scroll_stop.x = x;
|
||||
pointer_scroll_stop.y = y;
|
||||
pointer_scroll_stop.is_cancel = is_cancel;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_scroll_discrete(struct eis_device *device, uint32_t deviceid,
|
||||
int32_t x, int32_t y)
|
||||
{
|
||||
|
||||
prepare_msg(POINTER_SCROLL_DISCRETE, PointerScrollDiscrete, pointer_scroll_discrete);
|
||||
|
||||
pointer_scroll_discrete.deviceid = device->id;
|
||||
pointer_scroll_discrete.x = x;
|
||||
pointer_scroll_discrete.y = y;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_touch_down(struct eis_device *device, uint32_t deviceid,
|
||||
uint32_t tid, double x, double y)
|
||||
{
|
||||
prepare_msg(TOUCH_DOWN, TouchDown, touch_down);
|
||||
|
||||
touch_down.deviceid = device->id;
|
||||
touch_down.touchid = tid;
|
||||
touch_down.x = x;
|
||||
touch_down.y = y;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_touch_motion(struct eis_device *device, uint32_t deviceid,
|
||||
uint32_t tid, double x, double y)
|
||||
{
|
||||
prepare_msg(TOUCH_MOTION, TouchMotion, touch_motion);
|
||||
|
||||
touch_motion.deviceid = device->id;
|
||||
touch_motion.touchid = tid;
|
||||
touch_motion.x = x;
|
||||
touch_motion.y = y;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_touch_up(struct eis_device *device, uint32_t deviceid, uint32_t tid)
|
||||
{
|
||||
prepare_msg(TOUCH_UP, TouchUp, touch_up);
|
||||
|
||||
touch_up.deviceid = device->id;
|
||||
touch_up.touchid = tid;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static int
|
||||
eis_proto_send_frame(struct eis_device *device, uint32_t deviceid, uint64_t time)
|
||||
{
|
||||
prepare_msg(FRAME, Frame, frame);
|
||||
|
||||
frame.deviceid = device->id;
|
||||
frame.timestamp = time;
|
||||
|
||||
return eis_proto_send_msg(eis_device_get_client(device), &msg);
|
||||
}
|
||||
|
||||
static const struct eis_proto_requests requests = {
|
||||
.disconnected = eis_proto_send_disconnected,
|
||||
.connected = eis_proto_send_connected,
|
||||
.seat_added = eis_proto_send_seat_added,
|
||||
.seat_removed = eis_proto_send_seat_removed,
|
||||
.device_added = eis_proto_send_device_added,
|
||||
.device_removed = eis_proto_send_device_removed,
|
||||
.device_paused = eis_proto_send_device_paused,
|
||||
.device_resumed = eis_proto_send_device_resumed,
|
||||
.device_keymap = eis_proto_send_device_keymap,
|
||||
.device_done = eis_proto_send_device_done,
|
||||
.device_region = eis_proto_send_device_region,
|
||||
.keyboard_modifiers = eis_proto_send_keyboard_modifiers,
|
||||
.version = eis_proto_send_version,
|
||||
|
||||
/* events */
|
||||
.start_emulating = eis_proto_send_start_emulating,
|
||||
.stop_emulating = eis_proto_send_stop_emulating,
|
||||
.rel = eis_proto_send_rel,
|
||||
.abs = eis_proto_send_abs,
|
||||
.button = eis_proto_send_button,
|
||||
.scroll = eis_proto_send_scroll,
|
||||
.scroll_stop = eis_proto_send_scroll_stop,
|
||||
.scroll_discrete = eis_proto_send_scroll_discrete,
|
||||
.key = eis_proto_send_key,
|
||||
.touch_down = eis_proto_send_touch_down,
|
||||
.touch_motion = eis_proto_send_touch_motion,
|
||||
.touch_up = eis_proto_send_touch_up,
|
||||
.frame = eis_proto_send_frame,
|
||||
};
|
||||
|
||||
const struct eis_proto_requests *
|
||||
eis_proto_get_requests(void) {
|
||||
return &requests;
|
||||
}
|
||||
|
||||
static void clientmessage_cleanup(ClientMessage **m) {
|
||||
if (*m)
|
||||
client_message__free_unpacked(*m, NULL);
|
||||
}
|
||||
#define _cleanup_clientmessage_ _cleanup_(clientmessage_cleanup)
|
||||
|
||||
int
|
||||
eis_proto_handle_message(struct eis_client *client,
|
||||
const struct eis_proto_interface *interface,
|
||||
struct brei_message *bmsg)
|
||||
{
|
||||
_cleanup_clientmessage_ ClientMessage *proto = client_message__unpack(NULL, bmsg->len,
|
||||
(const unsigned char*)bmsg->data);
|
||||
if (!proto)
|
||||
return -EAGAIN;
|
||||
|
||||
#define call(field, ...) \
|
||||
({ \
|
||||
int r = (interface->field == NULL) ? -EPROTO : interface->field(__VA_ARGS__); \
|
||||
log_debug(eis_client_get_context(client), "message type '" #field "': errno %d (%s)", -r, strerror(-r)); \
|
||||
r; \
|
||||
})
|
||||
|
||||
int rc;
|
||||
switch (proto->msg_case) {
|
||||
case CLIENT_MESSAGE__MSG_CONNECT:
|
||||
rc = call(connect, client, proto->connect->version,
|
||||
proto->connect->name, proto->connect->is_sender);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_CONNECT_DONE:
|
||||
rc = call(connect_done, client);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_DISCONNECT:
|
||||
rc = call(disconnect, client);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_BIND_SEAT:
|
||||
rc = call(bind_seat, client,
|
||||
proto->bind_seat->seatid,
|
||||
proto->bind_seat->capabilities);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_CLOSE_DEVICE:
|
||||
rc = call(close_device, client,
|
||||
proto->close_device->deviceid);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_GET_VERSION:
|
||||
rc = call(get_version, client);
|
||||
break;
|
||||
/* Events */
|
||||
case CLIENT_MESSAGE__MSG_START_EMULATING:
|
||||
rc = call(start_emulating, client,
|
||||
proto->start_emulating->deviceid,
|
||||
proto->start_emulating->sequence);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_STOP_EMULATING:
|
||||
rc = call(stop_emulating, client,
|
||||
proto->stop_emulating->deviceid);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_POINTER_RELATIVE:
|
||||
rc = call(rel, client,
|
||||
proto->pointer_relative->deviceid,
|
||||
proto->pointer_relative->x,
|
||||
proto->pointer_relative->y);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_POINTER_ABSOLUTE:
|
||||
rc = call(abs, client,
|
||||
proto->pointer_absolute->deviceid,
|
||||
proto->pointer_absolute->x,
|
||||
proto->pointer_absolute->y);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_POINTER_BUTTON:
|
||||
rc = call(button, client,
|
||||
proto->pointer_button->deviceid,
|
||||
proto->pointer_button->button,
|
||||
proto->pointer_button->state);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_POINTER_SCROLL:
|
||||
rc = call(scroll, client,
|
||||
proto->pointer_scroll->deviceid,
|
||||
proto->pointer_scroll->x,
|
||||
proto->pointer_scroll->y);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_POINTER_SCROLL_STOP:
|
||||
rc = call(scroll_stop, client,
|
||||
proto->pointer_scroll_stop->deviceid,
|
||||
proto->pointer_scroll_stop->x,
|
||||
proto->pointer_scroll_stop->y,
|
||||
proto->pointer_scroll_stop->is_cancel);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_POINTER_SCROLL_DISCRETE:
|
||||
rc = call(scroll_discrete, client,
|
||||
proto->pointer_scroll_discrete->deviceid,
|
||||
proto->pointer_scroll_discrete->x,
|
||||
proto->pointer_scroll_discrete->y);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_KEYBOARD_KEY:
|
||||
rc = call(key, client,
|
||||
proto->keyboard_key->deviceid,
|
||||
proto->keyboard_key->key,
|
||||
proto->keyboard_key->state);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_TOUCH_DOWN:
|
||||
rc = call(touch_down, client,
|
||||
proto->touch_down->deviceid,
|
||||
proto->touch_down->touchid,
|
||||
proto->touch_down->x,
|
||||
proto->touch_down->y);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_TOUCH_MOTION:
|
||||
rc = call(touch_motion, client,
|
||||
proto->touch_motion->deviceid,
|
||||
proto->touch_motion->touchid,
|
||||
proto->touch_motion->x,
|
||||
proto->touch_motion->y);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_TOUCH_UP:
|
||||
rc = call(touch_up, client,
|
||||
proto->touch_up->deviceid,
|
||||
proto->touch_up->touchid);
|
||||
break;
|
||||
case CLIENT_MESSAGE__MSG_FRAME:
|
||||
rc = call(frame, client, proto->frame->deviceid, proto->frame->timestamp);
|
||||
break;
|
||||
default:
|
||||
rc = -EBADMSG;
|
||||
break;
|
||||
}
|
||||
|
||||
return rc < 0 ? rc : (int)bmsg->len;
|
||||
}
|
||||
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
/* SPDX-License-Identifier: MIT */
|
||||
/*
|
||||
* Copyright © 2020 Red Hat, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "util-macros.h"
|
||||
#include "util-mem.h"
|
||||
|
||||
#include "brei-shared.h"
|
||||
#include "libeis-private.h"
|
||||
|
||||
/* callbacks invoked during eis_proto_parse_message() */
|
||||
struct eis_proto_interface {
|
||||
int (*connect)(struct eis_client *client, uint32_t version, const char *name, bool is_sender);
|
||||
int (*connect_done)(struct eis_client *client);
|
||||
int (*disconnect)(struct eis_client *client);
|
||||
int (*bind_seat)(struct eis_client *client, uint32_t seatid, enum eis_device_capability cap);
|
||||
int (*unbind_seat)(struct eis_client *client, uint32_t seatid, enum eis_device_capability cap);
|
||||
int (*close_device)(struct eis_client *client, uint32_t deviceid);
|
||||
int (*get_version)(struct eis_client *client);
|
||||
/* events */
|
||||
int (*start_emulating)(struct eis_client *client, uint32_t deviceid, uint32_t sequence);
|
||||
int (*stop_emulating)(struct eis_client *client, uint32_t deviceid);
|
||||
int (*rel)(struct eis_client *client, uint32_t deviceid, double x, double y);
|
||||
int (*abs)(struct eis_client *client, uint32_t deviceid, double x, double y);
|
||||
int (*button)(struct eis_client *client, uint32_t deviceid, uint32_t button, bool is_press);
|
||||
int (*key)(struct eis_client *client, uint32_t deviceid, uint32_t key, bool is_press);
|
||||
int (*scroll)(struct eis_client *client, uint32_t deviceid, double x, double y);
|
||||
int (*scroll_stop)(struct eis_client *client, uint32_t deviceid, bool x, bool y, bool is_cancel);
|
||||
int (*scroll_discrete)(struct eis_client *client, uint32_t deviceid, int32_t x, int32_t y);
|
||||
int (*touch_down)(struct eis_client *client, uint32_t deviceid,
|
||||
uint32_t tid, double x, double y);
|
||||
int (*touch_motion)(struct eis_client *client, uint32_t deviceid,
|
||||
uint32_t tid, double x, double y);
|
||||
int (*touch_up)(struct eis_client *client, uint32_t deviceid, uint32_t tid);
|
||||
int (*frame) (struct eis_client *client, uint32_t deviceid, uint64_t time);
|
||||
};
|
||||
|
||||
struct eis_proto_requests {
|
||||
int (*connected)(struct eis_client *client);
|
||||
int (*disconnected)(struct eis_client *client);
|
||||
int (*seat_added)(struct eis_seat *seat);
|
||||
int (*seat_removed)(struct eis_seat *seat);
|
||||
int (*device_added)(struct eis_device *device);
|
||||
int (*device_removed)(struct eis_device *device);
|
||||
int (*device_paused)(struct eis_device *device);
|
||||
int (*device_resumed)(struct eis_device *device);
|
||||
int (*device_keymap)(struct eis_device *device);
|
||||
int (*device_done)(struct eis_device *device);
|
||||
int (*device_region)(struct eis_device *device,
|
||||
const struct eis_region *region);
|
||||
int (*keyboard_modifiers)(struct eis_device *device,
|
||||
const struct eis_xkb_modifiers *mods);
|
||||
int (*version)(struct eis_client *client, uint32_t version);
|
||||
|
||||
/* events */
|
||||
int (*start_emulating)(struct eis_device *device, uint32_t deviceid, uint32_t sequence);
|
||||
int (*stop_emulating)(struct eis_device *device, uint32_t deviceid);
|
||||
int (*rel)(struct eis_device *device, uint32_t deviceid, double x, double y);
|
||||
int (*abs)(struct eis_device *device, uint32_t deviceid, double x, double y);
|
||||
int (*button)(struct eis_device *device, uint32_t deviceid, uint32_t button, bool is_press);
|
||||
int (*key)(struct eis_device *device, uint32_t deviceid, uint32_t key, bool is_press);
|
||||
int (*scroll)(struct eis_device *device, uint32_t deviceid, double x, double y);
|
||||
int (*scroll_stop)(struct eis_device *device, uint32_t deviceid, bool x, bool y, bool is_cancel);
|
||||
int (*scroll_discrete)(struct eis_device *device, uint32_t deviceid, int32_t x, int32_t y);
|
||||
int (*touch_down)(struct eis_device *device, uint32_t deviceid,
|
||||
uint32_t tid, double x, double y);
|
||||
int (*touch_motion)(struct eis_device *device, uint32_t deviceid,
|
||||
uint32_t tid, double x, double y);
|
||||
int (*touch_up)(struct eis_device *device, uint32_t deviceid, uint32_t tid);
|
||||
int (*frame) (struct eis_device *device, uint32_t deviceid, uint64_t time);
|
||||
};
|
||||
|
||||
int
|
||||
eis_proto_handle_message(struct eis_client *client,
|
||||
const struct eis_proto_interface *interface,
|
||||
struct brei_message *message);
|
||||
|
||||
const struct eis_proto_requests *
|
||||
eis_proto_get_requests(void);
|
||||
Loading…
Add table
Reference in a new issue