2010-08-07 12:05:16 -04:00
|
|
|
/*
|
|
|
|
* i3bar - an xcb-based status- and ws-bar for i3
|
|
|
|
*
|
|
|
|
* © 2010 Axel Wagner and contributors
|
|
|
|
*
|
|
|
|
* See file LICNSE for license information
|
|
|
|
*
|
|
|
|
*/
|
2010-07-22 22:43:43 -04:00
|
|
|
#include <stdio.h>
|
2010-07-22 23:04:13 -04:00
|
|
|
#include <i3/ipc.h>
|
2010-07-22 22:43:43 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2010-07-26 17:51:51 -04:00
|
|
|
#include <stdlib.h>
|
2010-08-03 21:34:18 -04:00
|
|
|
#include <errno.h>
|
2010-07-22 22:43:43 -04:00
|
|
|
#include <ev.h>
|
2010-08-05 21:32:05 -04:00
|
|
|
#include <getopt.h>
|
2010-08-05 22:11:44 -04:00
|
|
|
#include <glob.h>
|
2010-07-22 22:43:43 -04:00
|
|
|
|
2010-07-21 19:15:18 -04:00
|
|
|
#include "common.h"
|
2010-08-03 21:34:18 -04:00
|
|
|
|
2010-08-05 22:11:44 -04:00
|
|
|
char *i3_default_sock_path = "~/.i3/ipc.sock";
|
|
|
|
|
|
|
|
char *expand_path(char *path) {
|
|
|
|
static glob_t globbuf;
|
|
|
|
if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0) {
|
|
|
|
printf("glob() failed");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
char *result = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
|
|
|
|
if (result == NULL) {
|
|
|
|
printf("malloc() failed");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
globfree(&globbuf);
|
|
|
|
return result;
|
|
|
|
}
|
2010-08-05 21:32:05 -04:00
|
|
|
|
2010-08-25 18:01:24 -04:00
|
|
|
void print_usage(char *elf_name) {
|
|
|
|
printf("Usage: %s [-s sock_path] [-c command] [-m] [-f font] [-h]\n", elf_name);
|
|
|
|
printf("-s <sock_path>\tConnect to i3 via <sock_path>\n");
|
|
|
|
printf("-c <command>\tExecute <command> to get stdin\n");
|
|
|
|
printf("-m\t\tHide the bars, when mod4 is not pressed.\n");
|
|
|
|
printf("\t\tIf -c is specified, the childprocess is sent a SIGSTOP on hiding,\n");
|
|
|
|
printf("\t\tand a SIGCONT on unhiding of the bars\n");
|
|
|
|
printf("-f <font>\tUse X-Core-Font <font> for display\n");
|
|
|
|
printf("-h\t\tDisplay this help-message and exit\n");
|
|
|
|
}
|
|
|
|
|
2010-07-21 19:15:18 -04:00
|
|
|
int main(int argc, char **argv) {
|
2010-08-05 21:32:05 -04:00
|
|
|
int opt;
|
|
|
|
int option_index = 0;
|
|
|
|
char *socket_path = NULL;
|
|
|
|
char *command = NULL;
|
|
|
|
char *fontname = NULL;
|
|
|
|
|
|
|
|
static struct option long_opt[] = {
|
|
|
|
{ "socket", required_argument, 0, 's' },
|
|
|
|
{ "command", required_argument, 0, 'c' },
|
|
|
|
{ "font", required_argument, 0, 'f' },
|
|
|
|
{ "help", no_argument, 0, 'h' },
|
2010-08-06 21:50:22 -04:00
|
|
|
{ "version", no_argument, 0, 'v' },
|
2010-08-05 21:32:05 -04:00
|
|
|
{ NULL, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2010-08-06 21:50:22 -04:00
|
|
|
while ((opt = getopt_long(argc, argv, "s:c:f:hv", long_opt, &option_index)) != -1) {
|
2010-08-05 21:32:05 -04:00
|
|
|
switch (opt) {
|
|
|
|
case 's':
|
2010-08-05 22:11:44 -04:00
|
|
|
socket_path = expand_path(optarg);
|
2010-08-05 21:32:05 -04:00
|
|
|
break;
|
|
|
|
case 'c':
|
2010-08-05 22:11:44 -04:00
|
|
|
command = strdup(optarg);
|
2010-08-05 21:32:05 -04:00
|
|
|
break;
|
|
|
|
case 'f':
|
2010-08-05 22:11:44 -04:00
|
|
|
fontname = strdup(optarg);
|
2010-08-05 21:32:05 -04:00
|
|
|
break;
|
2010-08-06 21:50:22 -04:00
|
|
|
case 'v':
|
|
|
|
printf("i3bar version " I3BAR_VERSION " © 2010 Axel Wagner and contributors\n");
|
|
|
|
exit(EXIT_SUCCESS);
|
2010-08-25 18:01:24 -04:00
|
|
|
break;
|
2010-08-05 21:32:05 -04:00
|
|
|
default:
|
2010-08-25 18:01:24 -04:00
|
|
|
print_usage(argv[0]);
|
2010-08-05 21:32:05 -04:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fontname == NULL) {
|
|
|
|
fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (socket_path == NULL) {
|
|
|
|
printf("No Socket Path Specified, default to %s\n", i3_default_sock_path);
|
2010-08-05 22:11:44 -04:00
|
|
|
socket_path = expand_path(i3_default_sock_path);
|
2010-08-05 21:32:05 -04:00
|
|
|
}
|
|
|
|
|
2010-08-03 15:20:11 -04:00
|
|
|
main_loop = ev_default_loop(0);
|
2010-07-21 19:15:18 -04:00
|
|
|
|
2010-08-05 21:32:05 -04:00
|
|
|
init_xcb(fontname);
|
|
|
|
init_outputs();
|
|
|
|
init_connection(socket_path);
|
2010-07-21 19:15:18 -04:00
|
|
|
|
2010-08-05 22:11:44 -04:00
|
|
|
FREE(socket_path);
|
|
|
|
|
2010-08-03 15:20:11 -04:00
|
|
|
subscribe_events();
|
2010-07-21 19:15:18 -04:00
|
|
|
|
2010-08-03 15:20:11 -04:00
|
|
|
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
|
|
|
|
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
|
2010-07-22 23:04:13 -04:00
|
|
|
|
2010-08-05 21:32:05 -04:00
|
|
|
start_child(command);
|
2010-08-03 21:34:18 -04:00
|
|
|
|
2010-08-03 15:20:11 -04:00
|
|
|
ev_loop(main_loop, 0);
|
2010-07-21 19:15:18 -04:00
|
|
|
|
2010-08-04 23:09:59 -04:00
|
|
|
kill_child();
|
2010-08-03 22:07:16 -04:00
|
|
|
|
|
|
|
FREE(statusline);
|
2010-07-26 17:51:51 -04:00
|
|
|
|
2010-08-03 15:20:11 -04:00
|
|
|
clean_xcb();
|
2010-08-04 23:09:59 -04:00
|
|
|
ev_default_destroy();
|
2010-07-29 21:11:54 -04:00
|
|
|
|
2010-08-03 15:20:11 -04:00
|
|
|
free_workspaces();
|
|
|
|
FREE_SLIST(outputs, i3_output);
|
2010-07-21 19:15:18 -04:00
|
|
|
|
2010-08-03 15:20:11 -04:00
|
|
|
return 0;
|
2010-07-21 19:15:18 -04:00
|
|
|
}
|