[draw] Make draw_text using a const pointer to a style
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
f0e29977d8
commit
b142264787
|
@ -431,7 +431,7 @@ redraw(void)
|
||||||
|
|
||||||
if(a_strlen(globalconf.prompt))
|
if(a_strlen(globalconf.prompt))
|
||||||
{
|
{
|
||||||
draw_text(globalconf.ctx, geometry, globalconf.prompt, globalconf.styles.focus);
|
draw_text(globalconf.ctx, geometry, globalconf.prompt, &globalconf.styles.focus);
|
||||||
|
|
||||||
len = MARGIN * 2 + draw_text_extents(globalconf.connection, globalconf.default_screen,
|
len = MARGIN * 2 + draw_text_extents(globalconf.connection, globalconf.default_screen,
|
||||||
globalconf.styles.focus.font, globalconf.prompt).width;
|
globalconf.styles.focus.font, globalconf.prompt).width;
|
||||||
|
@ -439,7 +439,7 @@ redraw(void)
|
||||||
geometry.width -= len;
|
geometry.width -= len;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_text(globalconf.ctx, geometry, globalconf.text, globalconf.styles.normal);
|
draw_text(globalconf.ctx, geometry, globalconf.text, &globalconf.styles.normal);
|
||||||
|
|
||||||
len = MARGIN * 2 + MAX(draw_text_extents(globalconf.connection, globalconf.default_screen,
|
len = MARGIN * 2 + MAX(draw_text_extents(globalconf.connection, globalconf.default_screen,
|
||||||
globalconf.styles.normal.font, globalconf.text).width,
|
globalconf.styles.normal.font, globalconf.text).width,
|
||||||
|
@ -461,7 +461,7 @@ redraw(void)
|
||||||
else
|
else
|
||||||
selected_item_is_drawn = true;
|
selected_item_is_drawn = true;
|
||||||
}
|
}
|
||||||
draw_text(globalconf.ctx, geometry, item->data, style);
|
draw_text(globalconf.ctx, geometry, item->data, &style);
|
||||||
geometry.x += len;
|
geometry.x += len;
|
||||||
geometry.width -= len;
|
geometry.width -= len;
|
||||||
}
|
}
|
||||||
|
@ -483,7 +483,7 @@ redraw(void)
|
||||||
if(geometry.x < prompt_len)
|
if(geometry.x < prompt_len)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
draw_text(globalconf.ctx, geometry, item->data, style);
|
draw_text(globalconf.ctx, geometry, item->data, &style);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(item)
|
if(item)
|
||||||
|
|
|
@ -211,7 +211,7 @@ main(int argc, char **argv)
|
||||||
geometry.width, geometry.height, sw->drawable);
|
geometry.width, geometry.height, sw->drawable);
|
||||||
|
|
||||||
geometry.x = geometry.y = 0;
|
geometry.x = geometry.y = 0;
|
||||||
draw_text(ctx, geometry, argv[optind], globalconf.style);
|
draw_text(ctx, geometry, argv[optind], &globalconf.style);
|
||||||
|
|
||||||
if(icon_geometry.width > 0 && icon_geometry.height > 0)
|
if(icon_geometry.width > 0 && icon_geometry.height > 0)
|
||||||
draw_image(ctx, 0, (geometry.height / 2) - (globalconf.style.font->height / 2),
|
draw_image(ctx, 0, (geometry.height / 2) - (globalconf.style.font->height / 2),
|
||||||
|
|
|
@ -285,14 +285,14 @@ draw_text_markup_expand(draw_parser_data_t *data,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Draw text into a draw context
|
/** Draw text into a draw context.
|
||||||
* \param ctx draw_context_t to draw to
|
* \param ctx Draw context to draw to.
|
||||||
* \param area area to draw to
|
* \param area Area to draw to.
|
||||||
* \param text text to draw
|
* \param text Text to draw.
|
||||||
* \return area_t with width and height are set to what used
|
* \param style A pointer to the style to use.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
draw_text(draw_context_t *ctx, area_t area, const char *text, style_t style)
|
draw_text(draw_context_t *ctx, area_t area, const char *text, const style_t *style)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
ssize_t len, olen;
|
ssize_t len, olen;
|
||||||
|
@ -326,7 +326,7 @@ draw_text(draw_context_t *ctx, area_t area, const char *text, style_t style)
|
||||||
if(parser_data.has_bg_color)
|
if(parser_data.has_bg_color)
|
||||||
draw_rectangle(ctx, area, 1.0, true, parser_data.bg_color);
|
draw_rectangle(ctx, area, 1.0, true, parser_data.bg_color);
|
||||||
else
|
else
|
||||||
draw_rectangle(ctx, area, 1.0, true, style.bg);
|
draw_rectangle(ctx, area, 1.0, true, style->bg);
|
||||||
|
|
||||||
pango_layout_set_width(ctx->layout,
|
pango_layout_set_width(ctx->layout,
|
||||||
pango_units_from_double(area.width
|
pango_units_from_double(area.width
|
||||||
|
@ -334,14 +334,14 @@ draw_text(draw_context_t *ctx, area_t area, const char *text, style_t style)
|
||||||
+ parser_data.margin.right)));
|
+ parser_data.margin.right)));
|
||||||
pango_layout_set_ellipsize(ctx->layout, PANGO_ELLIPSIZE_END);
|
pango_layout_set_ellipsize(ctx->layout, PANGO_ELLIPSIZE_END);
|
||||||
pango_layout_set_markup(ctx->layout, buf, len);
|
pango_layout_set_markup(ctx->layout, buf, len);
|
||||||
pango_layout_set_font_description(ctx->layout, style.font->desc);
|
pango_layout_set_font_description(ctx->layout, style->font->desc);
|
||||||
pango_layout_get_pixel_extents(ctx->layout, NULL, &ext);
|
pango_layout_get_pixel_extents(ctx->layout, NULL, &ext);
|
||||||
|
|
||||||
x = area.x + parser_data.margin.left;
|
x = area.x + parser_data.margin.left;
|
||||||
/* + 1 is added for rounding, so that in any case of doubt we rather draw
|
/* + 1 is added for rounding, so that in any case of doubt we rather draw
|
||||||
* the text 1px lower than too high which usually results in a better type
|
* the text 1px lower than too high which usually results in a better type
|
||||||
* face */
|
* face */
|
||||||
y = area.y + (ctx->height - style.font->height + 1) / 2;
|
y = area.y + (ctx->height - style->font->height + 1) / 2;
|
||||||
|
|
||||||
switch(parser_data.align)
|
switch(parser_data.align)
|
||||||
{
|
{
|
||||||
|
@ -359,8 +359,8 @@ draw_text(draw_context_t *ctx, area_t area, const char *text, style_t style)
|
||||||
p_clear(&shadow, 1);
|
p_clear(&shadow, 1);
|
||||||
if(parser_data.shadow.offset)
|
if(parser_data.shadow.offset)
|
||||||
shadow = parser_data.shadow;
|
shadow = parser_data.shadow;
|
||||||
else if(style.shadow.offset)
|
else if(style->shadow.offset)
|
||||||
shadow = style.shadow;
|
shadow = style->shadow;
|
||||||
|
|
||||||
if(shadow.offset)
|
if(shadow.offset)
|
||||||
{
|
{
|
||||||
|
@ -376,9 +376,9 @@ draw_text(draw_context_t *ctx, area_t area, const char *text, style_t style)
|
||||||
cairo_move_to(ctx->cr, x, y);
|
cairo_move_to(ctx->cr, x, y);
|
||||||
|
|
||||||
cairo_set_source_rgb(ctx->cr,
|
cairo_set_source_rgb(ctx->cr,
|
||||||
style.fg.red / 65535.0,
|
style->fg.red / 65535.0,
|
||||||
style.fg.green / 65535.0,
|
style->fg.green / 65535.0,
|
||||||
style.fg.blue / 65535.0);
|
style->fg.blue / 65535.0);
|
||||||
pango_cairo_update_layout(ctx->cr, ctx->layout);
|
pango_cairo_update_layout(ctx->cr, ctx->layout);
|
||||||
pango_cairo_show_layout(ctx->cr, ctx->layout);
|
pango_cairo_show_layout(ctx->cr, ctx->layout);
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ void draw_context_delete(draw_context_t **);
|
||||||
font_t *draw_font_new(xcb_connection_t *, int, char *);
|
font_t *draw_font_new(xcb_connection_t *, int, char *);
|
||||||
void draw_font_delete(font_t **);
|
void draw_font_delete(font_t **);
|
||||||
|
|
||||||
void draw_text(draw_context_t *, area_t, const char *, style_t);
|
void draw_text(draw_context_t *, area_t, const char *, const style_t *);
|
||||||
void draw_rectangle(draw_context_t *, area_t, float, bool, xcolor_t);
|
void draw_rectangle(draw_context_t *, area_t, float, bool, xcolor_t);
|
||||||
void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, area_t, xcolor_t *, xcolor_t *, xcolor_t *);
|
void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, area_t, xcolor_t *, xcolor_t *, xcolor_t *);
|
||||||
|
|
||||||
|
|
37
mouse.c
37
mouse.c
|
@ -131,14 +131,15 @@ mouse_snapclient(client_t *c, area_t geometry)
|
||||||
return titlebar_geometry_remove(&c->titlebar, geometry);
|
return titlebar_geometry_remove(&c->titlebar, geometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Redraw the resizebar
|
/** Redraw the resizebar.
|
||||||
* \param ctx draw context
|
* \param ctx Draw context.
|
||||||
* \param style the style to use for drawing
|
* \param style The style pointer to use for drawing.
|
||||||
* \param geometry the geometry to use for the box
|
* \param geometry The geometry to use for the box.
|
||||||
* \param border the client border size
|
* \param border The client border size.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
mouse_resizebar_draw(draw_context_t *ctx, style_t style, simple_window_t *sw, area_t geometry, int border)
|
mouse_resizebar_draw(draw_context_t *ctx, style_t *style,
|
||||||
|
simple_window_t *sw, area_t geometry, int border)
|
||||||
{
|
{
|
||||||
area_t draw_geometry = { 0, 0, ctx->width, ctx->height, NULL, NULL };
|
area_t draw_geometry = { 0, 0, ctx->width, ctx->height, NULL, NULL };
|
||||||
char size[64];
|
char size[64];
|
||||||
|
@ -153,21 +154,23 @@ mouse_resizebar_draw(draw_context_t *ctx, style_t style, simple_window_t *sw, ar
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initialize the resizebar window.
|
/** Initialize the resizebar window.
|
||||||
* \param phys_screen physical screen id
|
* \param phys_screen Physical screen number.
|
||||||
* \param border border size of the client
|
* \param border Border size of the client.
|
||||||
* \param geometry client geometry
|
* \param geometry Client geometry.
|
||||||
* \param style style used to draw
|
* \param style Style used to draw.
|
||||||
* \param ctx drawctx to create
|
* \param ctx Draw context to create.
|
||||||
|
* \return The simple window.
|
||||||
*/
|
*/
|
||||||
static simple_window_t *
|
static simple_window_t *
|
||||||
mouse_resizebar_new(int phys_screen, int border, area_t geometry, style_t style, draw_context_t **ctx)
|
mouse_resizebar_new(int phys_screen, int border, area_t geometry,
|
||||||
|
style_t *style, draw_context_t **ctx)
|
||||||
{
|
{
|
||||||
simple_window_t *sw;
|
simple_window_t *sw;
|
||||||
area_t geom;
|
area_t geom;
|
||||||
|
|
||||||
geom = draw_text_extents(globalconf.connection,
|
geom = draw_text_extents(globalconf.connection,
|
||||||
globalconf.default_screen,
|
globalconf.default_screen,
|
||||||
style.font,
|
style->font,
|
||||||
"0000x0000+0000+0000");
|
"0000x0000+0000+0000");
|
||||||
geom.x = geometry.x + ((2 * border + geometry.width) - geom.width) / 2;
|
geom.x = geometry.x + ((2 * border + geometry.width) - geom.width) / 2;
|
||||||
geom.y = geometry.y + ((2 * border + geometry.height) - geom.height) / 2;
|
geom.y = geometry.y + ((2 * border + geometry.height) - geom.height) / 2;
|
||||||
|
@ -200,7 +203,7 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
|
||||||
Layout *layout = layout_get_current(screen);
|
Layout *layout = layout_get_current(screen);
|
||||||
simple_window_t *sw = NULL;
|
simple_window_t *sw = NULL;
|
||||||
draw_context_t *ctx;
|
draw_context_t *ctx;
|
||||||
style_t style;
|
style_t *style;
|
||||||
xcb_generic_event_t *ev = NULL;
|
xcb_generic_event_t *ev = NULL;
|
||||||
xcb_motion_notify_event_t *ev_motion = NULL;
|
xcb_motion_notify_event_t *ev_motion = NULL;
|
||||||
xcb_grab_pointer_reply_t *grab_pointer_r = NULL;
|
xcb_grab_pointer_reply_t *grab_pointer_r = NULL;
|
||||||
|
@ -222,7 +225,7 @@ uicb_client_movemouse(int screen, char *arg __attribute__ ((unused)))
|
||||||
geometry = c->geometry;
|
geometry = c->geometry;
|
||||||
ocx = geometry.x;
|
ocx = geometry.x;
|
||||||
ocy = geometry.y;
|
ocy = geometry.y;
|
||||||
style = globalconf.screens[c->screen].styles.focus;
|
style = &globalconf.screens[c->screen].styles.focus;
|
||||||
|
|
||||||
/* Get responses */
|
/* Get responses */
|
||||||
if(!(grab_pointer_r = xcb_grab_pointer_reply(globalconf.connection, grab_pointer_c, NULL)))
|
if(!(grab_pointer_r = xcb_grab_pointer_reply(globalconf.connection, grab_pointer_c, NULL)))
|
||||||
|
@ -330,7 +333,7 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
|
||||||
double mwfact;
|
double mwfact;
|
||||||
simple_window_t *sw = NULL;
|
simple_window_t *sw = NULL;
|
||||||
draw_context_t *ctx = NULL;
|
draw_context_t *ctx = NULL;
|
||||||
style_t style;
|
style_t *style;
|
||||||
xcb_grab_pointer_cookie_t grab_pointer_c;
|
xcb_grab_pointer_cookie_t grab_pointer_c;
|
||||||
xcb_grab_pointer_reply_t *grab_pointer_r = NULL;
|
xcb_grab_pointer_reply_t *grab_pointer_r = NULL;
|
||||||
xcb_screen_t *s = xcb_aux_get_screen(globalconf.connection, c->phys_screen);
|
xcb_screen_t *s = xcb_aux_get_screen(globalconf.connection, c->phys_screen);
|
||||||
|
@ -339,7 +342,7 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused)))
|
||||||
if(!c || c->isfixed)
|
if(!c || c->isfixed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
style = globalconf.screens[c->screen].styles.focus;
|
style = &globalconf.screens[c->screen].styles.focus;
|
||||||
|
|
||||||
if(layout->arrange == layout_floating || c->isfloating)
|
if(layout->arrange == layout_floating || c->isfloating)
|
||||||
{
|
{
|
||||||
|
|
|
@ -221,7 +221,7 @@ titlebar_draw(client_t *c)
|
||||||
text = titlebar_text(c);
|
text = titlebar_text(c);
|
||||||
geometry.x = geometry.y = 0;
|
geometry.x = geometry.y = 0;
|
||||||
style = client_style_get(c);
|
style = client_style_get(c);
|
||||||
draw_text(ctx, geometry, text, *style);
|
draw_text(ctx, geometry, text, style);
|
||||||
p_delete(&text);
|
p_delete(&text);
|
||||||
|
|
||||||
switch(c->titlebar.position)
|
switch(c->titlebar.position)
|
||||||
|
|
|
@ -163,7 +163,7 @@ taglist_draw(widget_t *widget,
|
||||||
tag && area;
|
tag && area;
|
||||||
tag = tag->next, area = area->next, i++)
|
tag = tag->next, area = area->next, i++)
|
||||||
{
|
{
|
||||||
draw_text(ctx, *area, text[i], *styles[i]);
|
draw_text(ctx, *area, text[i], styles[i]);
|
||||||
p_delete(&text[i]);
|
p_delete(&text[i]);
|
||||||
|
|
||||||
if(tag_isoccupied(tag))
|
if(tag_isoccupied(tag))
|
||||||
|
|
|
@ -162,7 +162,7 @@ tasklist_draw(widget_t *widget, draw_context_t *ctx, int offset, int used)
|
||||||
if(i == n - 1)
|
if(i == n - 1)
|
||||||
area.width += box_width_rest;
|
area.width += box_width_rest;
|
||||||
|
|
||||||
draw_text(ctx, area, text, *style);
|
draw_text(ctx, area, text, style);
|
||||||
|
|
||||||
p_delete(&text);
|
p_delete(&text);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,8 @@ textbox_draw(widget_t *widget, draw_context_t *ctx, int offset, int used)
|
||||||
if(!widget->user_supplied_y)
|
if(!widget->user_supplied_y)
|
||||||
widget->area.y = 0;
|
widget->area.y = 0;
|
||||||
|
|
||||||
draw_text(ctx, widget->area, d->text, globalconf.screens[widget->statusbar->screen].styles.normal);
|
draw_text(ctx, widget->area, d->text,
|
||||||
|
&globalconf.screens[widget->statusbar->screen].styles.normal);
|
||||||
|
|
||||||
return widget->area.width;
|
return widget->area.width;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue