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);
22 void handle_xcb_event(xcb_generic_event_t *event) {
23 switch (event->response_type & ~0x80) {
30 int get_string_width(char *string) {
31 xcb_query_text_extents_cookie_t cookie;
32 xcb_query_text_extents_reply_t *reply;
33 xcb_generic_error_t *error;
36 cookie = xcb_query_text_extents(xcb_connection, xcb_font, strlen(string), (xcb_char2b_t *)string);
37 if ((reply= xcb_query_text_extents_reply(xcb_connection, cookie, &error)) == NULL) {
38 printf("ERROR: Could not get text extents!");
42 width = reply->overall_width;
48 /* FIXME: xcb_connect leaks Memory */
49 xcb_connection = xcb_connect(NULL, NULL);
50 if (xcb_connection_has_error(xcb_connection)) {
51 printf("Cannot open display\n");
54 printf("Connected to xcb\n");
56 /* We have to request the atoms we need */
57 #define ATOM_DO(name) atom_cookies[name] = xcb_intern_atom(xcb_connection, 0, strlen(#name), #name);
58 #include "xcb_atoms.def"
60 xcb_screens = xcb_setup_roots_iterator(xcb_get_setup(xcb_connection)).data;
61 xcb_root = xcb_screens->root;
63 xcb_font = xcb_generate_id(xcb_connection);
64 char *fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1";
65 xcb_open_font(xcb_connection,
70 xcb_list_fonts_with_info_cookie_t cookie;
71 cookie = xcb_list_fonts_with_info(xcb_connection,
75 xcb_list_fonts_with_info_reply_t *reply;
76 reply = xcb_list_fonts_with_info_reply(xcb_connection,
79 font_height = reply->font_ascent + reply->font_descent;
80 printf("Calculated Font-height: %d\n", font_height);
83 /* FIXME: Maybe we can push that further backwards */
88 xcb_disconnect(xcb_connection);
92 xcb_intern_atom_reply_t* reply;
93 #define ATOM_DO(name) reply = xcb_intern_atom_reply(xcb_connection, atom_cookies[name], NULL); \
94 atoms[name] = reply->atom; \
97 #include "xcb_atoms.def"
98 printf("Got Atoms\n");
101 void destroy_windows() {
103 if (outputs == NULL) {
106 SLIST_FOREACH(walk, outputs, slist) {
107 if (walk->bar == XCB_NONE) {
110 xcb_destroy_window(xcb_connection, walk->bar);
111 walk->bar = XCB_NONE;
115 void create_windows() {
120 SLIST_FOREACH(walk, outputs, slist) {
124 printf("Creating Window for output %s\n", walk->name);
126 walk->bar = xcb_generate_id(xcb_connection);
127 mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
128 values[0] = xcb_screens->black_pixel;
129 values[1] = XCB_EVENT_MASK_EXPOSURE;
130 xcb_create_window(xcb_connection,
131 xcb_screens->root_depth,
134 walk->rect.x, walk->rect.y,
135 walk->rect.w, font_height + 6,
137 XCB_WINDOW_CLASS_INPUT_OUTPUT,
138 xcb_screens->root_visual,
142 xcb_change_property(xcb_connection,
143 XCB_PROP_MODE_REPLACE,
145 atoms[_NET_WM_WINDOW_TYPE],
149 (unsigned char*) &atoms[_NET_WM_WINDOW_TYPE_DOCK]);
151 walk->bargc = xcb_generate_id(xcb_connection);
153 values[0] = xcb_font;
154 xcb_create_gc(xcb_connection,
160 xcb_map_window(xcb_connection, walk->bar);
162 xcb_flush(xcb_connection);
165 void draw_buttons() {
166 printf("Drawing Buttons...\n");
168 i3_output *outputs_walk;
169 SLIST_FOREACH(outputs_walk, outputs, slist) {
170 if (!outputs_walk->active) {
171 printf("Output %s inactive, skipping...\n", outputs_walk->name);
174 if (outputs_walk->bar == XCB_NONE) {
177 uint32_t color = get_colorpixel("000000");
178 xcb_change_gc(xcb_connection,
182 xcb_rectangle_t rect = { 0, 0, outputs_walk->rect.w, font_height + 6 };
183 xcb_poly_fill_rectangle(xcb_connection,
189 TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) {
190 printf("Drawing Button for WS %s...\n", ws_walk->name);
191 uint32_t color = get_colorpixel("240000");
192 if (ws_walk->visible) {
193 color = get_colorpixel("480000");
195 if (ws_walk->urgent) {
196 printf("WS %s is urgent!\n", ws_walk->name);
197 color = get_colorpixel("002400");
199 xcb_change_gc(xcb_connection,
203 xcb_change_gc(xcb_connection,
207 xcb_rectangle_t rect = { i + 1, 1, ws_walk->name_width + 8, font_height + 4 };
208 xcb_poly_fill_rectangle(xcb_connection,
213 color = get_colorpixel("FFFFFF");
214 xcb_change_gc(xcb_connection,
218 xcb_image_text_8(xcb_connection,
219 strlen(ws_walk->name),
222 i + 5, font_height + 1,
224 i += 10 + ws_walk->name_width;
228 xcb_flush(xcb_connection);