8 #include "workspaces.h"
10 xcb_intern_atom_cookie_t atom_cookies[NUM_ATOMS];
12 uint32_t get_colorpixel(const char *s) {
13 char strings[3][3] = { { s[0], s[1], '\0'} ,
15 { s[4], s[5], '\0'} };
16 uint8_t r = strtol(strings[0], NULL, 16);
17 uint8_t g = strtol(strings[1], NULL, 16);
18 uint8_t b = strtol(strings[2], NULL, 16);
19 return (r << 16 | g << 8 | b);
23 /* FIXME: xcb_connect leaks Memory */
24 xcb_connection = xcb_connect(NULL, NULL);
25 if (xcb_connection_has_error(xcb_connection)) {
26 printf("Cannot open display\n");
29 printf("Connected to xcb\n");
31 /* We have to request the atoms we need */
32 #define ATOM_DO(name) atom_cookies[name] = xcb_intern_atom(xcb_connection, 0, strlen(#name), #name);
33 #include "xcb_atoms.def"
35 xcb_screens = xcb_setup_roots_iterator(xcb_get_setup(xcb_connection)).data;
36 xcb_root = xcb_screens->root;
38 /* FIXME: Maybe we can push that further backwards */
43 xcb_disconnect(xcb_connection);
47 xcb_intern_atom_reply_t* reply;
48 #define ATOM_DO(name) reply = xcb_intern_atom_reply(xcb_connection, atom_cookies[name], NULL); \
49 atoms[name] = reply->atom; \
52 #include "xcb_atoms.def"
53 printf("Got Atoms\n");
56 void destroy_windows() {
57 i3_output *walk = outputs;
59 if (walk->bar == XCB_NONE) {
62 xcb_destroy_window(xcb_connection, walk->bar);
67 void create_windows() {
71 i3_output* walk = outputs;
72 while (walk != NULL) {
77 printf("Creating Window for output %s\n", walk->name);
79 walk->bar = xcb_generate_id(xcb_connection);
80 mask = XCB_CW_BACK_PIXEL;
81 values[0] = xcb_screens->black_pixel;
82 xcb_create_window(xcb_connection,
83 xcb_screens->root_depth,
86 walk->rect.x, walk->rect.y,
89 XCB_WINDOW_CLASS_INPUT_OUTPUT,
90 xcb_screens->root_visual,
94 xcb_change_property(xcb_connection,
95 XCB_PROP_MODE_REPLACE,
97 atoms[_NET_WM_WINDOW_TYPE],
101 (unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]);
103 walk->bargc = xcb_generate_id(xcb_connection);
104 xcb_create_gc(xcb_connection,
110 xcb_map_window(xcb_connection, walk->bar);
113 xcb_flush(xcb_connection);
116 void draw_buttons() {
117 printf("Drawing Buttons...\n");
118 i3_output *outputs_walk = outputs;
120 while (outputs_walk != NULL) {
121 if (!outputs_walk->active) {
122 printf("Output %s inactive, skipping...\n", outputs_walk->name);
123 outputs_walk = outputs_walk->next;
126 if (outputs_walk->bar == XCB_NONE) {
129 uint32_t color = get_colorpixel("000000");
130 xcb_change_gc(xcb_connection,
134 xcb_rectangle_t rect = { 0, 0, outputs_walk->rect.w, 20 };
135 xcb_poly_fill_rectangle(xcb_connection,
140 i3_ws *ws_walk = workspaces;
141 while (ws_walk != NULL) {
142 if (ws_walk->output != outputs_walk) {
143 printf("WS %s on wrong output, skipping...\n", ws_walk->name);
144 ws_walk = ws_walk->next;
147 printf("Drawing Button for WS %s...\n", ws_walk->name);
148 uint32_t color = get_colorpixel("240000");
149 if (ws_walk->visible) {
150 color = get_colorpixel("480000");
152 if (ws_walk->urgent) {
153 color = get_colorpixel("002400");
155 xcb_change_gc(xcb_connection,
159 xcb_change_gc(xcb_connection,
163 xcb_rectangle_t rect = { i + 1, 1, 18, 18 };
164 xcb_poly_fill_rectangle(xcb_connection,
170 ws_walk = ws_walk->next;
172 outputs_walk = outputs_walk->next;
175 xcb_flush(xcb_connection);