13 i3Font *load_font(xcb_connection_t *c, const char *pattern) {
14 /* TODO: this function should be caching */
15 i3Font *new = malloc(sizeof(i3Font));
17 xcb_list_fonts_with_info_cookie_t cookie = xcb_list_fonts_with_info(c, 1, strlen(pattern), pattern);
18 xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(c, cookie, NULL);
20 printf("Could not load font\n");
24 /* Oh my, this is so ugly :-(. Why can’t they just return a null-terminated
25 * string? That’s what abstraction layers are for. */
26 char buffer[xcb_list_fonts_with_info_name_length(reply)+1];
27 memset(buffer, 0, sizeof(buffer));
28 memcpy(buffer, xcb_list_fonts_with_info_name(reply), sizeof(buffer)-1);
29 new->name = strdup(buffer);
30 new->pattern = strdup(pattern);
31 new->height = reply->font_ascent + reply->font_descent;
33 /* Actually load the font */
34 new->id = xcb_generate_id(c);
35 xcb_void_cookie_t font_cookie = xcb_open_font_checked(c, new->id, strlen(pattern), pattern);
36 check_error(c, font_cookie, "Could not open font");