]> git.sur5r.net Git - i3/i3/blob - i3bar/src/main.c
Change the indention-style
[i3/i3] / i3bar / src / main.c
1 #include <stdio.h>
2 #include <i3/ipc.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <stdlib.h>
6 #include <ev.h>
7 #include <xcb/xcb.h>
8
9 #include "ipc.h"
10 #include "outputs.h"
11 #include "workspaces.h"
12 #include "common.h"
13 #include "xcb.h"
14
15 void ev_prepare_cb(struct ev_loop *loop, ev_prepare *w, int revents) {
16     xcb_flush(xcb_connection);
17 }
18
19 void ev_check_cb(struct ev_loop *loop, ev_check *w, int revents) {
20     xcb_generic_event_t *event;
21     if ((event = xcb_poll_for_event(xcb_connection)) != NULL) {
22         handle_xcb_event(event);
23     }
24     free(event);
25 }
26
27 void xcb_io_cb(struct ev_loop *loop, ev_io *w, int revents) {
28 }
29
30 int main(int argc, char **argv) {
31     main_loop = ev_default_loop(0);
32
33     init_xcb();
34     init_connection("/home/mero/.i3/ipc.sock");
35
36     subscribe_events();
37
38     ev_io *xcb_io = malloc(sizeof(ev_io));
39     ev_prepare *ev_prep = malloc(sizeof(ev_prepare));
40     ev_check *ev_chk = malloc(sizeof(ev_check));
41
42     ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ);
43     ev_prepare_init(ev_prep, &ev_prepare_cb);
44     ev_check_init(ev_chk, &ev_check_cb);
45
46     ev_io_start(main_loop, xcb_io);
47     ev_prepare_start(main_loop, ev_prep);
48     ev_check_start(main_loop, ev_chk);
49
50     i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
51     i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
52
53     ev_loop(main_loop, 0);
54
55     ev_prepare_stop(main_loop, ev_prep);
56     ev_check_stop(main_loop, ev_chk);
57     FREE(ev_prep);
58     FREE(ev_chk);
59
60     ev_default_destroy();
61     clean_xcb();
62
63     free_workspaces();
64     FREE_SLIST(outputs, i3_output);
65
66     return 0;
67 }