12 /* TODO: This is just here to be somewhere. Move it somewhere else. */
13 void check_error(xcb_connection_t *connection, xcb_void_cookie_t cookie, char *errMessage) {
14 xcb_generic_error_t *error = xcb_request_check (connection, cookie);
16 fprintf(stderr, "ERROR: %s : %d\n", errMessage , error->error_code);
17 xcb_disconnect(connection);
23 i3Font *load_font(xcb_connection_t *c, const char *pattern) {
24 /* TODO: this function should be caching */
25 i3Font *new = malloc(sizeof(i3Font));
27 xcb_list_fonts_with_info_cookie_t cookie = xcb_list_fonts_with_info(c, 1, strlen(pattern), pattern);
28 xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(c, cookie, NULL);
30 printf("Could not load font\n");
34 /* Oh my, this is so ugly :-(. Why can’t they just return a null-terminated
35 * string? That’s what abstraction layers are for. */
36 char buffer[xcb_list_fonts_with_info_name_length(reply)+1];
37 memset(buffer, 0, sizeof(buffer));
38 memcpy(buffer, xcb_list_fonts_with_info_name(reply), sizeof(buffer)-1);
39 new->name = strdup(buffer);
40 new->pattern = strdup(pattern);
41 new->height = reply->font_ascent + reply->font_descent;
43 /* Actually load the font */
44 new->id = xcb_generate_id(c);
45 xcb_void_cookie_t font_cookie = xcb_open_font_checked(c, new->id, strlen(pattern), pattern);
46 check_error(c, font_cookie, "Could not open font");