]> git.sur5r.net Git - i3/i3/blob - i3bar/src/main.c
Handling Exposure-Events
[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                 switch (event->response_type & ~0x80) {
23                         case XCB_EXPOSE:
24                                 draw_buttons();
25                 }
26                 free(event);
27         }
28 }
29
30 void xcb_io_cb(struct ev_loop *loop, ev_io *w, int revents) {
31 }
32
33 int main(int argc, char **argv) {
34         main_loop = ev_default_loop(0);
35
36         init_xcb();
37         init_connection("/home/mero/.i3/ipc.sock");
38
39         subscribe_events();
40
41         ev_io *xcb_io = malloc(sizeof(ev_io));
42         ev_prepare *ev_prep = malloc(sizeof(ev_prepare));
43         ev_check *ev_chk = malloc(sizeof(ev_check));
44
45         ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ);
46         ev_prepare_init(ev_prep, &ev_prepare_cb);
47         ev_check_init(ev_chk, &ev_check_cb);
48
49         ev_io_start(main_loop, xcb_io);
50         ev_prepare_start(main_loop, ev_prep);
51         ev_check_start(main_loop, ev_chk);
52
53         i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
54         i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
55
56         ev_loop(main_loop, 0);
57
58         ev_prepare_stop(main_loop, ev_prep);
59         ev_check_stop(main_loop, ev_chk);
60         FREE(ev_prep);
61         FREE(ev_chk);
62
63         ev_default_destroy();
64         clean_xcb();
65         free_outputs();
66         free_workspaces();
67
68         return 0;       
69 }