123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- /*
- * wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
- * For license, see COPYING.
- */
- #include <X11/Xutil.h> /* IconicState / NormalState */
- #include "tag.h"
- #include "util.h"
- #include "infobar.h"
- #include "client.h"
- #include "config.h"
- #include "barwin.h"
- #include "ewmh.h"
- #include "layout.h"
- struct tag*
- tag_new(struct screen *s, char *name)
- {
- struct tag *t, *l;
- t = xcalloc(1, sizeof(struct tag));
- t->screen = s;
- t->name = xstrdup(name);
- t->flags = 0;
- t->id = 0;
- t->sel = NULL;
- t->prev = NULL;
- if((l = TAILQ_LAST(&s->tags, tsub)))
- t->id = l->id + 1;
- SLIST_INIT(&t->clients);
- TAILQ_INIT(&t->sets);
- TAILQ_INSERT_TAIL(&s->tags, t, next);
- return t;
- }
- void
- tag_screen(struct screen *s, struct tag *t)
- {
- if(t == s->seltag)
- t = t->prev;
- if(!t)
- t = TAILQ_FIRST(&s->tags);
- t->prev = s->seltag;
- s->seltag = t;
- clients_arrange_map();
- if(!SLIST_EMPTY(&t->clients) && !(W->flags & WMFS_SCAN))
- client_focus( client_tab_next(t->sel));
- infobar_elem_screen_update(s, ElemTag);
- ewmh_update_wmfs_props();
- }
- /* Set t to NULL to untag c from c->tag */
- void
- tag_client(struct tag *t, struct client *c)
- {
- /* Remove client from its previous tag */
- if(c->tag && !(c->flags & CLIENT_RULED))
- {
- if(c->tag == t)
- return;
- if(!(c->flags & CLIENT_IGNORE_LAYOUT))
- layout_split_arrange_closed(c);
- if(!(c->flags & CLIENT_REMOVEALL))
- {
- SLIST_REMOVE(&c->tag->clients, c, client, tnext);
- if(c->tag->sel == c || W->client == c)
- client_focus( client_tab_next( client_next(c)));
- }
- }
- c->flags &= ~CLIENT_RULED;
- /* Client remove */
- if(!t)
- return;
- c->prevtag = c->tag;
- c->tag = t;
- c->screen = t->screen;
- client_update_props(c, CPROP_LOC);
- /*
- * Insert in new tag list before
- * layout_split_integrate, because of set historic.
- */
- SLIST_INSERT_HEAD(&t->clients, c, tnext);
- infobar_elem_screen_update(t->screen, ElemTag);
- if(c->flags & CLIENT_IGNORE_LAYOUT)
- c->flags ^= CLIENT_IGNORE_LAYOUT;
- else if(!(c->flags & CLIENT_TABBED))
- layout_split_integrate(c, t->sel);
- if(c->flags & CLIENT_TABMASTER && c->prevtag)
- {
- struct client *cc;
- SLIST_FOREACH(cc, &c->prevtag->clients, tnext)
- if(cc->tabmaster == c)
- tag_client(t, cc);
- }
- if(t != c->screen->seltag || c->flags & CLIENT_TABBED)
- client_unmap(c);
- }
- void
- uicb_tag_set(Uicb cmd)
- {
- int i = 0, n = ATOI(cmd);
- struct tag *t;
- TAILQ_FOREACH(t, &W->screen->tags, next)
- if(i++ == n)
- {
- tag_screen(W->screen, t);
- return;
- }
- }
- void
- uicb_tag_set_with_name(Uicb cmd)
- {
- struct tag *t;
- TAILQ_FOREACH(t, &W->screen->tags, next)
- if(!strcmp(cmd, t->name))
- {
- tag_screen(W->screen, t);
- return;
- }
- }
- void
- uicb_tag_next(Uicb cmd)
- {
- (void)cmd;
- struct tag *t;
- if((t = TAILQ_NEXT(W->screen->seltag, next)))
- tag_screen(W->screen, t);
- else if( /* CIRCULAR OPTION */ 1)
- tag_screen(W->screen, TAILQ_FIRST(&W->screen->tags));
- }
- void
- uicb_tag_prev(Uicb cmd)
- {
- (void)cmd;
- struct tag *t;
- if((t = TAILQ_PREV(W->screen->seltag, tsub, next)))
- tag_screen(W->screen, t);
- else if( /* CIRCULAR OPTION */ 1)
- tag_screen(W->screen, TAILQ_LAST(&W->screen->tags, tsub));
- }
- void
- uicb_tag_client(Uicb cmd)
- {
- struct tag *t;
- int id = ATOI(cmd);
- if((t = tag_gb_id(W->screen, id)))
- tag_client(t, W->client);
- }
- void
- uicb_tag_move_client_next(Uicb cmd)
- {
- (void)cmd;
- struct tag *t;
- if((t = TAILQ_NEXT(W->screen->seltag, next)))
- tag_client(t, W->client);
- else if( /* CIRCULAR OPTION */ 1)
- tag_client(TAILQ_FIRST(&W->screen->tags), W->client);
- }
- void
- uicb_tag_move_client_prev(Uicb cmd)
- {
- (void)cmd;
- struct tag *t;
- if((t = TAILQ_PREV(W->screen->seltag, tsub, next)))
- tag_client(t, W->client);
- else if( /* CIRCULAR OPTION */ 1)
- tag_client(TAILQ_LAST(&W->screen->tags, tsub), W->client);
- }
- void
- uicb_tag_click(Uicb cmd)
- {
- (void)cmd;
- struct tag *t;
- if((t = (struct tag*)W->last_clicked_barwin->ptr)
- && t->screen == W->screen)
- tag_screen(W->screen, t);
- }
- static void
- tag_remove(struct tag *t)
- {
- free(t->name);
- layout_free_set(t);
- free(t);
- }
- void
- tag_free(struct screen *s)
- {
- struct tag *t;
- TAILQ_FOREACH(t, &s->tags, next)
- {
- TAILQ_REMOVE(&s->tags, t, next);
- tag_remove(t);
- }
- }
|