[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

40
bar.c
View File

@ -147,9 +147,10 @@ updatebar(void)
void void
updatebutton(Bool c) updatebutton(Bool c)
{ {
int i, j, x, pm = 0; int i, j, x, pm = 0, buttonw = 0;
int y = 0, hi = 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; j = taglen[conf.ntag] + get_image_attribute(tags[seltag].layout.image)->width + PAD / 2;
if(!conf.bartop) if(!conf.bartop)
@ -159,31 +160,56 @@ updatebutton(Bool c)
hi = -1; hi = -1;
for(i = 0; i < conf.nbutton; ++i) for(i = 0; i < conf.nbutton; ++i)
{
/* CALCUL POSITION */
{ {
if(!(x = conf.barbutton[i].x)) if(!(x = conf.barbutton[i].x))
{ {
if(i) if(i)
pm += textw(conf.barbutton[i-1].text) + BPAD; 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; x = (!i) ? j : j + pm;
} }
buttonw = (conf.barbutton[i].type) ?
get_image_attribute(conf.barbutton[i].content)->width :
textw(conf.barbutton[i].content) + BPAD;
}
/* FIRST TIME */
{
if(!c) if(!c)
{ {
conf.barbutton[i].bw = bar_create(x, y, textw(conf.barbutton[i].text) + BPAD, conf.barbutton[i].bw = bar_create(x, y, buttonw, barheight + hi, 0,
barheight + hi, 0,
conf.barbutton[i].bg_color, False); conf.barbutton[i].bg_color, False);
XMapRaised(dpy, conf.barbutton[i].bw->win); XMapRaised(dpy, conf.barbutton[i].bw->win);
} }
}
/* REFRESH/DRAW TEXT/IMAGE */
{
if(!conf.barbutton[i].bw) if(!conf.barbutton[i].bw)
return; return;
if(!conf.barbutton[i].type)
bar_refresh_color(conf.barbutton[i].bw); bar_refresh_color(conf.barbutton[i].bw);
bar_moveresize(conf.barbutton[i].bw, x, y, textw(conf.barbutton[i].text) + BPAD, barheight + hi); bar_moveresize(conf.barbutton[i].bw, x, y, buttonw, barheight + hi);
/* 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, 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); conf.barbutton[i].bg_color, BPAD, conf.barbutton[i].content);
/* Refresh button */
bar_refresh(conf.barbutton[i].bw); bar_refresh(conf.barbutton[i].bw);
} }
}
XSync(dpy, False); XSync(dpy, False);
return; return;

View File

@ -243,7 +243,8 @@ init_conf(void)
static cfg_opt_t button_opts[] = 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_SEC("mouse", mouse_button_opts, CFGF_MULTI),
CFG_STR("fg_color", "#000000", CFGF_NONE), CFG_STR("fg_color", "#000000", CFGF_NONE),
CFG_STR("bg_color", "#FFFFFF", 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].mouse[j] = char_to_button(cfg_getstr(cfgtmp3, "button"));
} }
conf.barbutton[i].nmousesec = cfg_size(cfgtmp2, "mouse"); conf.barbutton[i].nmousesec = cfg_size(cfgtmp2, "mouse");
conf.barbutton[i].text = strdup(var_to_str(cfg_getstr(cfgtmp2, "text"))); 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].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].bg_color = getcolor(strdup(var_to_str(cfg_getstr(cfgtmp2, "bg_color"))));
}
conf.barbutton[i].x = cfg_getint(cfgtmp2, "x"); 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); bar_moveresize(layoutsym, x, y, get_image_attribute(tags[seltag].layout.image)->width, barheight-1);
draw_image(layoutsym->dr, 0, 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); tags[seltag].layout.image);
bar_refresh(layoutsym); bar_refresh(layoutsym);

3
wmfs.h
View File

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

18
wmfsrc
View File

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