aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/main.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-12-15 22:08:09 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-12-15 22:08:09 -0500
commitf80e7364b1c4e4a449ddf3494783d99429376fb2 (patch)
tree043e048864d2f93719031f0f270bfe161dc15e9c /swaybar/main.c
parentMerge pull request #335 from mikkeloscar/bar-font (diff)
downloadsway-f80e7364b1c4e4a449ddf3494783d99429376fb2.tar.gz
sway-f80e7364b1c4e4a449ddf3494783d99429376fb2.tar.zst
sway-f80e7364b1c4e4a449ddf3494783d99429376fb2.zip
Parse command line in swaybar
Diffstat (limited to 'swaybar/main.c')
-rw-r--r--swaybar/main.c45
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
237int main(int argc, char **argv) { 238int 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);