[draw] Add margin code inside markup string
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
1fc2b7997a
commit
f12f1798dd
|
@ -431,8 +431,7 @@ redraw(void)
|
||||||
|
|
||||||
if(a_strlen(globalconf.prompt))
|
if(a_strlen(globalconf.prompt))
|
||||||
{
|
{
|
||||||
draw_text(globalconf.ctx, geometry,
|
draw_text(globalconf.ctx, geometry, globalconf.prompt, globalconf.styles.focus);
|
||||||
MARGIN, 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;
|
||||||
|
@ -440,8 +439,7 @@ redraw(void)
|
||||||
geometry.width -= len;
|
geometry.width -= len;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_text(globalconf.ctx, geometry,
|
draw_text(globalconf.ctx, geometry, globalconf.text, globalconf.styles.normal);
|
||||||
MARGIN, 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,
|
||||||
|
@ -463,7 +461,7 @@ redraw(void)
|
||||||
else
|
else
|
||||||
selected_item_is_drawn = true;
|
selected_item_is_drawn = true;
|
||||||
}
|
}
|
||||||
draw_text(globalconf.ctx, geometry, MARGIN / 2, item->data, style);
|
draw_text(globalconf.ctx, geometry, item->data, style);
|
||||||
geometry.x += len;
|
geometry.x += len;
|
||||||
geometry.width -= len;
|
geometry.width -= len;
|
||||||
}
|
}
|
||||||
|
@ -485,7 +483,7 @@ redraw(void)
|
||||||
if(geometry.x < prompt_len)
|
if(geometry.x < prompt_len)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
draw_text(globalconf.ctx, geometry, MARGIN / 2, 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, 0, 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),
|
||||||
|
|
|
@ -280,11 +280,11 @@ cfg_opt_t widget_taglist_opts[] =
|
||||||
/** Mouse bindings. */
|
/** Mouse bindings. */
|
||||||
CFG_SEC((char *) "mouse", mouse_taglist_opts, CFGF_MULTI),
|
CFG_SEC((char *) "mouse", mouse_taglist_opts, CFGF_MULTI),
|
||||||
/** Markup title string for normal tags */
|
/** Markup title string for normal tags */
|
||||||
CFG_STR((char *) "text_normal", (char *) "<text align=\"center\"/><bg color=\"#444444\"/><title/>", CFGF_NONE),
|
CFG_STR((char *) "text_normal", (char *) " <text align=\"center\"/><bg color=\"#444444\"/><title/> ", CFGF_NONE),
|
||||||
/** Markup title string for selected tags. */
|
/** Markup title string for selected tags. */
|
||||||
CFG_STR((char *) "text_focus", (char *) "<text align=\"center\"/><bg color=\"#535d6c\"/><title/>", CFGF_NONE),
|
CFG_STR((char *) "text_focus", (char *) " <text align=\"center\"/><bg color=\"#535d6c\"/><title/> ", CFGF_NONE),
|
||||||
/** Markup title string for tags with urgent windows. */
|
/** Markup title string for tags with urgent windows. */
|
||||||
CFG_STR((char *) "text_urgent", (char *) "<text align=\"center\"/><bg color=\"#ff4500\"/><title/>", CFGF_NONE),
|
CFG_STR((char *) "text_urgent", (char *) " <text align=\"center\"/><bg color=\"#ff4500\"/><title/> ", CFGF_NONE),
|
||||||
CFG_AWESOME_END()
|
CFG_AWESOME_END()
|
||||||
};
|
};
|
||||||
/** This section defines iconbox widget options. */
|
/** This section defines iconbox widget options. */
|
||||||
|
|
|
@ -221,6 +221,10 @@ typedef struct
|
||||||
int phys_screen;
|
int phys_screen;
|
||||||
char *text;
|
char *text;
|
||||||
alignment_t align;
|
alignment_t align;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
int left, right;
|
||||||
|
} margin;
|
||||||
bool has_bg_color;
|
bool has_bg_color;
|
||||||
xcolor_t bg_color;
|
xcolor_t bg_color;
|
||||||
} draw_parser_data_t;
|
} draw_parser_data_t;
|
||||||
|
@ -229,14 +233,14 @@ static bool
|
||||||
draw_text_markup_expand(draw_parser_data_t *data,
|
draw_text_markup_expand(draw_parser_data_t *data,
|
||||||
const char *str, ssize_t slen)
|
const char *str, ssize_t slen)
|
||||||
{
|
{
|
||||||
const char *elements[] = { "bg", "text", NULL };
|
const char *elements[] = { "bg", "text", "margin", NULL };
|
||||||
markup_parser_data_t *p;
|
markup_parser_data_t *p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
p = markup_parser_data_new(elements, NULL, countof(elements));
|
p = markup_parser_data_new(elements, NULL, countof(elements));
|
||||||
|
|
||||||
if(!markup_parse(p, str, slen))
|
if(!markup_parse(p, str, slen))
|
||||||
return false;
|
return a_strdup(str);
|
||||||
|
|
||||||
/* bg */
|
/* bg */
|
||||||
if(p->attribute_names[0])
|
if(p->attribute_names[0])
|
||||||
|
@ -251,6 +255,16 @@ draw_text_markup_expand(draw_parser_data_t *data,
|
||||||
if(!a_strcmp(p->attribute_names[1][i], "align"))
|
if(!a_strcmp(p->attribute_names[1][i], "align"))
|
||||||
data->align = draw_align_get_from_str(p->attribute_values[1][i]);
|
data->align = draw_align_get_from_str(p->attribute_values[1][i]);
|
||||||
|
|
||||||
|
/* margin */
|
||||||
|
if(p->attribute_names[2])
|
||||||
|
for(i = 0; p->attribute_names[2][i]; i++)
|
||||||
|
{
|
||||||
|
if(!a_strcmp(p->attribute_names[2][i], "left"))
|
||||||
|
data->margin.left = atoi(p->attribute_values[2][i]);
|
||||||
|
else if(!a_strcmp(p->attribute_names[2][i], "right"))
|
||||||
|
data->margin.right = atoi(p->attribute_values[2][i]);
|
||||||
|
}
|
||||||
|
|
||||||
/* stole text */
|
/* stole text */
|
||||||
data->text = p->text;
|
data->text = p->text;
|
||||||
p->text = NULL;
|
p->text = NULL;
|
||||||
|
@ -263,16 +277,11 @@ draw_text_markup_expand(draw_parser_data_t *data,
|
||||||
/** Draw text into a draw context
|
/** Draw text into a draw context
|
||||||
* \param ctx DrawCtx to draw to
|
* \param ctx DrawCtx to draw to
|
||||||
* \param area area to draw to
|
* \param area area to draw to
|
||||||
* \param padding padding to add before drawing the text
|
|
||||||
* \param text text to draw
|
* \param text text to draw
|
||||||
* \return area_t with width and height are set to what used
|
* \return area_t with width and height are set to what used
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
draw_text(DrawCtx *ctx,
|
draw_text(DrawCtx *ctx, area_t area, const char *text, style_t style)
|
||||||
area_t area,
|
|
||||||
int padding,
|
|
||||||
const char *text,
|
|
||||||
style_t style)
|
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
ssize_t len, olen;
|
ssize_t len, olen;
|
||||||
|
@ -311,13 +320,16 @@ draw_text(DrawCtx *ctx,
|
||||||
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_units_from_double(area.width - padding));
|
pango_layout_set_width(ctx->layout,
|
||||||
|
pango_units_from_double(area.width
|
||||||
|
- (parser_data.margin.left
|
||||||
|
+ 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 + padding;
|
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 */
|
||||||
|
|
|
@ -125,7 +125,7 @@ void draw_context_delete(DrawCtx **);
|
||||||
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(DrawCtx *, area_t, int, const char *, style_t);
|
void draw_text(DrawCtx *, area_t, const char *, style_t);
|
||||||
void draw_rectangle(DrawCtx *, area_t, float, bool, xcolor_t);
|
void draw_rectangle(DrawCtx *, area_t, float, bool, xcolor_t);
|
||||||
void draw_rectangle_gradient(DrawCtx *, area_t, float, bool, area_t, xcolor_t *, xcolor_t *, xcolor_t *);
|
void draw_rectangle_gradient(DrawCtx *, area_t, float, bool, area_t, xcolor_t *, xcolor_t *, xcolor_t *);
|
||||||
|
|
||||||
|
|
|
@ -148,10 +148,7 @@ markup_parse_text(GMarkupParseContext *context __attribute__ ((unused)),
|
||||||
len = a_strlen(p->text);
|
len = a_strlen(p->text);
|
||||||
rlen = len + 1 + text_len;
|
rlen = len + 1 + text_len;
|
||||||
p_realloc(&p->text, rlen);
|
p_realloc(&p->text, rlen);
|
||||||
if(len)
|
a_strncat(p->text, rlen, text, text_len);
|
||||||
a_strncat(p->text, rlen, text, len);
|
|
||||||
else
|
|
||||||
a_strncpy(p->text, rlen, text, text_len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a markup_parser_data_t structure with elements list.
|
/** Create a markup_parser_data_t structure with elements list.
|
||||||
|
@ -169,6 +166,7 @@ markup_parser_data_new(const char **elements, const char **elements_sub, ssize_t
|
||||||
|
|
||||||
p = p_new(markup_parser_data_t, 1);
|
p = p_new(markup_parser_data_t, 1);
|
||||||
|
|
||||||
|
p->text = p_new(char, 1);
|
||||||
p->elements = elements;
|
p->elements = elements;
|
||||||
p->elements_sub = elements_sub;
|
p->elements_sub = elements_sub;
|
||||||
p->attribute_names = p_new(char **, nelem);
|
p->attribute_names = p_new(char **, nelem);
|
||||||
|
|
2
mouse.c
2
mouse.c
|
@ -145,7 +145,7 @@ mouse_resizebar_draw(DrawCtx *ctx, style_t style, simple_window_t *sw, area_t ge
|
||||||
|
|
||||||
snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d",
|
snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d",
|
||||||
geometry.x, geometry.y, geometry.width, geometry.height);
|
geometry.x, geometry.y, geometry.width, geometry.height);
|
||||||
draw_text(ctx, draw_geometry, style.font->height / 2, size, style);
|
draw_text(ctx, draw_geometry, size, style);
|
||||||
simplewindow_move(sw,
|
simplewindow_move(sw,
|
||||||
geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2,
|
geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2,
|
||||||
geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2);
|
geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2);
|
||||||
|
|
|
@ -216,8 +216,7 @@ titlebar_draw(client_t *c)
|
||||||
|
|
||||||
text = titlebar_text(c);
|
text = titlebar_text(c);
|
||||||
geometry.x = geometry.y = 0;
|
geometry.x = geometry.y = 0;
|
||||||
draw_text(ctx, geometry, 0,
|
draw_text(ctx, geometry, text, globalconf.screens[c->screen].styles.normal);
|
||||||
text, globalconf.screens[c->screen].styles.normal);
|
|
||||||
p_delete(&text);
|
p_delete(&text);
|
||||||
|
|
||||||
switch(c->titlebar.position)
|
switch(c->titlebar.position)
|
||||||
|
|
|
@ -123,7 +123,6 @@ taglist_draw(widget_t *widget,
|
||||||
*area = draw_text_extents(ctx->connection, ctx->default_screen,
|
*area = draw_text_extents(ctx->connection, ctx->default_screen,
|
||||||
style.font, text[i]);
|
style.font, text[i]);
|
||||||
area->x = widget->area.width;
|
area->x = widget->area.width;
|
||||||
area->width += style.font->height;
|
|
||||||
area->height = widget->statusbar->height;
|
area->height = widget->statusbar->height;
|
||||||
area_list_append(&data->draw_area, area);
|
area_list_append(&data->draw_area, area);
|
||||||
widget->area.width += area->width;
|
widget->area.width += area->width;
|
||||||
|
@ -142,7 +141,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, 0, text[i], style);
|
draw_text(ctx, *area, text[i], style);
|
||||||
|
|
||||||
if(tag_isoccupied(tag))
|
if(tag_isoccupied(tag))
|
||||||
{
|
{
|
||||||
|
|
|
@ -169,7 +169,7 @@ tasklist_draw(widget_t *widget, DrawCtx *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, style.font->height / 2, text, style);
|
draw_text(ctx, area, text, style);
|
||||||
|
|
||||||
p_delete(&text);
|
p_delete(&text);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ textbox_draw(widget_t *widget, DrawCtx *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, 0, 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