From d794678b90e863a38c924b4f95515dcfec9f27ce Mon Sep 17 00:00:00 2001 From: David Redondo Date: Fri, 5 Apr 2024 11:20:30 +0200 Subject: [PATCH 1/3] ei-demo-client: Remove obsolote portal option --- tools/ei-demo-client.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tools/ei-demo-client.c b/tools/ei-demo-client.c index 93351f9..b7f09a4 100644 --- a/tools/ei-demo-client.c +++ b/tools/ei-demo-client.c @@ -175,8 +175,6 @@ usage(FILE *fp, const char *argv0) "Options:\n" " --socket Use the socket backend. The socket path is $LIBEI_SOCKET if set, \n" " otherwise $XDG_RUNTIME_DIR/eis-0\n" - " --portal Use the portal backend.\n" - " --busname Use the given busname (default: org.freedesktop.portal.Desktop)\n" " --verbose Enable debugging output\n" " --receiver Create a receiver EIS context, receiving events instead of sending them\n" " --interval Interval in milliseconds between polling\n" @@ -189,7 +187,6 @@ int main(int argc, char **argv) { enum { SOCKET, - PORTAL, } backend = SOCKET; bool verbose = false; bool receiver = false; @@ -200,8 +197,6 @@ int main(int argc, char **argv) while (1) { enum { OPT_BACKEND_SOCKET, - OPT_BACKEND_PORTAL, - OPT_BUSNAME, OPT_VERBOSE, OPT_RECEIVER, OPT_INTERVAL, @@ -209,8 +204,6 @@ int main(int argc, char **argv) }; static struct option long_opts[] = { {"socket", no_argument, 0, OPT_BACKEND_SOCKET}, - {"portal", no_argument, 0, OPT_BACKEND_PORTAL}, - {"busname", required_argument, 0, OPT_BUSNAME}, {"verbose", no_argument, 0, OPT_VERBOSE}, {"receiver", no_argument, 0, OPT_RECEIVER}, {"interval", required_argument, 0, OPT_INTERVAL}, @@ -234,12 +227,6 @@ int main(int argc, char **argv) case OPT_BACKEND_SOCKET: backend = SOCKET; break; - case OPT_BACKEND_PORTAL: - backend = PORTAL; - break; - case OPT_BUSNAME: - free(busname); - busname = xstrdup(optarg); break; case OPT_RECEIVER: receiver = true; @@ -274,11 +261,6 @@ int main(int argc, char **argv) const char SOCKETNAME[] = "eis-0"; colorprint("connecting to %s\n", SOCKETNAME); rc = ei_setup_backend_socket(ei, getenv("LIBEI_SOCKET") ? NULL : SOCKETNAME); - } else if (backend == PORTAL) { -#if ENABLE_LIBEI_PORTAL - colorprint("connecting to %s\n", busname); - rc = ei_setup_backend_portal_busname(ei, busname); -#endif } if (rc != 0) { From f12a01baf9f82b48c75af4addd4272bed4aa1877 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Fri, 5 Apr 2024 11:52:02 +0200 Subject: [PATCH 2/3] Allow passing a fd to ei-demo-client Like in ei-debug-events --- tools/ei-demo-client.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/ei-demo-client.c b/tools/ei-demo-client.c index b7f09a4..18e62eb 100644 --- a/tools/ei-demo-client.c +++ b/tools/ei-demo-client.c @@ -57,6 +57,7 @@ #include "src/util-mem.h" #include "src/util-memfile.h" #include "src/util-color.h" +#include "src/util-io.h" #include "src/util-strings.h" #include "src/util-time.h" @@ -175,6 +176,7 @@ usage(FILE *fp, const char *argv0) "Options:\n" " --socket Use the socket backend. The socket path is $LIBEI_SOCKET if set, \n" " otherwise $XDG_RUNTIME_DIR/eis-0\n" + " --socketfd Use the given fd as socket to the EIS implementation\n" " --verbose Enable debugging output\n" " --receiver Create a receiver EIS context, receiving events instead of sending them\n" " --interval Interval in milliseconds between polling\n" @@ -187,7 +189,9 @@ int main(int argc, char **argv) { enum { SOCKET, + FD, } backend = SOCKET; + _cleanup_close_ int socketfd = -1; bool verbose = false; bool receiver = false; unsigned int interval = 2000; @@ -201,9 +205,11 @@ int main(int argc, char **argv) OPT_RECEIVER, OPT_INTERVAL, OPT_ITERATIONS, + OPT_SOCKETFD, }; static struct option long_opts[] = { {"socket", no_argument, 0, OPT_BACKEND_SOCKET}, + {"socketfd", required_argument, 0, OPT_SOCKETFD}, {"verbose", no_argument, 0, OPT_VERBOSE}, {"receiver", no_argument, 0, OPT_RECEIVER}, {"interval", required_argument, 0, OPT_INTERVAL}, @@ -227,6 +233,12 @@ int main(int argc, char **argv) case OPT_BACKEND_SOCKET: backend = SOCKET; break; + case OPT_SOCKETFD: + backend = FD; + if (!xatoi(optarg, &socketfd)) { + fprintf(stderr, "Invalid socketfd: %s", optarg); + return 2; + } break; case OPT_RECEIVER: receiver = true; @@ -261,6 +273,8 @@ int main(int argc, char **argv) const char SOCKETNAME[] = "eis-0"; colorprint("connecting to %s\n", SOCKETNAME); rc = ei_setup_backend_socket(ei, getenv("LIBEI_SOCKET") ? NULL : SOCKETNAME); + } else if (backend == FD) { + rc = ei_setup_backend_fd(ei, socketfd); } if (rc != 0) { From 737d25f68d86a6a634667319c7be754bec6727e9 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Fri, 5 Apr 2024 11:52:38 +0200 Subject: [PATCH 3/3] Let oeffis-demo-tool start ei-demo-client optionally This allows testing the EIS implementation when no public socket is available. --- tools/oeffis-demo-tool.c | 78 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/tools/oeffis-demo-tool.c b/tools/oeffis-demo-tool.c index 11e26ce..bab72b7 100644 --- a/tools/oeffis-demo-tool.c +++ b/tools/oeffis-demo-tool.c @@ -29,6 +29,7 @@ #include "config.h" #include +#include #include #include #include @@ -67,8 +68,76 @@ static void start_debug_events(int fd) } } +static void start_demo_client(int fd) +{ + pid_t pid = fork(); + assert(pid != -1); + + if (pid == 0) { + _cleanup_free_ char *fdstr = xaprintf("%d", fd); + execl(MESON_BUILDDIR "/ei-demo-client", + "ei-demo-client", + "--socketfd", fdstr, NULL); + fprintf(stderr, "Failed to fork: %m\n"); + exit(1); + } +} + +static void +usage(FILE *fp, const char *argv0) +{ + fprintf(fp, + "Usage: %s [--debug|--sendevents]\n" + "\n" + "Connect to the EIS implementation via the remote desktop portal.\n" + "Afterwards the specified action is taken.\n" + "\n" + "Options:\n" + " --debug print communication with the EIS implementation (default)\n" + " --sendevents send emulated keyboard and pointer events in a loop\n", + argv0); +} + int main(int argc, char **argv) { + enum { + DEBUG, + CLIENT, + } action = DEBUG; + + while (1) { + enum { + OPT_DEBUG, + OPT_SENDEVENTS, + }; + static struct option long_opts[] = { + {"debug", required_argument, 0, OPT_DEBUG}, + {"sendevents", no_argument, 0, OPT_SENDEVENTS}, + {"help", no_argument, 0, 'h'}, + {.name = NULL}, + }; + + int optind = 0; + int c = getopt_long(argc, argv, "h", long_opts, &optind); + if (c == -1) + break; + + switch(c) { + case 'h': + usage(stdout, argv[0]); + return EXIT_SUCCESS; + case OPT_DEBUG: + action = DEBUG; + break; + case OPT_SENDEVENTS: + action = CLIENT; + break; + default: + usage(stderr, argv[0]); + return EXIT_FAILURE; + } + } + _unref_(oeffis) *oeffis = oeffis_new(NULL); signal(SIGINT, sighandler); @@ -103,7 +172,14 @@ int main(int argc, char **argv) * cause the compositor or the portal to invalidate * our EIS fd. */ - start_debug_events(eisfd); + switch (action) { + case DEBUG: + start_debug_events(eisfd); + break; + case CLIENT: + start_demo_client(eisfd); + break; + } break; } case OEFFIS_EVENT_DISCONNECTED: