diff options
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/main.c | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/swaybar/main.c b/swaybar/main.c index 21e3100b..79635de1 100644 --- a/swaybar/main.c +++ b/swaybar/main.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <sys/un.h> | 8 | #include <sys/un.h> |
9 | #include <sys/socket.h> | 9 | #include <sys/socket.h> |
10 | #include <sys/ioctl.h> | 10 | #include <sys/ioctl.h> |
11 | #include <getopt.h> | ||
11 | #include "ipc-client.h" | 12 | #include "ipc-client.h" |
12 | #include "readline.h" | 13 | #include "readline.h" |
13 | #include "client/registry.h" | 14 | #include "client/registry.h" |
@@ -236,6 +237,44 @@ void render() { | |||
236 | 237 | ||
237 | int main(int argc, char **argv) { | 238 | int main(int argc, char **argv) { |
238 | init_log(L_INFO); | 239 | init_log(L_INFO); |
240 | |||
241 | char *socket_path = NULL; | ||
242 | char *bar_id = NULL; | ||
243 | |||
244 | static struct option long_options[] = { | ||
245 | {"version", no_argument, NULL, 'v'}, | ||
246 | {"socket", required_argument, NULL, 's'}, | ||
247 | {"bar_id", required_argument, NULL, 'b'}, | ||
248 | {0, 0, 0, 0} | ||
249 | }; | ||
250 | |||
251 | int c; | ||
252 | while (1) { | ||
253 | int option_index = 0; | ||
254 | c = getopt_long(argc, argv, "vs:b:", long_options, &option_index); | ||
255 | if (c == -1) { | ||
256 | break; | ||
257 | } | ||
258 | switch (c) { | ||
259 | case 's': // Socket | ||
260 | socket_path = strdup(optarg); | ||
261 | break; | ||
262 | case 'b': // Type | ||
263 | bar_id = strdup(optarg); | ||
264 | break; | ||
265 | case 'v': | ||
266 | #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE | ||
267 | fprintf(stdout, "sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH); | ||
268 | #else | ||
269 | fprintf(stdout, "version not detected\n"); | ||
270 | #endif | ||
271 | exit(EXIT_SUCCESS); | ||
272 | break; | ||
273 | default: | ||
274 | exit(EXIT_FAILURE); | ||
275 | } | ||
276 | } | ||
277 | |||
239 | registry = registry_poll(); | 278 | registry = registry_poll(); |
240 | 279 | ||
241 | if (!registry->desktop_shell) { | 280 | if (!registry->desktop_shell) { |
@@ -261,9 +300,11 @@ int main(int argc, char **argv) { | |||
261 | line = malloc(1024); | 300 | line = malloc(1024); |
262 | line[0] = '\0'; | 301 | line[0] = '\0'; |
263 | 302 | ||
264 | char *socket_path = get_socketpath(); | ||
265 | if (!socket_path) { | 303 | if (!socket_path) { |
266 | sway_abort("Unable to retrieve socket path"); | 304 | char *socket_path = get_socketpath(); |
305 | if (!socket_path) { | ||
306 | sway_abort("Unable to retrieve socket path"); | ||
307 | } | ||
267 | } | 308 | } |
268 | socketfd = ipc_open_socket(socket_path); | 309 | socketfd = ipc_open_socket(socket_path); |
269 | bar_ipc_init(desired_output); | 310 | bar_ipc_init(desired_output); |