Merge font.c into xcb.c
This commit is contained in:
parent
bb83dd6727
commit
f45e706c48
1
Makefile
1
Makefile
|
@ -5,6 +5,7 @@ INSTALL=install
|
|||
CFLAGS += -std=c99
|
||||
CFLAGS += -pipe
|
||||
CFLAGS += -Wall
|
||||
CFLAGS += -Wunused
|
||||
CFLAGS += -Iinclude
|
||||
CFLAGS += -I/usr/local/include
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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);
|
||||
|
|
60
src/font.c
60
src/font.c
|
@ -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;
|
||||
}
|
|
@ -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"
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "font.h"
|
||||
#include "i3.h"
|
||||
#include "xcb.h"
|
||||
#include "table.h"
|
||||
|
|
|
@ -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"
|
||||
|
|
41
src/xcb.c
41
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).
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue