Merge font.c into xcb.c

This commit is contained in:
Michael Stapelberg 2009-03-04 14:52:04 +01:00
parent bb83dd6727
commit f45e706c48
9 changed files with 45 additions and 84 deletions

View File

@ -5,6 +5,7 @@ INSTALL=install
CFLAGS += -std=c99
CFLAGS += -pipe
CFLAGS += -Wall
CFLAGS += -Wunused
CFLAGS += -Iinclude
CFLAGS += -I/usr/local/include

View File

@ -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 <xcb/xcb.h>
#include "data.h"
#ifndef _FONT_H
#define _FONT_H
i3Font *load_font(xcb_connection_t *c, const char *pattern);
#endif

View File

@ -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);

View File

@ -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 <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <xcb/xcb.h>
#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;
}

View File

@ -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"

View File

@ -17,7 +17,6 @@
#include <assert.h>
#include "config.h"
#include "font.h"
#include "i3.h"
#include "xcb.h"
#include "table.h"

View File

@ -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"

View File

@ -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).
*

View File

@ -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