Make all programs use draw_text.
This commit is contained in:
parent
5c2088c87e
commit
eafc7af606
|
@ -112,9 +112,10 @@ static int handle_expose() {
|
||||||
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#000000") });
|
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#000000") });
|
||||||
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &border);
|
xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &border);
|
||||||
|
|
||||||
xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ font.id });
|
set_font(&font);
|
||||||
|
|
||||||
#define txt(x, row, text) xcb_image_text_8(conn, strlen(text), pixmap, pixmap_gc, x, (row * font.height) + 2, text)
|
#define txt(x, row, text) \
|
||||||
|
draw_text(text, strlen(text), false, pixmap, pixmap_gc, x, (row - 1) * font.height + 4)
|
||||||
|
|
||||||
if (current_step == STEP_WELCOME) {
|
if (current_step == STEP_WELCOME) {
|
||||||
/* restore font color */
|
/* restore font color */
|
||||||
|
@ -150,12 +151,14 @@ static int handle_expose() {
|
||||||
else txt(31, 4, "<Win>");
|
else txt(31, 4, "<Win>");
|
||||||
|
|
||||||
/* the selected modifier */
|
/* the selected modifier */
|
||||||
|
set_font(&bold_font);
|
||||||
xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ bold_font.id });
|
xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ bold_font.id });
|
||||||
if (modifier == MOD_Mod4)
|
if (modifier == MOD_Mod4)
|
||||||
txt(31, 4, "<Win>");
|
txt(31, 4, "<Win>");
|
||||||
else txt(31, 5, "<Alt>");
|
else txt(31, 5, "<Alt>");
|
||||||
|
|
||||||
/* green */
|
/* green */
|
||||||
|
set_font(&font);
|
||||||
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_FONT,
|
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_FONT,
|
||||||
(uint32_t[]) { get_colorpixel("#00FF00"), font.id });
|
(uint32_t[]) { get_colorpixel("#00FF00"), font.id });
|
||||||
|
|
||||||
|
@ -437,6 +440,7 @@ int main(int argc, char *argv[]) {
|
||||||
xcb_numlock_mask = get_mod_mask_for(XCB_NUM_LOCK, symbols, modmap_reply);
|
xcb_numlock_mask = get_mod_mask_for(XCB_NUM_LOCK, symbols, modmap_reply);
|
||||||
|
|
||||||
font = load_font(pattern, true);
|
font = load_font(pattern, true);
|
||||||
|
set_font(&font);
|
||||||
bold_font = load_font(patternbold, true);
|
bold_font = load_font(patternbold, true);
|
||||||
|
|
||||||
/* Open an input window */
|
/* Open an input window */
|
||||||
|
|
|
@ -104,8 +104,8 @@ static int handle_expose(void *data, xcb_connection_t *conn, xcb_expose_event_t
|
||||||
memcpy(full_text, prompt, prompt_len * 2);
|
memcpy(full_text, prompt, prompt_len * 2);
|
||||||
memcpy(full_text + (prompt_len * 2), con, input_position * 2);
|
memcpy(full_text + (prompt_len * 2), con, input_position * 2);
|
||||||
}
|
}
|
||||||
xcb_image_text_16(conn, input_position + prompt_len, pixmap, pixmap_gc, 4 /* X */,
|
if (input_position + prompt_len != 0)
|
||||||
font.height + 2 /* Y = baseline of font */, (xcb_char2b_t*)full_text);
|
draw_text(full_text, input_position + prompt_len, true, pixmap, pixmap_gc, 4, 4);
|
||||||
|
|
||||||
/* Copy the contents of the pixmap to the real window */
|
/* Copy the contents of the pixmap to the real window */
|
||||||
xcb_copy_area(conn, pixmap, win, pixmap_gc, 0, 0, 0, 0, /* */ 500, font.height + 8);
|
xcb_copy_area(conn, pixmap, win, pixmap_gc, 0, 0, 0, 0, /* */ 500, font.height + 8);
|
||||||
|
@ -361,6 +361,7 @@ int main(int argc, char *argv[]) {
|
||||||
symbols = xcb_key_symbols_alloc(conn);
|
symbols = xcb_key_symbols_alloc(conn);
|
||||||
|
|
||||||
font = load_font(pattern, true);
|
font = load_font(pattern, true);
|
||||||
|
set_font(&font);
|
||||||
|
|
||||||
/* Open an input window */
|
/* Open an input window */
|
||||||
win = xcb_generate_id(conn);
|
win = xcb_generate_id(conn);
|
||||||
|
|
|
@ -135,8 +135,7 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
|
||||||
values[0] = color_text;
|
values[0] = color_text;
|
||||||
values[1] = color_background;
|
values[1] = color_background;
|
||||||
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, values);
|
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, values);
|
||||||
xcb_image_text_8(conn, strlen(prompt), pixmap, pixmap_gc, 4 + 4/* X */,
|
draw_text(prompt, strlen(prompt), false, pixmap, pixmap_gc, 4 + 4, 4 + 4);
|
||||||
font.height + 2 + 4 /* Y = baseline of font */, prompt);
|
|
||||||
|
|
||||||
/* render close button */
|
/* render close button */
|
||||||
int line_width = 4;
|
int line_width = 4;
|
||||||
|
@ -163,8 +162,7 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
|
||||||
values[1] = color_button_background;
|
values[1] = color_button_background;
|
||||||
values[2] = 1;
|
values[2] = 1;
|
||||||
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_LINE_WIDTH, values);
|
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_LINE_WIDTH, values);
|
||||||
xcb_image_text_8(conn, strlen("x"), pixmap, pixmap_gc, y - w - line_width + (w / 2) - 4/* X */,
|
draw_text("X", 1, false, pixmap, pixmap_gc, y - w - line_width + w / 2 - 4, 4 + 4 - 1);
|
||||||
font.height + 2 + 4 - 1/* Y = baseline of font */, "X");
|
|
||||||
y -= w;
|
y -= w;
|
||||||
|
|
||||||
y -= 20;
|
y -= 20;
|
||||||
|
@ -194,8 +192,8 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
|
||||||
values[0] = color_text;
|
values[0] = color_text;
|
||||||
values[1] = color_button_background;
|
values[1] = color_button_background;
|
||||||
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, values);
|
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, values);
|
||||||
xcb_image_text_8(conn, strlen(buttons[c].label), pixmap, pixmap_gc, y - w - line_width + 6/* X */,
|
draw_text(buttons[c].label, strlen(buttons[c].label), false, pixmap, pixmap_gc,
|
||||||
font.height + 2 + 3/* Y = baseline of font */, buttons[c].label);
|
y - w - line_width + 6, 4 + 3);
|
||||||
|
|
||||||
y -= w;
|
y -= w;
|
||||||
}
|
}
|
||||||
|
@ -304,6 +302,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
font = load_font(pattern, true);
|
font = load_font(pattern, true);
|
||||||
|
set_font(&font);
|
||||||
|
|
||||||
/* Open an input window */
|
/* Open an input window */
|
||||||
win = xcb_generate_id(conn);
|
win = xcb_generate_id(conn);
|
||||||
|
|
|
@ -193,7 +193,9 @@ void render_con(Con *con, bool render_fullscreen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find the height for the decorations */
|
/* find the height for the decorations */
|
||||||
int deco_height = config.font.height + 5;
|
int deco_height = config.font.height + 4;
|
||||||
|
if (config.font.height & 0x01)
|
||||||
|
++deco_height;
|
||||||
|
|
||||||
/* precalculate the sizes to be able to correct rounding errors */
|
/* precalculate the sizes to be able to correct rounding errors */
|
||||||
int sizes[children];
|
int sizes[children];
|
||||||
|
|
|
@ -50,12 +50,8 @@ static int sig_draw_window(xcb_window_t win, int width, int height, int font_hei
|
||||||
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
|
xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") });
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(crash_text) / sizeof(char*); i++) {
|
for (int i = 0; i < sizeof(crash_text) / sizeof(char*); i++) {
|
||||||
int text_len = strlen(crash_text[i]);
|
draw_text(crash_text[i], strlen(crash_text[i]), false,
|
||||||
xcb_char2b_t *full_text = convert_utf8_to_ucs2(crash_text[i], &text_len);
|
pixmap, pixmap_gc, 8, 3 + (i - 1) * font_height);
|
||||||
xcb_image_text_16(conn, text_len, pixmap, pixmap_gc, 8 /* X */,
|
|
||||||
3 + (i + 1) * font_height /* Y = baseline of font */,
|
|
||||||
(xcb_char2b_t*)full_text);
|
|
||||||
free(full_text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the contents of the pixmap to the real window */
|
/* Copy the contents of the pixmap to the real window */
|
||||||
|
|
38
src/x.c
38
src/x.c
|
@ -411,22 +411,15 @@ void x_draw_decoration(Con *con) {
|
||||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
|
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
|
||||||
uint32_t values[] = { p->color->text, p->color->background, config.font.id };
|
uint32_t values[] = { p->color->text, p->color->background, config.font.id };
|
||||||
xcb_change_gc(conn, parent->pm_gc, mask, values);
|
xcb_change_gc(conn, parent->pm_gc, mask, values);
|
||||||
int text_offset_y = config.font.height + (con->deco_rect.height - config.font.height) / 2 - 1;
|
int text_offset_y = (con->deco_rect.height - config.font.height) / 2;
|
||||||
|
|
||||||
struct Window *win = con->window;
|
struct Window *win = con->window;
|
||||||
if (win == NULL || win->name_x == NULL) {
|
if (win == NULL || win->name_x == NULL) {
|
||||||
/* this is a non-leaf container, we need to make up a good description */
|
/* this is a non-leaf container, we need to make up a good description */
|
||||||
// TODO: use a good description instead of just "another container"
|
// TODO: use a good description instead of just "another container"
|
||||||
xcb_image_text_8(
|
draw_text("another container", strlen("another container"), false,
|
||||||
conn,
|
parent->pixmap, parent->pm_gc,
|
||||||
strlen("another container"),
|
con->deco_rect.x + 2, con->deco_rect.y + text_offset_y);
|
||||||
parent->pixmap,
|
|
||||||
parent->pm_gc,
|
|
||||||
con->deco_rect.x + 2,
|
|
||||||
con->deco_rect.y + text_offset_y,
|
|
||||||
"another container"
|
|
||||||
);
|
|
||||||
|
|
||||||
goto copy_pixmaps;
|
goto copy_pixmaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,26 +440,9 @@ void x_draw_decoration(Con *con) {
|
||||||
//DLOG("indent_level = %d, indent_mult = %d\n", indent_level, indent_mult);
|
//DLOG("indent_level = %d, indent_mult = %d\n", indent_level, indent_mult);
|
||||||
int indent_px = (indent_level * 5) * indent_mult;
|
int indent_px = (indent_level * 5) * indent_mult;
|
||||||
|
|
||||||
if (win->uses_net_wm_name)
|
draw_text(win->name_x, win->name_len, win->uses_net_wm_name,
|
||||||
xcb_image_text_16(
|
parent->pixmap, parent->pm_gc,
|
||||||
conn,
|
con->deco_rect.x + 2 + indent_px, con->deco_rect.y + text_offset_y);
|
||||||
win->name_len,
|
|
||||||
parent->pixmap,
|
|
||||||
parent->pm_gc,
|
|
||||||
con->deco_rect.x + 2 + indent_px,
|
|
||||||
con->deco_rect.y + text_offset_y,
|
|
||||||
(xcb_char2b_t*)win->name_x
|
|
||||||
);
|
|
||||||
else
|
|
||||||
xcb_image_text_8(
|
|
||||||
conn,
|
|
||||||
win->name_len,
|
|
||||||
parent->pixmap,
|
|
||||||
parent->pm_gc,
|
|
||||||
con->deco_rect.x + 2 + indent_px,
|
|
||||||
con->deco_rect.y + text_offset_y,
|
|
||||||
win->name_x
|
|
||||||
);
|
|
||||||
|
|
||||||
copy_pixmaps:
|
copy_pixmaps:
|
||||||
xcb_copy_area(conn, con->pixmap, con->frame, con->pm_gc, 0, 0, 0, 0, con->rect.width, con->rect.height);
|
xcb_copy_area(conn, con->pixmap, con->frame, con->pm_gc, 0, 0, 0, 0, con->rect.width, con->rect.height);
|
||||||
|
|
Loading…
Reference in New Issue