From 839418b524ffa8fe4fca15fcbcfa7f33cd6bb6fb Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sun, 12 Oct 2008 22:31:23 +0200 Subject: [PATCH] [Barbutton/conf] Add XPM support (#3) --- bar.c | 60 ++++++++++++++++++++++++++++++++++++++++---------------- config.c | 16 +++++++++++---- draw.c | 2 +- wmfs.h | 3 ++- wmfsrc | 36 +++++++++++++++++----------------- 5 files changed, 76 insertions(+), 41 deletions(-) diff --git a/bar.c b/bar.c index 5ccc546..1f604dc 100644 --- a/bar.c +++ b/bar.c @@ -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); diff --git a/config.c b/config.c index f11d17f..d15fb49 100644 --- a/config.c +++ b/config.c @@ -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"); } diff --git a/draw.c b/draw.c index 79e4ea9..5208aa6 100644 --- a/draw.c +++ b/draw.c @@ -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); diff --git a/wmfs.h b/wmfs.h index 07ddda4..4d17ed3 100644 --- a/wmfs.h +++ b/wmfs.h @@ -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; diff --git a/wmfsrc b/wmfsrc index 6f60f62..4bdeffd 100644 --- a/wmfsrc +++ b/wmfsrc @@ -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" } # }}} }