From f45e706c48c8dd3c629841cf195605d219451b3f Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 4 Mar 2009 14:52:04 +0100 Subject: [PATCH] Merge font.c into xcb.c --- Makefile | 1 + include/font.h | 20 ----------------- include/xcb.h | 3 +++ src/font.c | 60 -------------------------------------------------- src/handlers.c | 1 - src/layout.c | 1 - src/mainx.c | 1 - src/xcb.c | 41 ++++++++++++++++++++++++++++++++++ src/xinerama.c | 1 - 9 files changed, 45 insertions(+), 84 deletions(-) delete mode 100644 include/font.h delete mode 100644 src/font.c diff --git a/Makefile b/Makefile index 1993a481..eb806d96 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ INSTALL=install CFLAGS += -std=c99 CFLAGS += -pipe CFLAGS += -Wall +CFLAGS += -Wunused CFLAGS += -Iinclude CFLAGS += -I/usr/local/include diff --git a/include/font.h b/include/font.h deleted file mode 100644 index 3e9d0a1a..00000000 --- a/include/font.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * vim:ts=8:expandtab - * - * i3 - an improved dynamic tiling window manager - * - * (c) 2009 Michael Stapelberg and contributors - * - * See file LICENSE for license information. - * - */ -#include - -#include "data.h" - -#ifndef _FONT_H -#define _FONT_H - -i3Font *load_font(xcb_connection_t *c, const char *pattern); - -#endif diff --git a/include/xcb.h b/include/xcb.h index cf2863ae..1e8a9321 100644 --- a/include/xcb.h +++ b/include/xcb.h @@ -11,6 +11,8 @@ #ifndef _XCB_H #define _XCB_H +#include "data.h" + #define _NET_WM_STATE_REMOVE 0 #define _NET_WM_STATE_ADD 1 #define _NET_WM_STATE_TOGGLE 2 @@ -27,6 +29,7 @@ enum { _NET_SUPPORTED = 0, UTF8_STRING }; +i3Font *load_font(xcb_connection_t *connection, const char *pattern); uint32_t get_colorpixel(xcb_connection_t *conn, Client *client, xcb_window_t window, char *hex); xcb_window_t create_window(xcb_connection_t *conn, Rect r, uint16_t window_class, uint32_t mask, uint32_t *values); void xcb_change_gc_single(xcb_connection_t *conn, xcb_gcontext_t gc, uint32_t mask, uint32_t value); diff --git a/src/font.c b/src/font.c deleted file mode 100644 index 624c20ac..00000000 --- a/src/font.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * vim:ts=8:expandtab - * - * i3 - an improved dynamic tiling window manager - * - * © 2009 Michael Stapelberg and contributors - * - * See file LICENSE for license information. - * - * font.c: Handles font loading (with caching, with height information) - * - */ -#include -#include -#include -#include - -#include "data.h" -#include "util.h" - -TAILQ_HEAD(cached_fonts_head, Font) cached_fonts = TAILQ_HEAD_INITIALIZER(cached_fonts); - -/* - * 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 *connection, 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(connection); - font_cookie = xcb_open_font_checked(connection, new->id, strlen(pattern), pattern); - info_cookie = xcb_list_fonts_with_info(connection, 1, strlen(pattern), pattern); - - check_error(connection, 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(connection, 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; -} diff --git a/src/handlers.c b/src/handlers.c index 2c1861be..1c1d9a9a 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -23,7 +23,6 @@ #include "layout.h" #include "commands.h" #include "data.h" -#include "font.h" #include "xcb.h" #include "util.h" #include "xinerama.h" diff --git a/src/layout.c b/src/layout.c index c122f313..6fd767e7 100644 --- a/src/layout.c +++ b/src/layout.c @@ -17,7 +17,6 @@ #include #include "config.h" -#include "font.h" #include "i3.h" #include "xcb.h" #include "table.h" diff --git a/src/mainx.c b/src/mainx.c index 4dbe7794..4e98ab55 100644 --- a/src/mainx.c +++ b/src/mainx.c @@ -35,7 +35,6 @@ #include "config.h" #include "queue.h" #include "table.h" -#include "font.h" #include "layout.h" #include "debug.h" #include "handlers.h" diff --git a/src/xcb.c b/src/xcb.c index 2f60ba70..bcef6086 100644 --- a/src/xcb.c +++ b/src/xcb.c @@ -19,6 +19,47 @@ #include "util.h" +TAILQ_HEAD(cached_fonts_head, Font) cached_fonts = TAILQ_HEAD_INITIALIZER(cached_fonts); + +/* + * 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 *connection, 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(connection); + font_cookie = xcb_open_font_checked(connection, new->id, strlen(pattern), pattern); + info_cookie = xcb_list_fonts_with_info(connection, 1, strlen(pattern), pattern); + + check_error(connection, 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(connection, 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). * diff --git a/src/xinerama.c b/src/xinerama.c index 1d16eb9b..82392692 100644 --- a/src/xinerama.c +++ b/src/xinerama.c @@ -24,7 +24,6 @@ #include "xinerama.h" #include "layout.h" #include "xcb.h" -#include "font.h" #include "config.h" /* This TAILQ of i3Screens stores the virtual screens, used for handling overlapping screens -- 2.39.5