diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-11-27 10:10:29 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-11-27 10:10:29 -0500 |
commit | 062c74b7d01a543c69d206a036deff75bc9f7cf1 (patch) | |
tree | 6ac5b23e1ca2b471a82c9e2978e0e9d2db1b5bc4 /swaygrab/main.c | |
parent | Add swaygrab(1) man page (diff) | |
download | sway-062c74b7d01a543c69d206a036deff75bc9f7cf1.tar.gz sway-062c74b7d01a543c69d206a036deff75bc9f7cf1.tar.zst sway-062c74b7d01a543c69d206a036deff75bc9f7cf1.zip |
Add command line to swaygrab
Also modifies IPC client so that we can work with persistent
connections.
Diffstat (limited to 'swaygrab/main.c')
-rw-r--r-- | swaygrab/main.c | 55 |
1 files changed, 54 insertions, 1 deletions
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 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include "log.h" | 3 | #include "log.h" |
4 | #include "ipc-client.h" | ||
4 | 5 | ||
5 | void sway_terminate(void) { | 6 | void sway_terminate(void) { |
6 | exit(1); | 7 | exit(1); |
7 | } | 8 | } |
8 | 9 | ||
9 | int main(int argc, const char **argv) { | 10 | int main(int argc, const char **argv) { |
11 | int capture; | ||
12 | char *socket_path = NULL; | ||
13 | |||
10 | init_log(L_INFO); | 14 | init_log(L_INFO); |
11 | sway_log(L_INFO, "Hello world!"); | 15 | |
16 | static struct option long_options[] = { | ||
17 | {"capture", no_argument, &capture, 'c'}, | ||
18 | {"version", no_argument, NULL, 'v'}, | ||
19 | {"socket", required_argument, NULL, 's'}, | ||
20 | {0, 0, 0, 0} | ||
21 | }; | ||
22 | |||
23 | int c; | ||
24 | while (1) { | ||
25 | int option_index = 0; | ||
26 | c = getopt_long(argc, argv, "cvs:", long_options, &option_index); | ||
27 | if (c == -1) { | ||
28 | break; | ||
29 | } | ||
30 | switch (c) { | ||
31 | case 0: // Flag | ||
32 | break; | ||
33 | case 's': // Socket | ||
34 | socket_path = strdup(optarg); | ||
35 | break; | ||
36 | case 'v': | ||
37 | #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE | ||
38 | fprintf(stdout, "sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH); | ||
39 | #else | ||
40 | fprintf(stdout, "version not detected\n"); | ||
41 | #endif | ||
42 | exit(0); | ||
43 | break; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | if (!socket_path) { | ||
48 | socket_path = get_socketpath(); | ||
49 | if (!socket_path) { | ||
50 | sway_abort("Unable to retrieve socket path"); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | if (optind >= argc) { | ||
55 | sway_abort("Expected output file on command line. See `man swaygrab`"); | ||
56 | } | ||
57 | |||
58 | char *out = argv[optind]; | ||
59 | int socketfd = ipc_open_socket(socket_path); | ||
60 | free(socket_path); | ||
61 | |||
62 | close(socketfd); | ||
63 | free(out); | ||
64 | return 0; | ||
12 | } | 65 | } |