From 7fda48aa9fd5c5b6174de7378fd6e6592187a065 Mon Sep 17 00:00:00 2001 From: Axel Wagner Date: Fri, 17 Sep 2010 03:11:49 +0200 Subject: [PATCH] We don't need get_string_width anymore --- i3bar/include/xcb.h | 6 +++--- i3bar/src/workspaces.c | 5 +++-- i3bar/src/xcb.c | 28 +++------------------------- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/i3bar/include/xcb.h b/i3bar/include/xcb.h index 2e4b16a8..82216f7f 100644 --- a/i3bar/include/xcb.h +++ b/i3bar/include/xcb.h @@ -55,11 +55,11 @@ void draw_bars(); void redraw_bars(); /* - * Calculate the rendered width of a string with the configured font. + * Predicts the length of text based on cached data. * The string has to be encoded in ucs2 and glyph_len has to be the length - * of the string (in width) + * of the string (in glyphs). * */ -int get_string_width(xcb_char2b_t *string, int glyph_len); +uint32_t predict_text_extents(xcb_char2b_t *text, uint32_t length); #endif diff --git a/i3bar/src/workspaces.c b/i3bar/src/workspaces.c index 8ba79eec..71903fb0 100644 --- a/i3bar/src/workspaces.c +++ b/i3bar/src/workspaces.c @@ -115,8 +115,9 @@ static int workspaces_string_cb(void *params_, const unsigned char *val, unsigne xcb_char2b_t *ucs2_name = (xcb_char2b_t*) convert_utf8_to_ucs2(params->workspaces_walk->name, &ucs2_len); params->workspaces_walk->ucs2_name = ucs2_name; params->workspaces_walk->name_glyphs = ucs2_len; - params->workspaces_walk->name_width = get_string_width(params->workspaces_walk->ucs2_name, - params->workspaces_walk->name_glyphs); + params->workspaces_walk->name_width = + predict_text_extents(params->workspaces_walk->ucs2_name, + params->workspaces_walk->name_glyphs); printf("Got Workspace %s, name_width: %d, glyphs: %d\n", params->workspaces_walk->name, diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 453d5f46..e200c5e4 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -64,7 +64,9 @@ ev_io *xcb_io; ev_io *xkb_io; /* - * Predicts the length of text based on cached data + * Predicts the length of text based on cached data. + * The string has to be encoded in ucs2 and glyph_len has to be the length + * of the string (in glyphs). * */ uint32_t predict_text_extents(xcb_char2b_t *text, uint32_t length) { @@ -396,30 +398,6 @@ void xkb_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) { } } -/* - * Calculate the rendered width of a string with the configured font. - * The string has to be encoded in ucs2 and glyph_len has to be the length - * of the string (in width) - * - */ -int get_string_width(xcb_char2b_t *string, int glyph_len) { - xcb_query_text_extents_cookie_t cookie; - xcb_query_text_extents_reply_t *reply; - xcb_generic_error_t *error = NULL; - int width; - - cookie = xcb_query_text_extents(xcb_connection, xcb_font, glyph_len, string); - reply = xcb_query_text_extents_reply(xcb_connection, cookie, &error); - if (error != NULL) { - printf("ERROR: Could not get text extents! XCB-errorcode: %d\n", error->error_code); - exit(EXIT_FAILURE); - } - - width = reply->overall_width; - free(reply); - return width; -} - /* * Initialize xcb and use the specified fontname for text-rendering * -- 2.39.5