We don't need get_string_width anymore

This commit is contained in:
Axel Wagner 2010-09-17 03:11:49 +02:00
parent 5deb95de33
commit 7fda48aa9f
3 changed files with 9 additions and 30 deletions

View File

@ -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

View File

@ -115,7 +115,8 @@ 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_width =
predict_text_extents(params->workspaces_walk->ucs2_name,
params->workspaces_walk->name_glyphs);
printf("Got Workspace %s, name_width: %d, glyphs: %d\n",

View File

@ -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
*