Use draw_text() to render text to the correct spot
This commit is contained in:
parent
0dc802c7b5
commit
52120e3ed5
|
@ -111,6 +111,8 @@ void draw_text(xcb_drawable_t drawable, xcb_gcontext_t ctx, int16_t x, int16_t y
|
||||||
xcb_char2b_t *text, uint32_t glyph_count) {
|
xcb_char2b_t *text, uint32_t glyph_count) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int16_t pos_x = x;
|
int16_t pos_x = x;
|
||||||
|
int16_t font_ascent = font_info->font_ascent;
|
||||||
|
|
||||||
while (glyph_count > 0) {
|
while (glyph_count > 0) {
|
||||||
uint8_t chunk_size = MIN(255, glyph_count);
|
uint8_t chunk_size = MIN(255, glyph_count);
|
||||||
uint32_t chunk_width = predict_text_extents(text + offset, chunk_size);
|
uint32_t chunk_width = predict_text_extents(text + offset, chunk_size);
|
||||||
|
@ -119,7 +121,7 @@ void draw_text(xcb_drawable_t drawable, xcb_gcontext_t ctx, int16_t x, int16_t y
|
||||||
chunk_size,
|
chunk_size,
|
||||||
drawable,
|
drawable,
|
||||||
ctx,
|
ctx,
|
||||||
pos_x, y,
|
pos_x, y + font_ascent,
|
||||||
text + offset);
|
text + offset);
|
||||||
|
|
||||||
offset += chunk_size;
|
offset += chunk_size;
|
||||||
|
@ -166,24 +168,13 @@ void refresh_statusline() {
|
||||||
statusline_width,
|
statusline_width,
|
||||||
font_height);
|
font_height);
|
||||||
|
|
||||||
xcb_void_cookie_t text_cookie = xcb_image_text_16(xcb_connection,
|
draw_text(statusline_pm, statusline_ctx, 0, 0, text, glyph_count);
|
||||||
glyph_count,
|
|
||||||
statusline_pm,
|
|
||||||
statusline_ctx,
|
|
||||||
0,
|
|
||||||
font_height,
|
|
||||||
text);
|
|
||||||
|
|
||||||
xcb_generic_error_t *err;
|
xcb_generic_error_t *err;
|
||||||
if ((err = xcb_request_check(xcb_connection, sl_pm_cookie)) != NULL) {
|
if ((err = xcb_request_check(xcb_connection, sl_pm_cookie)) != NULL) {
|
||||||
printf("ERROR: Could not allocate statusline-buffer! XCB-error: %d\n", err->error_code);
|
printf("ERROR: Could not allocate statusline-buffer! XCB-error: %d\n", err->error_code);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = xcb_request_check(xcb_connection, text_cookie)) != NULL) {
|
|
||||||
printf("ERROR: Could not draw text to buffer! XCB-error: %d\n", err->error_code);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -790,18 +781,13 @@ void draw_bars() {
|
||||||
if (statusline != NULL) {
|
if (statusline != NULL) {
|
||||||
printf("Printing statusline!\n");
|
printf("Printing statusline!\n");
|
||||||
|
|
||||||
xcb_void_cookie_t ca_cookie = xcb_copy_area(xcb_connection,
|
xcb_copy_area(xcb_connection,
|
||||||
statusline_pm,
|
statusline_pm,
|
||||||
outputs_walk->buffer,
|
outputs_walk->buffer,
|
||||||
outputs_walk->bargc,
|
outputs_walk->bargc,
|
||||||
0, 0,
|
MAX(0, (int16_t)(statusline_width - outputs_walk->rect.w + 4)), 0,
|
||||||
MAX(0, (int16_t)(outputs_walk->rect.w - statusline_width)), 1,
|
MAX(0, (int16_t)(outputs_walk->rect.w - statusline_width - 4)), 3,
|
||||||
(uint16_t)outputs_walk->rect.w, font_height);
|
MIN(outputs_walk->rect.w - 4, statusline_width), font_height);
|
||||||
xcb_generic_error_t *err;
|
|
||||||
if ((err = xcb_request_check(xcb_connection, ca_cookie)) != NULL) {
|
|
||||||
printf("ERROR: Can not copy statusline-buffer! XCB-error: %d\n", err->error_code);
|
|
||||||
free(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i3_ws *ws_walk;
|
i3_ws *ws_walk;
|
||||||
|
|
Loading…
Reference in New Issue