Add tag_new & tag_del uicb (Dynamic tagging)
This commit is contained in:
parent
688dfb34d2
commit
65c8c7a5ce
@ -38,6 +38,8 @@ static const struct { char *name; void (*func)(Uicb cmd); } uicb_list[] =
|
|||||||
{ "tag_move_client_next", uicb_tag_move_client_next },
|
{ "tag_move_client_next", uicb_tag_move_client_next },
|
||||||
{ "tag_move_client_prev", uicb_tag_move_client_prev },
|
{ "tag_move_client_prev", uicb_tag_move_client_prev },
|
||||||
{ "tag_click", uicb_tag_click },
|
{ "tag_click", uicb_tag_click },
|
||||||
|
{ "tag_new", uicb_tag_new },
|
||||||
|
{ "tag_del", uicb_tag_del },
|
||||||
|
|
||||||
/* Layout */
|
/* Layout */
|
||||||
{ "layout_vmirror", uicb_layout_vmirror },
|
{ "layout_vmirror", uicb_layout_vmirror },
|
||||||
|
|||||||
@ -12,6 +12,14 @@
|
|||||||
#include "status.h"
|
#include "status.h"
|
||||||
#include "systray.h"
|
#include "systray.h"
|
||||||
|
|
||||||
|
#define ELEM_FREE_BARWIN(e) \
|
||||||
|
while(!SLIST_EMPTY(&e->bars)) \
|
||||||
|
{ \
|
||||||
|
b = SLIST_FIRST(&e->bars); \
|
||||||
|
SLIST_REMOVE_HEAD(&e->bars, enext); \
|
||||||
|
barwin_remove(b); \
|
||||||
|
}
|
||||||
|
|
||||||
static void infobar_elem_tag_init(struct element *e);
|
static void infobar_elem_tag_init(struct element *e);
|
||||||
static void infobar_elem_tag_update(struct element *e);
|
static void infobar_elem_tag_update(struct element *e);
|
||||||
static void infobar_elem_status_init(struct element *e);
|
static void infobar_elem_status_init(struct element *e);
|
||||||
@ -54,8 +62,15 @@ infobar_elem_tag_init(struct element *e)
|
|||||||
|
|
||||||
e->statusctx = &e->infobar->theme->tags_n_sl;
|
e->statusctx = &e->infobar->theme->tags_n_sl;
|
||||||
|
|
||||||
if(SLIST_EMPTY(&e->bars))
|
if(SLIST_EMPTY(&e->bars) || (e->infobar->screen->flags & SCREEN_TAG_UPDATE))
|
||||||
{
|
{
|
||||||
|
if((e->infobar->screen->flags & SCREEN_TAG_UPDATE))
|
||||||
|
{
|
||||||
|
ELEM_FREE_BARWIN(e);
|
||||||
|
SLIST_INIT(&e->bars);
|
||||||
|
e->infobar->screen->flags ^= SCREEN_TAG_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
TAILQ_FOREACH(t, &e->infobar->screen->tags, next)
|
TAILQ_FOREACH(t, &e->infobar->screen->tags, next)
|
||||||
{
|
{
|
||||||
s = draw_textw(e->infobar->theme, t->name) + PAD;
|
s = draw_textw(e->infobar->theme, t->name) + PAD;
|
||||||
@ -380,12 +395,7 @@ infobar_elem_remove(struct element *e)
|
|||||||
|
|
||||||
TAILQ_REMOVE(&e->infobar->elements, e, next);
|
TAILQ_REMOVE(&e->infobar->elements, e, next);
|
||||||
|
|
||||||
while(!SLIST_EMPTY(&e->bars))
|
ELEM_FREE_BARWIN(e);
|
||||||
{
|
|
||||||
b = SLIST_FIRST(&e->bars);
|
|
||||||
SLIST_REMOVE_HEAD(&e->bars, enext);
|
|
||||||
barwin_remove(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(e);
|
free(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ screen_new(struct geo *g, int id)
|
|||||||
s->geo = s->ugeo = *g;
|
s->geo = s->ugeo = *g;
|
||||||
s->seltag = NULL;
|
s->seltag = NULL;
|
||||||
s->id = id;
|
s->id = id;
|
||||||
|
s->flags = 0;
|
||||||
|
|
||||||
TAILQ_INIT(&s->tags);
|
TAILQ_INIT(&s->tags);
|
||||||
SLIST_INIT(&s->infobars);
|
SLIST_INIT(&s->infobars);
|
||||||
|
|||||||
46
src/tag.c
46
src/tag.c
@ -22,7 +22,6 @@ tag_new(struct screen *s, char *name)
|
|||||||
t = xcalloc(1, sizeof(struct tag));
|
t = xcalloc(1, sizeof(struct tag));
|
||||||
|
|
||||||
t->screen = s;
|
t->screen = s;
|
||||||
t->name = xstrdup(name);
|
|
||||||
t->flags = 0;
|
t->flags = 0;
|
||||||
t->id = 0;
|
t->id = 0;
|
||||||
t->sel = NULL;
|
t->sel = NULL;
|
||||||
@ -31,6 +30,11 @@ tag_new(struct screen *s, char *name)
|
|||||||
if((l = TAILQ_LAST(&s->tags, tsub)))
|
if((l = TAILQ_LAST(&s->tags, tsub)))
|
||||||
t->id = l->id + 1;
|
t->id = l->id + 1;
|
||||||
|
|
||||||
|
if(!strlen(name))
|
||||||
|
xasprintf(&t->name, "%d", t->id + 1);
|
||||||
|
else
|
||||||
|
t->name = xstrdup(name);
|
||||||
|
|
||||||
SLIST_INIT(&t->clients);
|
SLIST_INIT(&t->clients);
|
||||||
TAILQ_INIT(&t->sets);
|
TAILQ_INIT(&t->sets);
|
||||||
|
|
||||||
@ -219,6 +223,8 @@ uicb_tag_click(Uicb cmd)
|
|||||||
static void
|
static void
|
||||||
tag_remove(struct tag *t)
|
tag_remove(struct tag *t)
|
||||||
{
|
{
|
||||||
|
TAILQ_REMOVE(&t->screen->tags, t, next);
|
||||||
|
|
||||||
free(t->name);
|
free(t->name);
|
||||||
|
|
||||||
layout_free_set(t);
|
layout_free_set(t);
|
||||||
@ -226,14 +232,46 @@ tag_remove(struct tag *t)
|
|||||||
free(t);
|
free(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
uicb_tag_new(Uicb cmd)
|
||||||
|
{
|
||||||
|
struct screen *s = W->screen;
|
||||||
|
struct infobar *i;
|
||||||
|
|
||||||
|
tag_new(s, (char*)cmd);
|
||||||
|
|
||||||
|
s->flags |= SCREEN_TAG_UPDATE;
|
||||||
|
|
||||||
|
SLIST_FOREACH(i, &s->infobars, next)
|
||||||
|
infobar_elem_reinit(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
uicb_tag_del(Uicb cmd)
|
||||||
|
{
|
||||||
|
struct infobar *i;
|
||||||
|
struct tag *t = W->screen->seltag;
|
||||||
|
(void)cmd;
|
||||||
|
|
||||||
|
if(SLIST_EMPTY(&t->clients)
|
||||||
|
&& TAILQ_NEXT(TAILQ_FIRST(&W->screen->tags), next))
|
||||||
|
{
|
||||||
|
|
||||||
|
tag_screen(W->screen, TAILQ_NEXT(t, next));
|
||||||
|
tag_remove(t);
|
||||||
|
|
||||||
|
W->screen->flags |= SCREEN_TAG_UPDATE;
|
||||||
|
|
||||||
|
SLIST_FOREACH(i, &W->screen->infobars, next)
|
||||||
|
infobar_elem_reinit(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tag_free(struct screen *s)
|
tag_free(struct screen *s)
|
||||||
{
|
{
|
||||||
struct tag *t;
|
struct tag *t;
|
||||||
|
|
||||||
TAILQ_FOREACH(t, &s->tags, next)
|
TAILQ_FOREACH(t, &s->tags, next)
|
||||||
{
|
|
||||||
TAILQ_REMOVE(&s->tags, t, next);
|
|
||||||
tag_remove(t);
|
tag_remove(t);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,5 +32,7 @@ void uicb_tag_client(Uicb cmd);
|
|||||||
void uicb_tag_move_client_next(Uicb cmd);
|
void uicb_tag_move_client_next(Uicb cmd);
|
||||||
void uicb_tag_move_client_prev(Uicb cmd);
|
void uicb_tag_move_client_prev(Uicb cmd);
|
||||||
void uicb_tag_click(Uicb cmd);
|
void uicb_tag_click(Uicb cmd);
|
||||||
|
void uicb_tag_new(Uicb cmd);
|
||||||
|
void uicb_tag_del(Uicb cmd);
|
||||||
|
|
||||||
#endif /* TAG_H */
|
#endif /* TAG_H */
|
||||||
|
|||||||
@ -149,6 +149,8 @@ struct screen
|
|||||||
{
|
{
|
||||||
struct geo geo, ugeo;
|
struct geo geo, ugeo;
|
||||||
struct tag *seltag;
|
struct tag *seltag;
|
||||||
|
#define SCREEN_TAG_UPDATE 0x01
|
||||||
|
Flags flags;
|
||||||
int id;
|
int id;
|
||||||
TAILQ_HEAD(tsub, tag) tags;
|
TAILQ_HEAD(tsub, tag) tags;
|
||||||
SLIST_HEAD(, infobar) infobars;
|
SLIST_HEAD(, infobar) infobars;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user