[tasklist] Remove styles; use drawtext format

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-04-28 12:23:10 +02:00
parent 26621fd598
commit eab7633675
5 changed files with 47 additions and 48 deletions

View file

@ -36,6 +36,7 @@
#include "screen.h"
#include "titlebar.h"
#include "layouts/floating.h"
#include "common/markup.h"
#include "common/xutil.h"
#include "common/xscreen.h"
@ -807,6 +808,21 @@ client_updatesizehints(client_t *c)
return size;
}
char *
client_markup_parse(client_t *c, const char *str, ssize_t len)
{
const char *elements[] = { "title", NULL };
const char *elements_sub[] = { c->name , NULL };
markup_parser_data_t *p;
p = markup_parser_data_new(elements, elements_sub, countof(elements));
if(!markup_parse(p, str, len))
return a_strdup(str);
return p->text;
}
/** Set the transparency of the selected client.
* Argument should be an absolut or relativ floating between 0.0 and 1.0
* \param screen Screen ID

View file

@ -42,6 +42,7 @@ void client_updatetitle(client_t *);
void client_saveprops(client_t *);
void client_kill(client_t *);
void client_setfloating(client_t *, bool, layer_t);
char * client_markup_parse(client_t *, const char *, ssize_t);
uicb_t uicb_client_kill;
uicb_t uicb_client_moveresize;

View file

@ -328,8 +328,12 @@ cfg_opt_t widget_tasklist_opts[] =
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
/** Mouse bindings. */
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
/** Styles to use for drawing. */
CFG_SEC((char *) "styles", styles_opts, CFGF_NONE),
/** Markup title string for normal window */
CFG_STR((char *) "text_normal", (char *) "<bg color=\"#444444\"/><title/>", CFGF_NONE),
/** Markup title string for focused windows. */
CFG_STR((char *) "text_focus", (char *) "<bg color=\"#535d6c\"/><title/>", CFGF_NONE),
/** Markup title string for urgent windows. */
CFG_STR((char *) "text_urgent", (char *) "<bg color=\"#ff4500\"/><title/>", CFGF_NONE),
/** Text alignment. */
CFG_ALIGNMENT((char *) "text_align", (char *) "left", CFGF_NONE),
/** Which windows to show: tags, all or focus. */

View file

@ -27,25 +27,9 @@
#include "titlebar.h"
#include "screen.h"
#include "layouts/floating.h"
#include "common/markup.h"
extern AwesomeConf globalconf;
static char *
titlebar_markup_parse(client_t *c, const char *str, ssize_t len)
{
const char *elements[] = { "title", NULL };
const char *elements_sub[] = { c->name , NULL };
markup_parser_data_t *p;
p = markup_parser_data_new(elements, elements_sub, countof(elements));
if(!markup_parse(p, str, len))
return a_strdup(str);
return p->text;
}
static char *
titlebar_text(client_t *c)
{
@ -58,7 +42,7 @@ titlebar_text(client_t *c)
else
text = c->titlebar.text_normal;
return titlebar_markup_parse(c, text, a_strlen(text));
return client_markup_parse(c, text, a_strlen(text));
}
static inline area_t

View file

@ -44,12 +44,7 @@ typedef struct
Showclient_t show;
bool show_icons;
alignment_t align;
struct
{
style_t normal;
style_t focus;
style_t urgent;
} styles;
char *text_normal, *text_urgent, *text_focus;
} Data;
static inline bool
@ -77,9 +72,10 @@ tasklist_draw(widget_t *widget, DrawCtx *ctx, int offset, int used)
Data *d = widget->data;
rule_t *r;
area_t area;
style_t style;
char *text;
int n = 0, i = 0, box_width = 0, icon_width = 0, box_width_rest = 0;
NetWMIcon *icon;
style_t style;
if(used >= widget->statusbar->width)
return (widget->area.width = 0);
@ -110,11 +106,22 @@ tasklist_draw(widget_t *widget, DrawCtx *ctx, int offset, int used)
icon_width = 0;
if(c->isurgent)
style = d->styles.urgent;
{
text = d->text_urgent;
style = globalconf.screens[c->screen].styles.urgent;
}
else if(globalconf.focus->client == c)
style = d->styles.focus;
{
text = d->text_focus;
style = globalconf.screens[c->screen].styles.focus;
}
else
style = d->styles.normal;
{
text = d->text_normal;
style = globalconf.screens[c->screen].styles.normal;
}
text = client_markup_parse(c, text, a_strlen(text));
if(d->show_icons)
{
@ -164,9 +171,11 @@ tasklist_draw(widget_t *widget, DrawCtx *ctx, int offset, int used)
area.width += box_width_rest;
draw_text(ctx, area, d->align,
style.font->height / 2, c->name,
style.font->height / 2, text,
style);
p_delete(&text);
if(c == globalconf.scratch.client)
{
area.x = widget->area.x + icon_width + box_width * i;
@ -263,7 +272,6 @@ tasklist_new(statusbar_t *statusbar, cfg_t *config)
widget_t *w;
Data *d;
char *buf;
cfg_t *cfg_styles;
w = p_new(widget_t, 1);
widget_common_new(w, statusbar, config);
@ -272,23 +280,9 @@ tasklist_new(statusbar_t *statusbar, cfg_t *config)
w->alignment = AlignFlex;
w->data = d = p_new(Data, 1);
cfg_styles = cfg_getsec(config, "styles");
draw_style_init(globalconf.connection, statusbar->phys_screen,
cfg_getsec(cfg_styles, "normal"),
&d->styles.normal,
&globalconf.screens[statusbar->screen].styles.normal);
draw_style_init(globalconf.connection, statusbar->phys_screen,
cfg_getsec(cfg_styles, "focus"),
&d->styles.focus,
&globalconf.screens[statusbar->screen].styles.focus);
draw_style_init(globalconf.connection, statusbar->phys_screen,
cfg_getsec(cfg_styles, "urgent"),
&d->styles.urgent,
&globalconf.screens[statusbar->screen].styles.urgent);
d->text_normal = a_strdup(cfg_getstr(config, "text_normal"));
d->text_focus = a_strdup(cfg_getstr(config, "text_focus"));
d->text_urgent = a_strdup(cfg_getstr(config, "text_urgent"));
d->align = cfg_getalignment(config, "text_align");
d->show_icons = cfg_getbool(config, "show_icons");