4 * i3 - an improved dynamic tiling window manager
6 * (c) 2009 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
12 * Handles font loading
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");