13 char *i3_default_sock_path = "~/.i3/ipc.sock";
15 char *expand_path(char *path) {
16 static glob_t globbuf;
17 if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0) {
18 printf("glob() failed");
21 char *result = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
23 printf("malloc() failed");
30 int main(int argc, char **argv) {
33 char *socket_path = NULL;
35 char *fontname = NULL;
37 static struct option long_opt[] = {
38 { "socket", required_argument, 0, 's' },
39 { "command", required_argument, 0, 'c' },
40 { "font", required_argument, 0, 'f' },
41 { "help", no_argument, 0, 'h' },
42 { "version", no_argument, 0, 'v' },
46 while ((opt = getopt_long(argc, argv, "s:c:f:hv", long_opt, &option_index)) != -1) {
49 socket_path = expand_path(optarg);
52 command = strdup(optarg);
55 fontname = strdup(optarg);
58 printf("i3bar version " I3BAR_VERSION " © 2010 Axel Wagner and contributors\n");
61 printf("Usage: %s [-s socket_path] [-c command] [-f font] [-h]\n", argv[0]);
62 printf("-s <socket_path>: Connect to i3 via <socket_path>\n");
63 printf("-c <command>: Execute <command> to get sdtin\n");
64 printf("-f <font>: Use X-Core-Font <font> for display\n");
65 printf("-h: Display this help-message and exit\n");
71 if (fontname == NULL) {
72 fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1";
75 if (socket_path == NULL) {
76 printf("No Socket Path Specified, default to %s\n", i3_default_sock_path);
77 socket_path = expand_path(i3_default_sock_path);
80 main_loop = ev_default_loop(0);
84 init_connection(socket_path);
90 i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
91 i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
95 ev_loop(main_loop, 0);
102 ev_default_destroy();
105 FREE_SLIST(outputs, i3_output);