Implement set_font_colors.

This paves the way for other font rendering backends. Fonts and
colors shouldn't be specified manually from now on.
This commit is contained in:
Fernando Tarlá Cardoso Lemos
2011-11-14 20:20:18 -02:00
committed by Michael Stapelberg
parent eafc7af606
commit 344c04af12
8 changed files with 63 additions and 68 deletions

View File

@ -47,11 +47,11 @@ static int sig_draw_window(xcb_window_t win, int width, int height, int font_hei
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &inner);
/* restore font color */
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
set_font_colors(pixmap_gc, get_colorpixel("#FFFFFF"), get_colorpixel("#000000"));
for (int i = 0; i < sizeof(crash_text) / sizeof(char*); i++) {
draw_text(crash_text[i], strlen(crash_text[i]), false,
pixmap, pixmap_gc, 8, 3 + (i - 1) * font_height);
draw_text(crash_text[i], strlen(crash_text[i]), false, pixmap, pixmap_gc,
8, 3 + (i - 1) * font_height, width - 16);
}
/* Copy the contents of the pixmap to the real window */
@ -165,9 +165,6 @@ void handle_signal(int sig, siginfo_t *info, void *data) {
xcb_create_pixmap(conn, root_depth, pixmap, win, width, height);
xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);
/* Create graphics context */
xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ config.font.id });
/* Grab the keyboard to get all input */
xcb_grab_keyboard(conn, false, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);

10
src/x.c
View File

@ -408,9 +408,7 @@ void x_draw_decoration(Con *con) {
xcb_poly_segment(conn, parent->pixmap, parent->pm_gc, 2, segments);
/* 6: draw the title */
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
uint32_t values[] = { p->color->text, p->color->background, config.font.id };
xcb_change_gc(conn, parent->pm_gc, mask, values);
set_font_colors(parent->pm_gc, p->color->text, p->color->background);
int text_offset_y = (con->deco_rect.height - config.font.height) / 2;
struct Window *win = con->window;
@ -419,7 +417,8 @@ void x_draw_decoration(Con *con) {
// TODO: use a good description instead of just "another container"
draw_text("another container", strlen("another container"), false,
parent->pixmap, parent->pm_gc,
con->deco_rect.x + 2, con->deco_rect.y + text_offset_y);
con->deco_rect.x + 2, con->deco_rect.y + text_offset_y,
con->deco_rect.width - 2);
goto copy_pixmaps;
}
@ -442,7 +441,8 @@ void x_draw_decoration(Con *con) {
draw_text(win->name_x, win->name_len, win->uses_net_wm_name,
parent->pixmap, parent->pm_gc,
con->deco_rect.x + 2 + indent_px, con->deco_rect.y + text_offset_y);
con->deco_rect.x + 2 + indent_px, con->deco_rect.y + text_offset_y,
con->deco_rect.width - 2 - indent_px);
copy_pixmaps:
xcb_copy_area(conn, con->pixmap, con->frame, con->pm_gc, 0, 0, 0, 0, con->rect.width, con->rect.height);