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 xcb_font_t button_font = xcb_generate_id(xcb_connection);
121 char *fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1";
122 xcb_open_font(xcb_connection,
126 xcb_change_gc(xcb_connection,
130 while (outputs_walk != NULL) {
131 if (!outputs_walk->active) {
132 printf("Output %s inactive, skipping...\n", outputs_walk->name);
133 outputs_walk = outputs_walk->next;
136 if (outputs_walk->bar == XCB_NONE) {
139 uint32_t color = get_colorpixel("000000");
140 xcb_change_gc(xcb_connection,
144 xcb_rectangle_t rect = { 0, 0, outputs_walk->rect.w, 20 };
145 xcb_poly_fill_rectangle(xcb_connection,
150 i3_ws *ws_walk = workspaces;
151 while (ws_walk != NULL) {
152 if (ws_walk->output != outputs_walk) {
153 printf("WS %s on wrong output, skipping...\n", ws_walk->name);
154 ws_walk = ws_walk->next;
157 printf("Drawing Button for WS %s...\n", ws_walk->name);
158 uint32_t color = get_colorpixel("240000");
159 if (ws_walk->visible) {
160 color = get_colorpixel("480000");
162 if (ws_walk->urgent) {
163 color = get_colorpixel("002400");
165 xcb_change_gc(xcb_connection,
169 xcb_change_gc(xcb_connection,
173 xcb_rectangle_t rect = { i + 1, 1, 18, 18 };
174 xcb_poly_fill_rectangle(xcb_connection,
179 color = get_colorpixel("FFFFFF");
180 xcb_change_gc(xcb_connection,
184 xcb_image_text_8(xcb_connection,
185 strlen(ws_walk->name),
191 ws_walk = ws_walk->next;
193 outputs_walk = outputs_walk->next;
196 xcb_flush(xcb_connection);