mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2025-12-25 16:20:06 +01:00
Now that the backend is more of an implementation detail, namespace for eis_setup_backend_foo() Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
153 lines
4.4 KiB
C
153 lines
4.4 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"
|
|
|
|
static bool stop = false;
|
|
|
|
static void sighandler(int signal) {
|
|
stop = true;
|
|
}
|
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(struct eis *, eis_unref);
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
_cleanup_(eis_unrefp) struct eis *eis = eis_new(NULL);
|
|
assert(eis);
|
|
|
|
_cleanup_free_ char *socketpath = NULL;
|
|
if (argc < 2) {
|
|
const char SOCKETNAME[] = "eis.socket";
|
|
const char *xdgdir = getenv("XDG_RUNTIME_DIR");
|
|
assert(xdgdir != NULL);
|
|
socketpath = xaprintf("%s/%s", xdgdir, SOCKETNAME);
|
|
} else {
|
|
socketpath = xstrdup(argv[1]);
|
|
}
|
|
|
|
signal(SIGINT, sighandler);
|
|
|
|
int rc = eis_setup_backend_socket(eis, socketpath);
|
|
if (rc != 0) {
|
|
fprintf(stderr, "init failed: %s\n", strerror(errno));
|
|
return 1;
|
|
}
|
|
|
|
printf("server: waiting on %s\n", socketpath);
|
|
|
|
struct pollfd fds = {
|
|
.fd = eis_get_fd(eis),
|
|
.events = POLLIN,
|
|
.revents = 0,
|
|
};
|
|
|
|
while (!stop && poll(&fds, 1, -1) > -1) {
|
|
eis_dispatch(eis);
|
|
|
|
while (true) {
|
|
struct eis_event *e = eis_get_event(eis);
|
|
if (!e)
|
|
break;
|
|
|
|
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_DEVICE_REMOVED:
|
|
{
|
|
printf("server: device removed\n");
|
|
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;
|
|
case EIS_EVENT_POINTER_BUTTON:
|
|
{
|
|
struct eis_event_pointer *p = eis_event_get_pointer_event(e);
|
|
printf("server: button %d (%s)\n",
|
|
eis_event_pointer_get_button(p),
|
|
eis_event_pointer_get_button_is_press(p) ? "press" : "release");
|
|
}
|
|
break;
|
|
case EIS_EVENT_KEYBOARD_KEY:
|
|
{
|
|
struct eis_event_keyboard *k = eis_event_get_keyboard_event(e);
|
|
printf("server: key %d (%s)\n",
|
|
eis_event_keyboard_get_key(k),
|
|
eis_event_keyboard_get_key_is_press(k) ? "press" : "release");
|
|
}
|
|
break;
|
|
default:
|
|
abort();
|
|
}
|
|
eis_event_unref(e);
|
|
}
|
|
}
|
|
|
|
unlink(socketpath);
|
|
|
|
return 0;
|
|
}
|