[Barbutton/conf] Add XPM support (#3)

This commit is contained in:
Martin Duquesnoy 2008-10-12 22:31:23 +02:00
parent 71f9e05187
commit 839418b524
5 changed files with 76 additions and 41 deletions

60
bar.c
View File

@ -147,9 +147,10 @@ updatebar(void)
void
updatebutton(Bool c)
{
int i, j, x, pm = 0;
int i, j, x, pm = 0, buttonw = 0;
int y = 0, hi = 0;
/* Calcul the position of the first button with the layout image size */
j = taglen[conf.ntag] + get_image_attribute(tags[seltag].layout.image)->width + PAD / 2;
if(!conf.bartop)
@ -160,29 +161,54 @@ updatebutton(Bool c)
for(i = 0; i < conf.nbutton; ++i)
{
if(!(x = conf.barbutton[i].x))
/* CALCUL POSITION */
{
if(i)
pm += textw(conf.barbutton[i-1].text) + BPAD;
x = (!i) ? j : j + pm;
if(!(x = conf.barbutton[i].x))
{
if(i)
pm += (conf.barbutton[i-1].type) ?
get_image_attribute(conf.barbutton[i-1].content)->width :
textw(conf.barbutton[i-1].content) + BPAD;
x = (!i) ? j : j + pm;
}
buttonw = (conf.barbutton[i].type) ?
get_image_attribute(conf.barbutton[i].content)->width :
textw(conf.barbutton[i].content) + BPAD;
}
if(!c)
/* FIRST TIME */
{
conf.barbutton[i].bw = bar_create(x, y, textw(conf.barbutton[i].text) + BPAD,
barheight + hi, 0,
conf.barbutton[i].bg_color, False);
XMapRaised(dpy, conf.barbutton[i].bw->win);
if(!c)
{
conf.barbutton[i].bw = bar_create(x, y, buttonw, barheight + hi, 0,
conf.barbutton[i].bg_color, False);
XMapRaised(dpy, conf.barbutton[i].bw->win);
}
}
if(!conf.barbutton[i].bw)
return;
/* REFRESH/DRAW TEXT/IMAGE */
{
if(!conf.barbutton[i].bw)
return;
if(!conf.barbutton[i].type)
bar_refresh_color(conf.barbutton[i].bw);
bar_moveresize(conf.barbutton[i].bw, x, y, buttonw, barheight + hi);
bar_refresh_color(conf.barbutton[i].bw);
bar_moveresize(conf.barbutton[i].bw, x, y, textw(conf.barbutton[i].text) + BPAD, barheight + hi);
draw_text(conf.barbutton[i].bw->dr, BPAD/2, fonth, conf.barbutton[i].fg_color,
conf.barbutton[i].bg_color, BPAD, conf.barbutton[i].text);
bar_refresh(conf.barbutton[i].bw);
/* Check the button type (image/text) */
if(conf.barbutton[i].type)
draw_image(conf.barbutton[i].bw->dr, 0, 0,
conf.barbutton[i].content);
else
draw_text(conf.barbutton[i].bw->dr, BPAD/2, fonth, conf.barbutton[i].fg_color,
conf.barbutton[i].bg_color, BPAD, conf.barbutton[i].content);
/* Refresh button */
bar_refresh(conf.barbutton[i].bw);
}
}
XSync(dpy, False);

View File

@ -243,7 +243,8 @@ init_conf(void)
static cfg_opt_t button_opts[] =
{
CFG_STR("text", "", CFGF_NONE),
CFG_STR("type", "text", CFGF_NONE),
CFG_STR("content", "", CFGF_NONE),
CFG_SEC("mouse", mouse_button_opts, CFGF_MULTI),
CFG_STR("fg_color", "#000000", CFGF_NONE),
CFG_STR("bg_color", "#FFFFFF", CFGF_NONE),
@ -464,9 +465,16 @@ init_conf(void)
conf.barbutton[i].mouse[j] = char_to_button(cfg_getstr(cfgtmp3, "button"));
}
conf.barbutton[i].nmousesec = cfg_size(cfgtmp2, "mouse");
conf.barbutton[i].text = strdup(var_to_str(cfg_getstr(cfgtmp2, "text")));
conf.barbutton[i].fg_color = strdup(var_to_str(cfg_getstr(cfgtmp2, "fg_color")));
conf.barbutton[i].bg_color = getcolor(strdup(var_to_str(cfg_getstr(cfgtmp2, "bg_color"))));
if(strcmp("image", strdup(cfg_getstr(cfgtmp2, "type"))) == 0)
conf.barbutton[i].type = True;
else
conf.barbutton[i].type = False;
conf.barbutton[i].content = strdup(var_to_str(cfg_getstr(cfgtmp2, "content")));
if(!conf.barbutton[i].type)
{
conf.barbutton[i].fg_color = strdup(var_to_str(cfg_getstr(cfgtmp2, "fg_color")));
conf.barbutton[i].bg_color = getcolor(strdup(var_to_str(cfg_getstr(cfgtmp2, "bg_color"))));
}
conf.barbutton[i].x = cfg_getint(cfgtmp2, "x");
}

2
draw.c
View File

@ -120,7 +120,7 @@ draw_layout(int x, int y)
bar_moveresize(layoutsym, x, y, get_image_attribute(tags[seltag].layout.image)->width, barheight-1);
draw_image(layoutsym->dr, 0,
(barheight)/2 - get_image_attribute(tags[seltag].layout.image)->height/2,
(barheight/2 - get_image_attribute(tags[seltag].layout.image)->height/2),
tags[seltag].layout.image);
bar_refresh(layoutsym);

3
wmfs.h
View File

@ -119,7 +119,8 @@ typedef struct
/* Bar Button */
typedef struct
{
char *text;
Bool type; /* False -> text, True -> image. */
char *content;
BarWindow *bw;
char *fg_color;
int bg_color;

36
wmfsrc
View File

@ -46,9 +46,9 @@ colors
layouts
{
layout { type = "tile" image = "/" }
layout { type = "max" image = "/" }
layout { type = "free" image = "/" }
layout { type = "tile" image = "icons/tile.xpm" }
layout { type = "max" image = "icons/max.xpm" }
layout { type = "free" image = "icons/free.xpm" }
}
tags
@ -69,41 +69,41 @@ buttons
# MWFACT BUTTON {{{
button
{
text = "[-]"
content = "[-]"
mouse { button = "Button1" func = "set_mwfact" cmd = "-0.01" }
fg_color = "#FFFFFF"
bg_color = "#191919"
}
button
{
text = "Mwfact" fg_color = "#FFFFFF" bg_color = "#3E3E3E"
content = "Mwfact" fg_color = "#FFFFFF" bg_color = "#3E3E3E"
mouse { button = "Button4" func = "set_mwfact" cmd = "+0.01" }
mouse { button = "Button5" func = "set_mwfact" cmd = "-0.01" }
}
button
{
text = "[+] "
mouse { button = "Button1" func = "set_mwfact" cmd = "+0.01" }
fg_color = "#FFFFFF"
bg_color = "#191919"
content = "[+] "
mouse { button = "Button1" func = "set_mwfact" cmd = "+0.01" }
fg_color = "#FFFFFF"
bg_color = "#191919"
}
# }}}
# NMASTER BUTTON {{{
button
{
text = "[-]"
mouse { button = "Button1" func = "set_nmaster" cmd = "-1" }
fg_color = "#FFFFFF"
bg_color = "#191919"
content = "[-]"
mouse { button = "Button1" func = "set_nmaster" cmd = "-1" }
fg_color = "#FFFFFF"
bg_color = "#191919"
}
button { text = "Nmaster" fg_color = "#FFFFFF" bg_color = "#3E3E3E" }
button { content = "Nmaster" fg_color = "#FFFFFF" bg_color = "#3E3E3E" }
button
{
text = "[+] "
mouse { button = "Button1" func = "set_nmaster" cmd = "+1" }
fg_color = "#FFFFFF"
bg_color = "#191919"
content = "[+] "
mouse { button = "Button1" func = "set_nmaster" cmd = "+1" }
fg_color = "#FFFFFF"
bg_color = "#191919"
}
# }}}
}