mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2025-12-28 09:40:07 +01:00
This is the minimum framework to support new clients, added devices and pointer relative motion events. It's missing a bunch of checks and verification, most of the server hooks aren't there yet, the only implementation is a UNIX socket and the protocol is plain text (but at least the last two makes it netcat-compatible). Protocol is plain text for now and interaction is like this (S is server, C is client): S: hello C: connect myclientname S: connected C: add 2 4 S: accept 2 C: rel 2 -1 1 C: rel 2 5 4 Where the last two lines are: add device with id 2 and capability mask 0x4, send a relative pointer motion event for device 2 with coordinates -1/1, then 5/4. The implementation relies heavily on some abstraction and macros galore, see the various util-* files. These are largely copied from libinput, with a few parts removed and a few other parts added. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
115 lines
3.5 KiB
C
115 lines
3.5 KiB
C
/*
|
|
* 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 <assert.h>
|
|
#include <errno.h>
|
|
#include <poll.h>
|
|
#include <stdio.h>
|
|
#include <signal.h>
|
|
#include <string.h>
|
|
|
|
#include "libeis.h"
|
|
|
|
#include "src/util-mem.h"
|
|
#include "src/util-strings.h"
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
const char SOCKETNAME[] = "eis.socket";
|
|
struct eis *eis = eis_socket_new_context(NULL);
|
|
assert(eis);
|
|
|
|
const char *xdgdir = getenv("XDG_RUNTIME_DIR");
|
|
assert(xdgdir != NULL);
|
|
|
|
_cleanup_free_ char *socketpath = xaprintf("%s/%s", xdgdir, SOCKETNAME);
|
|
unlink(socketpath);
|
|
|
|
/* This should be handled by libeis */
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
int rc = eis_socket_init(eis, SOCKETNAME);
|
|
if (rc != 0) {
|
|
fprintf(stderr, "init failed: %s\n", strerror(errno));
|
|
return 1;
|
|
}
|
|
|
|
struct pollfd fds = {
|
|
.fd = eis_get_fd(eis),
|
|
.events = POLLIN,
|
|
.revents = 0,
|
|
};
|
|
|
|
while (poll(&fds, 1, -1) > -1) {
|
|
eis_dispatch(eis);
|
|
struct eis_event *e = eis_get_event(eis);
|
|
if (!e)
|
|
continue;
|
|
|
|
switch(eis_event_get_type(e)) {
|
|
case EIS_EVENT_CLIENT_CONNECT:
|
|
{
|
|
struct eis_client *client = eis_event_get_client(e);
|
|
printf("server: new client: %s\n", eis_client_get_name(client));
|
|
/* insert sophisticated authentication here */
|
|
eis_client_connect(client);
|
|
printf("server: accepting client\n");
|
|
break;
|
|
}
|
|
case EIS_EVENT_CLIENT_DISCONNECT:
|
|
{
|
|
struct eis_client *client = eis_event_get_client(e);
|
|
printf("server: client %s disconnected\n", eis_client_get_name(client));
|
|
eis_client_disconnect(client);
|
|
break;
|
|
}
|
|
case EIS_EVENT_DEVICE_ADDED:
|
|
{
|
|
struct eis_device *device = eis_event_get_device(e);
|
|
printf("server: new device, caps:%s%s%s%s\n",
|
|
eis_device_has_capability(device, EIS_DEVICE_CAP_POINTER) ? " ptr" : "",
|
|
eis_device_has_capability(device, EIS_DEVICE_CAP_KEYBOARD) ? " kbd" : "",
|
|
eis_device_has_capability(device, EIS_DEVICE_CAP_POINTER_ABSOLUTE) ? " abs" : "",
|
|
eis_device_has_capability(device, EIS_DEVICE_CAP_TOUCH) ? " touch" : "");
|
|
/* insert sophisticated device checks here */
|
|
eis_device_connect(device);
|
|
break;
|
|
}
|
|
case EIS_EVENT_POINTER_MOTION:
|
|
{
|
|
struct eis_event_pointer *p = eis_event_get_pointer_event(e);
|
|
printf("server: motion by %d/%d\n",
|
|
eis_event_pointer_get_x(p),
|
|
eis_event_pointer_get_y(p));
|
|
}
|
|
break;
|
|
default:
|
|
abort();
|
|
}
|
|
eis_event_unref(e);
|
|
}
|
|
|
|
return 0;
|
|
}
|