-/*
- * Loads a font for usage, getting its height. This function is used very often, so it
- * maintains a cache.
- *
- */
-i3Font *load_font(xcb_connection_t *conn, const char *pattern) {
- /* Check if we got the font cached */
- i3Font *font;
- TAILQ_FOREACH(font, &cached_fonts, fonts)
- if (strcmp(font->pattern, pattern) == 0)
- return font;
-
- i3Font *new = smalloc(sizeof(i3Font));
- xcb_void_cookie_t font_cookie;
- xcb_list_fonts_with_info_cookie_t info_cookie;
-
- /* Send all our requests first */
- new->id = xcb_generate_id(conn);
- font_cookie = xcb_open_font_checked(conn, new->id, strlen(pattern), pattern);
- info_cookie = xcb_list_fonts_with_info(conn, 1, strlen(pattern), pattern);
-
- check_error(conn, font_cookie, "Could not open font");
-
- /* Get information (height/name) for this font */
- xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(conn, info_cookie, NULL);
- exit_if_null(reply, "Could not load font \"%s\"\n", pattern);
-
- if (asprintf(&(new->name), "%.*s", xcb_list_fonts_with_info_name_length(reply),
- xcb_list_fonts_with_info_name(reply)) == -1)
- die("asprintf() failed\n");
- new->pattern = sstrdup(pattern);
- new->height = reply->font_ascent + reply->font_descent;
-
- /* Insert into cache */
- TAILQ_INSERT_TAIL(&cached_fonts, new, fonts);
-
- return new;
-}
-
-/*
- * Returns the colorpixel to use for the given hex color (think of HTML).
- *
- * The hex_color has to start with #, for example #FF00FF.
- *
- * NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
- * This has to be done by the caller.
- *
- */
-uint32_t get_colorpixel(xcb_connection_t *conn, char *hex) {
- char strgroups[3][3] = {{hex[1], hex[2], '\0'},
- {hex[3], hex[4], '\0'},
- {hex[5], hex[6], '\0'}};
- uint32_t rgb16[3] = {(strtol(strgroups[0], NULL, 16)),
- (strtol(strgroups[1], NULL, 16)),
- (strtol(strgroups[2], NULL, 16))};
-
- return (rgb16[0] << 16) + (rgb16[1] << 8) + rgb16[2];
-}
-