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: