From 062c74b7d01a543c69d206a036deff75bc9f7cf1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 27 Nov 2015 10:10:29 -0500 Subject: Add command line to swaygrab Also modifies IPC client so that we can work with persistent connections. --- swaygrab/main.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'swaygrab') diff --git a/swaygrab/main.c b/swaygrab/main.c index 4a15bd06..bd64bd93 100644 --- a/swaygrab/main.c +++ b/swaygrab/main.c @@ -1,12 +1,65 @@ #include #include #include "log.h" +#include "ipc-client.h" void sway_terminate(void) { exit(1); } int main(int argc, const char **argv) { + int capture; + char *socket_path = NULL; + init_log(L_INFO); - sway_log(L_INFO, "Hello world!"); + + static struct option long_options[] = { + {"capture", no_argument, &capture, 'c'}, + {"version", no_argument, NULL, 'v'}, + {"socket", required_argument, NULL, 's'}, + {0, 0, 0, 0} + }; + + int c; + while (1) { + int option_index = 0; + c = getopt_long(argc, argv, "cvs:", long_options, &option_index); + if (c == -1) { + break; + } + switch (c) { + case 0: // Flag + break; + case 's': // Socket + socket_path = strdup(optarg); + break; + case 'v': +#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE + fprintf(stdout, "sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH); +#else + fprintf(stdout, "version not detected\n"); +#endif + exit(0); + break; + } + } + + if (!socket_path) { + socket_path = get_socketpath(); + if (!socket_path) { + sway_abort("Unable to retrieve socket path"); + } + } + + if (optind >= argc) { + sway_abort("Expected output file on command line. See `man swaygrab`"); + } + + char *out = argv[optind]; + int socketfd = ipc_open_socket(socket_path); + free(socket_path); + + close(socketfd); + free(out); + return 0; } -- cgit v1.2.3-54-g00ecf