/* * 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 #include #include #include #include #include #include "libei.h" #include "src/util-mem.h" #include "src/util-strings.h" int main(int argc, char **argv) { const char SOCKETNAME[] = "eis.socket"; struct ei *ei = ei_socket_new_context(NULL); assert(ei); ei_configure_name(ei, "ei-socket-client-demo"); /* This should be handled by libei */ signal(SIGPIPE, SIG_IGN); int rc = ei_socket_init(ei, getenv("LIBEI_SOCKET") ? NULL : SOCKETNAME); if (rc != 0) { fprintf(stderr, "init failed: %s\n", strerror(errno)); return 1; } printf("client: connected to %s\n", SOCKETNAME); struct pollfd fds = { .fd = ei_get_fd(ei), .events = POLLIN, .revents = 0, }; struct ei_device *ptr = ei_device_new(ei); ei_device_configure_capability(ptr, EI_DEVICE_CAP_POINTER); bool stop = false; bool have_device = false; while (!stop && poll(&fds, 1, 2000) > -1) { ei_dispatch(ei); while (true) { struct ei_event *e = ei_get_event(ei); if (!e) break; switch(ei_event_get_type(e)) { case EI_EVENT_CONNECT: printf("client: connected\n"); ei_device_add(ptr); break; case EI_EVENT_DISCONNECT: { printf("client: disconnected us\n"); stop = true; break; } case EI_EVENT_DEVICE_ADDED: { printf("client: our device was accepted\n"); have_device = true; break; } case EI_EVENT_DEVICE_REMOVED: { printf("client: our device was removed\n"); have_device = false; break; } default: abort(); } ei_event_unref(e); } if (have_device) { ei_device_pointer_motion(ptr, -1, 1); } } ei_unref(ei); return 0; }