X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mod_statusbar%2Fstatusbar.c;fp=mod_statusbar%2Fstatusbar.c;h=261560c12889e4783d8cd1854cb723d591e74c1b;hb=803afbc1cd633f6c025bcd9537e9b7e9aedadd0d;hp=1568b9fcf5c354b7316c2bd8ab023008da288c27;hpb=8366314611bf30a0f31d25bf5f5023186fa87692;p=ion3.git diff --git a/mod_statusbar/statusbar.c b/mod_statusbar/statusbar.c index 1568b9f..261560c 100644 --- a/mod_statusbar/statusbar.c +++ b/mod_statusbar/statusbar.c @@ -1,7 +1,7 @@ /* * ion/mod_statusbar/statusbar.c * - * Copyright (c) Tuomo Valkonen 1999-2006. + * Copyright (c) Tuomo Valkonen 1999-2007. * * Ion is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by @@ -10,6 +10,7 @@ */ #include +#include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -42,7 +44,6 @@ static void statusbar_rearrange(WStatusBar *sb, bool rs); static void do_calc_systray_w(WStatusBar *p, WSBElem *el); static void statusbar_calc_systray_w(WStatusBar *p); - static WStatusBar *statusbars=NULL; @@ -113,15 +114,16 @@ void statusbar_deinit(WStatusBar *p) /*{{{ Content stuff */ + static void init_sbelem(WSBElem *el) { el->type=WSBELEM_NONE; - el->meter=NULL; el->text_w=0; el->text=NULL; el->max_w=0; el->tmpl=NULL; - el->attr=NULL; + el->meter=STRINGID_NONE; + el->attr=STRINGID_NONE; el->stretch=0; el->align=WSBELEM_ALIGN_CENTER; el->zeropad=0; @@ -130,6 +132,20 @@ static void init_sbelem(WSBElem *el) } +static bool gets_stringstore(ExtlTab t, const char *str, StringId *id) +{ + char *s; + + if(extl_table_gets_s(t, str, &s)){ + *id=stringstore_alloc(s); + free(s); + return (*id!=STRINGID_NONE); + } + + return FALSE; +} + + static WSBElem *get_sbelems(ExtlTab t, int *nret, int *filleridxret) { int i, n=extl_table_get_n(t); @@ -157,15 +173,20 @@ static WSBElem *get_sbelems(ExtlTab t, int *nret, int *filleridxret) if(el[i].type==WSBELEM_TEXT || el[i].type==WSBELEM_STRETCH){ extl_table_gets_s(tt, "text", &(el[i].text)); }else if(el[i].type==WSBELEM_METER){ - extl_table_gets_s(tt, "meter", &(el[i].meter)); + gets_stringstore(tt, "meter", &(el[i].meter)); extl_table_gets_s(tt, "tmpl", &(el[i].tmpl)); extl_table_gets_i(tt, "align", &(el[i].align)); extl_table_gets_i(tt, "zeropad", &(el[i].zeropad)); el[i].zeropad=maxof(el[i].zeropad, 0); }else if(el[i].type==WSBELEM_SYSTRAY){ - extl_table_gets_s(tt, "meter", &(el[i].meter)); + const char *tmp; + + gets_stringstore(tt, "meter", &(el[i].meter)); extl_table_gets_i(tt, "align", &(el[i].align)); - if(el[i].meter==NULL || strcmp(el[i].meter, "systray")==0) + + tmp=stringstore_get(el[i].meter); + + if(tmp==NULL || strcmp(tmp, "systray")==0) systrayidx=i; }else if(el[i].type==WSBELEM_FILLER){ *filleridxret=i; @@ -198,12 +219,12 @@ static void free_sbelems(WSBElem *el, int n) for(i=0; imin_height=p->natural_h; h->max_set=TRUE; - h->max_width=p->natural_w; + h->max_width=INT_MAX;/*p->natural_w;*/ h->max_height=p->natural_h; } @@ -354,17 +375,22 @@ static WSBElem *statusbar_associate_systray(WStatusBar *sb, WRegion *reg) extl_table_gets_s(cwin->proptab, "statusbar", &name); for(i=0; inelems; i++){ + const char *meter; + if(sb->elems[i].type!=WSBELEM_SYSTRAY) continue; - if(sb->elems[i].meter==NULL){ + + meter=stringstore_get(sb->elems[i].meter); + + if(meter==NULL){ fbel=&sb->elems[i]; continue; } - if(name!=NULL && strcmp(sb->elems[i].meter, name)==0){ + if(name!=NULL && strcmp(meter, name)==0){ el=&sb->elems[i]; break; } - if(strcmp(sb->elems[i].meter, "systray")==0) + if(strcmp(meter, "systray")==0) fbel=&sb->elems[i]; } @@ -721,7 +747,7 @@ ExtlTab statusbar_get_template_table(WStatusBar *sb) extl_table_sets_i(tt, "type", sb->elems[i].type); extl_table_sets_s(tt, "text", sb->elems[i].text); - extl_table_sets_s(tt, "meter", sb->elems[i].meter); + extl_table_sets_s(tt, "meter", stringstore_get(sb->elems[i].meter)); extl_table_sets_s(tt, "tmpl", sb->elems[i].tmpl); extl_table_sets_i(tt, "align", sb->elems[i].align); extl_table_sets_i(tt, "zeropad", sb->elems[i].zeropad); @@ -844,6 +870,8 @@ void statusbar_update(WStatusBar *sb, ExtlTab t) return; for(i=0; inelems; i++){ + const char *meter; + el=&(sb->elems[i]); if(el->type!=WSBELEM_METER) @@ -854,16 +882,18 @@ void statusbar_update(WStatusBar *sb, ExtlTab t) el->text=NULL; } - if(el->attr!=NULL){ - free(el->attr); - el->attr=NULL; + if(el->attr!=GRATTR_NONE){ + stringstore_free(el->attr); + el->attr=GRATTR_NONE; } - if(el->meter!=NULL){ + meter=stringstore_get(el->meter); + + if(meter!=NULL){ const char *str; char *attrnm; - extl_table_gets_s(t, el->meter, &(el->text)); + extl_table_gets_s(t, meter, &(el->text)); if(el->text==NULL){ str=STATUSBAR_NX_STR; @@ -900,9 +930,13 @@ void statusbar_update(WStatusBar *sb, ExtlTab t) grow=TRUE; } - attrnm=scat(el->meter, "_hint"); + attrnm=scat(meter, "_hint"); if(attrnm!=NULL){ - extl_table_gets_s(t, attrnm, &(el->attr)); + char *s; + if(extl_table_gets_s(t, attrnm, &s)){ + el->attr=stringstore_alloc(s); + free(s); + } free(attrnm); } }