mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-05-15 11:38:09 +02:00
Let oeffis-demo-tool start ei-demo-client optionally
This commit is contained in:
parent
cea415fc40
commit
cd7ec93eda
1 changed files with 80 additions and 1 deletions
|
|
@ -29,6 +29,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -71,9 +72,80 @@ 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 [--client=debug-events|demo-client]\n"
|
||||||
|
"\n"
|
||||||
|
"Connect to the EIS implementation via the remote desktop portal.\n"
|
||||||
|
"Afterwards the specified action is taken.\n"
|
||||||
|
"\n"
|
||||||
|
"Options:\n"
|
||||||
|
" --client the tool to launch after connecting to the eis implementation,\n"
|
||||||
|
" one of debug-events (default) or demo-client\n",
|
||||||
|
argv0);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
enum {
|
||||||
|
DEBUG,
|
||||||
|
CLIENT,
|
||||||
|
} action = DEBUG;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
enum {
|
||||||
|
OPT_CLIENT,
|
||||||
|
};
|
||||||
|
static struct option long_opts[] = {
|
||||||
|
{"client", required_argument, 0, OPT_CLIENT},
|
||||||
|
{"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_CLIENT:
|
||||||
|
action = DEBUG;
|
||||||
|
if (strcmp(optarg, "debug-events") == 0) {
|
||||||
|
action = DEBUG;
|
||||||
|
break;
|
||||||
|
} else if (strcmp(optarg, "demo-client") == 0) {
|
||||||
|
action = CLIENT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_fallthrough_;
|
||||||
|
default:
|
||||||
|
usage(stderr, argv[0]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_unref_(oeffis) *oeffis = oeffis_new(NULL);
|
_unref_(oeffis) *oeffis = oeffis_new(NULL);
|
||||||
|
|
||||||
signal(SIGINT, sighandler);
|
signal(SIGINT, sighandler);
|
||||||
|
|
@ -108,8 +180,15 @@ main(int argc, char **argv)
|
||||||
* cause the compositor or the portal to invalidate
|
* cause the compositor or the portal to invalidate
|
||||||
* our EIS fd.
|
* our EIS fd.
|
||||||
*/
|
*/
|
||||||
|
switch (action) {
|
||||||
|
case DEBUG:
|
||||||
start_debug_events(eisfd);
|
start_debug_events(eisfd);
|
||||||
break;
|
break;
|
||||||
|
case CLIENT:
|
||||||
|
start_demo_client(eisfd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case OEFFIS_EVENT_DISCONNECTED:
|
case OEFFIS_EVENT_DISCONNECTED:
|
||||||
fprintf(stderr, "Disconnected: %s\n", oeffis_get_error_message(oeffis));
|
fprintf(stderr, "Disconnected: %s\n", oeffis_get_error_message(oeffis));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue