draw: text extents now gets len as arg
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
ad58260243
commit
750040be68
|
@ -993,12 +993,13 @@ draw_rotate(draw_context_t *ctx,
|
|||
* \param phys_screen Physical screen number.
|
||||
* \param font Font to use.
|
||||
* \param text The text.
|
||||
* \param len The text length.
|
||||
* \param pdata The parser data to fill.
|
||||
* \return Text height and width.
|
||||
*/
|
||||
area_t
|
||||
draw_text_extents(xcb_connection_t *conn, int phys_screen, font_t *font,
|
||||
const char *text, draw_parser_data_t *parser_data)
|
||||
const char *text, ssize_t len, draw_parser_data_t *parser_data)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
|
@ -1006,9 +1007,8 @@ draw_text_extents(xcb_connection_t *conn, int phys_screen, font_t *font,
|
|||
PangoRectangle ext;
|
||||
xcb_screen_t *s = xutil_screen_get(conn, phys_screen);
|
||||
area_t geom = { 0, 0, 0, 0 };
|
||||
ssize_t len;
|
||||
|
||||
if(!(len = a_strlen(text)))
|
||||
if(!len)
|
||||
return geom;
|
||||
|
||||
parser_data->connection = conn;
|
||||
|
|
|
@ -214,7 +214,7 @@ void draw_image_delete(draw_image_t **);
|
|||
void draw_image(draw_context_t *, int, int, int, draw_image_t *);
|
||||
void draw_image_from_argb_data(draw_context_t *, int, int, int, int, int, unsigned char *);
|
||||
void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int);
|
||||
area_t draw_text_extents(xcb_connection_t *, int, font_t *, const char *, draw_parser_data_t *);
|
||||
area_t draw_text_extents(xcb_connection_t *, int, font_t *, const char *, ssize_t, draw_parser_data_t *);
|
||||
alignment_t draw_align_fromstr(const char *, ssize_t);
|
||||
const char *draw_align_tostr(alignment_t);
|
||||
|
||||
|
|
6
mouse.c
6
mouse.c
|
@ -252,6 +252,8 @@ mouse_infobox_draw(draw_context_t *ctx,
|
|||
simplewindow_refresh_pixmap(sw);
|
||||
}
|
||||
|
||||
#define MOUSE_INFOBOX_STRING_DEFAULT "0000x0000+0000+0000"
|
||||
|
||||
/** Initialize the infobox window.
|
||||
* \param phys_screen Physical screen number.
|
||||
* \param border Border size of the client.
|
||||
|
@ -272,7 +274,9 @@ mouse_infobox_new(int phys_screen, int border, area_t geometry,
|
|||
geom = draw_text_extents(globalconf.connection,
|
||||
globalconf.default_screen,
|
||||
globalconf.font,
|
||||
"0000x0000+0000+0000", &pdata);
|
||||
MOUSE_INFOBOX_STRING_DEFAULT,
|
||||
sizeof(MOUSE_INFOBOX_STRING_DEFAULT),
|
||||
&pdata);
|
||||
geom.x = geometry.x + ((2 * border + geometry.width) - geom.width) / 2;
|
||||
geom.y = geometry.y + ((2 * border + geometry.height) - geom.height) / 2;
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w,
|
|||
area_t area;
|
||||
taglist_drawn_area_t *tda;
|
||||
int prev_width = 0;
|
||||
size_t len;
|
||||
|
||||
tag_array_t *tags = &globalconf.screens[screen].tags;
|
||||
const char **text = p_alloca(const char *, tags->len);
|
||||
|
@ -124,13 +125,13 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w,
|
|||
luaA_dofunction(globalconf.L, data->label, 1, 1);
|
||||
|
||||
if(lua_isstring(globalconf.L, -1))
|
||||
text[i] = lua_tostring(globalconf.L, -1);
|
||||
text[i] = lua_tolstring(globalconf.L, -1, &len);
|
||||
|
||||
lua_pop(globalconf.L, 1);
|
||||
|
||||
draw_parser_data_init(&pdata[i]);
|
||||
area = draw_text_extents(ctx->connection, ctx->phys_screen,
|
||||
globalconf.font, text[i], &pdata[i]);
|
||||
globalconf.font, text[i], len, &pdata[i]);
|
||||
|
||||
if(pdata[i].bg_image)
|
||||
area.width = MAX(area.width, pdata[i].bg_resize ? w->area.height : pdata[i].bg_image->width);
|
||||
|
|
|
@ -29,6 +29,8 @@ typedef struct
|
|||
{
|
||||
/** Textbox text */
|
||||
char *text;
|
||||
/** Textbox text length */
|
||||
size_t len;
|
||||
/** Textbox width */
|
||||
int width;
|
||||
} textbox_data_t;
|
||||
|
@ -59,7 +61,7 @@ textbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)),
|
|||
{
|
||||
draw_parser_data_init(&pdata);
|
||||
w->area.width = draw_text_extents(ctx->connection, ctx->phys_screen,
|
||||
globalconf.font, d->text, &pdata).width;
|
||||
globalconf.font, d->text, d->len, &pdata).width;
|
||||
|
||||
if(w->area.width > ctx->width - used)
|
||||
w->area.width = ctx->width - used;
|
||||
|
@ -145,6 +147,7 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
|
|||
{
|
||||
p_delete(&d->text);
|
||||
a_iso2utf8(&d->text, buf, len);
|
||||
d->len = len;
|
||||
}
|
||||
break;
|
||||
case A_TK_WIDTH:
|
||||
|
|
Loading…
Reference in New Issue