diff --git a/src/config.c b/src/config.c index 43a45d8..8065b9e 100644 --- a/src/config.c +++ b/src/config.c @@ -59,6 +59,8 @@ func_name_list_t tmp_func_list[] = {"tag_swap", uicb_tag_swap }, {"tag_swap_next", uicb_tag_swap_next }, {"tag_swap_prev", uicb_tag_swap_previous }, + {"tag_new", uicb_tag_new }, + {"tag_del", uicb_tag_del }, {"set_mwfact", uicb_set_mwfact }, {"set_nmaster", uicb_set_nmaster }, {"quit", uicb_quit }, diff --git a/src/infobar.c b/src/infobar.c index b3ade81..2a29481 100644 --- a/src/infobar.c +++ b/src/infobar.c @@ -278,6 +278,47 @@ infobar_draw_taglist(int sc) return; } +/** Update taglist geo + *\param sc Screen number +*/ +void +infobar_update_taglist(int sc) +{ + int i, j; + + for(i = 1, j = 0; i < conf.ntag[sc] + 1; ++i) + { + /* If the tag i does not exist yet (graphically) or need full update */ + if(!infobar[sc].tags[i] || infobar[sc].need_update) + { + infobar[sc].tags[i] = barwin_create(infobar[sc].tags_board->win, j, 0, + textw(tags[sc][i].name) + PAD, + infobar[sc].geo.height, + conf.colors.bar, conf.colors.text, False, False, conf.border.tag); + + barwin_map(infobar[sc].tags[i]); + barwin_map_subwin(infobar[sc].tags[i]); + + j += textw(tags[sc][i].name) + PAD; + + barwin_resize(infobar[sc].tags_board, j, infobar[sc].geo.height); + + continue; + } + + barwin_move(infobar[sc].tags[i], j, 0); + j += textw(tags[sc][i].name) + PAD; + barwin_resize(infobar[sc].tags[i], textw(tags[sc][i].name) + PAD, infobar[sc].geo.height); + barwin_resize(infobar[sc].tags_board, j, infobar[sc].geo.height); + } + + infobar[sc].need_update = False; + + + return; +} + + /** Destroy the InfoBar */ void diff --git a/src/structs.h b/src/structs.h index 9dcaade..b78b3f5 100644 --- a/src/structs.h +++ b/src/structs.h @@ -239,6 +239,7 @@ typedef struct XRectangle geo; int position; char *statustext; + Bool need_update; } InfoBar; /* Layout Structure */ diff --git a/src/tag.c b/src/tag.c index 92f7bb1..a45de91 100644 --- a/src/tag.c +++ b/src/tag.c @@ -306,7 +306,6 @@ tag_swap(int s, int t1, int t2) { Client *c; Tag t; - int i, j; if(t1 > conf.ntag[s] || t1 < 1 || t2 > conf.ntag[s] || t2 < 1 || t1 == t2) @@ -324,15 +323,7 @@ tag_swap(int s, int t1, int t2) c->tag = t1; } - /* Adapt tags buttons */ - for(i = 1, j = 0; i < conf.ntag[s] + 1; ++i) - { - barwin_move(infobar[s].tags[i], j, 0); - j += textw(tags[s][i].name) + PAD; - barwin_resize(infobar[s].tags[i], textw(tags[s][i].name) + PAD, infobar[s].geo.height); - barwin_resize(infobar[s].tags_board, j, infobar[s].geo.height); - } - + infobar_update_taglist(s); tag_set(t2); return; @@ -376,3 +367,98 @@ uicb_tag_swap_previous(uicb_t cmd) return; } + +/** Adding a tag + *\param s Screen number + *\param name New tag name +*/ +void +tag_new(int s, char *name) +{ + Tag t = { NULL, NULL, 0, 0, 0.65, 1, False, False, False, False, IB_Top, + layout_name_to_struct(conf.layout, "tile_right", conf.nlayout, layout_list), 0, NULL, 0 }; + + if(conf.ntag[s] + 1 > MAXTAG) + { + warnx("Too many tag: Can't create new tag"); + + return; + } + + ++conf.ntag[s]; + + tags[s][conf.ntag[s]] = t; + + tags[s][conf.ntag[s]].name = _strdup(((strlen(name)) ? name : "new tag")); + + infobar_update_taglist(s); + infobar_draw(s); + + return; +} + +/** Adding a tag + *\param cmd uicb_t type +*/ +void +uicb_tag_new(uicb_t cmd) +{ + screen_get_sel(); + + tag_new(selscreen, (char*)cmd); + + return; +} + +/** Delete a tag + *\param s Screen number + *\param tag Tag number +*/ +void +tag_delete(int s, int tag) +{ + Tag t = { 0 }; + Client *c; + int i; + + if(tag < 0 || tag > conf.ntag[s] || conf.ntag[s] == 1) + return; + + for(c = clients; c; c = c->next) + if(c->screen == s && c->tag == tag) + { + warnx("Client(s) present in this tag, can't delete it"); + + return; + } + + --conf.ntag[s]; + + tags[s][tag] = t; + infobar[s].tags[tag] = NULL; + + for(i = tag; i < conf.ntag[s] + 1; ++i) + tags[s][i] = tags[s][i + 1]; + + infobar[s].need_update = True; + infobar_update_taglist(s); + infobar_draw(s); + + tag_set(tag); + + return; +} + +/** Delete a tag + *\param cmd uicb_t type +*/ +void +uicb_tag_del(uicb_t cmd) +{ + screen_get_sel(); + + tag_delete(selscreen, ((strlen((char*)cmd)) ? atoi(cmd) : seltag[selscreen])); + + return; +} + diff --git a/src/wmfs.h b/src/wmfs.h index dc13315..232ab0e 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -146,6 +146,7 @@ void infobar_draw(int sc); void infobar_draw_layout(int sc); void infobar_draw_selbar(int sc); void infobar_draw_taglist(int sc); +void infobar_update_taglist(int sc); void infobar_destroy(void); void infobar_set_position(int pos); void uicb_infobar_togglepos(uicb_t); @@ -301,6 +302,10 @@ void tag_swap(int s, int t1, int t2); void uicb_tag_swap(uicb_t); void uicb_tag_swap_next(uicb_t); void uicb_tag_swap_previous(uicb_t); +void tag_new(int s, char *name); +void uicb_tag_new(uicb_t); +void tag_delete(int s, int tag); +void uicb_tag_del(uicb_t); /* screen.c */ int screen_count(void);