From f80e7364b1c4e4a449ddf3494783d99429376fb2 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 15 Dec 2015 22:08:09 -0500 Subject: [PATCH] Parse command line in swaybar --- swaybar/main.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/swaybar/main.c b/swaybar/main.c index 21e3100bf..79635de13 100644 --- a/swaybar/main.c +++ b/swaybar/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "ipc-client.h" #include "readline.h" #include "client/registry.h" @@ -236,6 +237,44 @@ void render() { int main(int argc, char **argv) { init_log(L_INFO); + + char *socket_path = NULL; + char *bar_id = NULL; + + static struct option long_options[] = { + {"version", no_argument, NULL, 'v'}, + {"socket", required_argument, NULL, 's'}, + {"bar_id", required_argument, NULL, 'b'}, + {0, 0, 0, 0} + }; + + int c; + while (1) { + int option_index = 0; + c = getopt_long(argc, argv, "vs:b:", long_options, &option_index); + if (c == -1) { + break; + } + switch (c) { + case 's': // Socket + socket_path = strdup(optarg); + break; + case 'b': // Type + bar_id = 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(EXIT_SUCCESS); + break; + default: + exit(EXIT_FAILURE); + } + } + registry = registry_poll(); if (!registry->desktop_shell) { @@ -261,9 +300,11 @@ int main(int argc, char **argv) { line = malloc(1024); line[0] = '\0'; - char *socket_path = get_socketpath(); if (!socket_path) { - sway_abort("Unable to retrieve socket path"); + char *socket_path = get_socketpath(); + if (!socket_path) { + sway_abort("Unable to retrieve socket path"); + } } socketfd = ipc_open_socket(socket_path); bar_ipc_init(desired_output);