diff --git a/client.c b/client.c index 28fbc4021..c4c2cec2e 100644 --- a/client.c +++ b/client.c @@ -227,8 +227,8 @@ void focus(Display *disp, DC *drawcontext, Client * c, jdwm_config *jdwmconf) { /* if c is NULL or invisible, take next client in the stack */ - if((!c && selscreen) || (c && !isvisible(c, jdwmconf->ntags))) - for(c = stack; c && !isvisible(c, jdwmconf->ntags); c = c->snext); + if((!c && selscreen) || (c && !isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags))) + for(c = stack; c && !isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags); c = c->snext); /* if a client was selected but it's not the current client, unfocus it */ if(sel && sel != c) diff --git a/config.c b/config.c index f5c9d288f..8d2576683 100644 --- a/config.c +++ b/config.c @@ -151,6 +151,7 @@ uicb_reload(Display *disp, jdwm_config *jdwmconf, const char *arg __attribute__ config_destroy(&jdwmlibconf); p_delete(&jdwmconf->rules); p_delete(&jdwmconf->tags); + p_delete(&jdwmconf->selected_tags); p_delete(&jdwmconf->layouts); parse_config(disp, screen, &dc, jdwmconf); } @@ -199,8 +200,16 @@ parse_config(Display * disp, int scr, DC * drawcontext, jdwm_config *jdwmconf) jdwmconf->ntags = config_setting_length(conftags); jdwmconf->tags = p_new(const char *, jdwmconf->ntags); + jdwmconf->selected_tags = p_new(Bool, jdwmconf->ntags); + for(i = 0; (tmp = config_setting_get_string_elem(conftags, i)); i++) + { jdwmconf->tags[i] = tmp; + jdwmconf->selected_tags[i] = False; + } + + /* select first tag by default */ + jdwmconf->selected_tags[0] = True; /* layouts */ conflayouts = config_lookup(&jdwmlibconf, "jdwm.layouts"); diff --git a/config.h b/config.h index abc4a846a..f2e229660 100644 --- a/config.h +++ b/config.h @@ -59,6 +59,8 @@ struct jdwm_config { /** Tag list */ const char **tags; + /** Selected tags */ + Bool *selected_tags; /** Number of tags in **tags */ int ntags; /** Layout list */ diff --git a/draw.c b/draw.c index a393514ec..30f304e47 100644 --- a/draw.c +++ b/draw.c @@ -9,7 +9,6 @@ extern int bh, blw; /* bar height, bar layout label width */ extern Window barwin; extern DC dc; /* global draw context */ extern Client *clients, *sel, *stack; /* global client list and stack */ -extern Bool *seltags; /* static */ @@ -118,7 +117,7 @@ drawstatus(Display *disp, jdwm_config * jdwmconf) for(i = 0; i < jdwmconf->ntags; i++) { dc.w = textw(jdwmconf->tags[i]); - if(seltags[i]) + if(jdwmconf->selected_tags[i]) { drawtext(disp, jdwmconf->tags[i], dc.sel); drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel, disp); diff --git a/event.c b/event.c index 1dd3b0385..aaeec146f 100644 --- a/event.c +++ b/event.c @@ -212,7 +212,7 @@ handle_event_configurerequest(XEvent * e, jdwm_config *jdwmconf __attribute__ (( c->y = sh / 2 - c->h / 2; /* center in y direction */ if((ev->value_mask & (CWX | CWY)) && !(ev->value_mask & (CWWidth | CWHeight))) configure(c); - if(isvisible(c, jdwmconf->ntags)) + if(isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags)) XMoveResizeWindow(e->xany.display, c->win, c->x, c->y, c->w, c->h); } else diff --git a/jdwm.c b/jdwm.c index af54e60e5..30dc3f281 100644 --- a/jdwm.c +++ b/jdwm.c @@ -25,7 +25,7 @@ extern void (*handler[LASTEvent]) (XEvent *, jdwm_config *); /* event handler int screen, sx, sy, sw, sh, wax, way, waw, wah; int bh; Atom jdwmprops, wmatom[WMLast], netatom[NetLast]; -Bool *seltags, *prevtags;; +Bool *prevtags;; Bool selscreen = True; Client *clients = NULL; Client *sel = NULL; @@ -98,7 +98,6 @@ cleanup(Display *disp, jdwm_config *jdwmconf) XFreeCursor(disp, cursor[CurMove]); XSetInputFocus(disp, PointerRoot, RevertToPointerRoot, CurrentTime); XSync(disp, False); - p_delete(&seltags); p_delete(&prevtags); p_delete(&taglayouts); } @@ -181,8 +180,6 @@ setup(Display *disp, jdwm_config *jdwmconf) XSelectInput(disp, DefaultRootWindow(disp), wa.event_mask); grabkeys(disp, jdwmconf); compileregs(jdwmconf); - seltags = p_new(Bool, jdwmconf->ntags); - seltags[0] = True; prevtags = p_new(Bool, jdwmconf->ntags); prevtags[0] = True; /* geometry */ diff --git a/layout.c b/layout.c index 94dbcc861..90385da99 100644 --- a/layout.c +++ b/layout.c @@ -22,7 +22,6 @@ extern Layout ** taglayouts; extern int wax, way, wah, waw; /* windowarea geometry */ extern Window barwin; extern Client *clients, *sel; /* global client list */ -extern Bool *seltags; extern Atom jdwmprops; extern DC dc; @@ -32,7 +31,7 @@ arrange(Display * disp, jdwm_config *jdwmconf) Client *c; for(c = clients; c; c = c->next) - if(isvisible(c, jdwmconf->ntags)) + if(isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags)) unban(c); else ban(c); @@ -50,9 +49,9 @@ uicb_focusnext(Display *disp __attribute__ ((unused)), if(!sel) return; - for(c = sel->next; c && !isvisible(c, jdwmconf->ntags); c = c->next); + for(c = sel->next; c && !isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags); c = c->next); if(!c) - for(c = clients; c && !isvisible(c, jdwmconf->ntags); c = c->next); + for(c = clients; c && !isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags); c = c->next); if(c) { focus(c->display, &dc, c, jdwmconf); @@ -69,11 +68,11 @@ uicb_focusprev(Display *disp __attribute__ ((unused)), if(!sel) return; - for(c = sel->prev; c && !isvisible(c, jdwmconf->ntags); c = c->prev); + for(c = sel->prev; c && !isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags); c = c->prev); if(!c) { for(c = clients; c && c->next; c = c->next); - for(; c && !isvisible(c, jdwmconf->ntags); c = c->prev); + for(; c && !isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags); c = c->prev); } if(c) { @@ -107,14 +106,14 @@ loadjdwmprops(Display *disp, jdwm_config * jdwmconf) if(gettextprop(disp, DefaultRootWindow(disp), jdwmprops, prop, sizeof(prop))) { for(i = 0; i < jdwmconf->ntags && i < ssizeof(prop) - 1 && prop[i] != '\0'; i++) - seltags[i] = prop[i] == '1'; + jdwmconf->selected_tags[i] = prop[i] == '1'; } } inline Client * -nexttiled(Client * c, int ntags) +nexttiled(Client * c, Bool * tags, int ntags) { - for(; c && (c->isfloating || !isvisible(c, ntags)); c = c->next); + for(; c && (c->isfloating || !isvisible(c, tags, ntags)); c = c->next); return c; } @@ -139,7 +138,7 @@ restack(Display * disp, jdwm_config *jdwmconf) XConfigureWindow(disp, sel->win, CWSibling | CWStackMode, &wc); wc.sibling = sel->win; } - for(c = nexttiled(clients, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->ntags)) + for(c = nexttiled(clients, jdwmconf->selected_tags, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->selected_tags, jdwmconf->ntags)) { if(c == sel) continue; @@ -156,7 +155,7 @@ savejdwmprops(Display *disp, jdwm_config *jdwmconf) { int i; for(i = 0; i < jdwmconf->ntags && i < ssizeof(prop) - 1; i++) - prop[i] = seltags[i] ? '1' : '0'; + prop[i] = jdwmconf->selected_tags[i] ? '1' : '0'; prop[i] = '\0'; XChangeProperty(disp, DefaultRootWindow(disp), jdwmprops, XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i); } @@ -191,7 +190,7 @@ uicb_setlayout(Display *disp, jdwm_config * jdwmconf, const char *arg) savejdwmprops(disp, jdwmconf); for(j = 0; j < jdwmconf->ntags; j++) - if (seltags[j]) + if (jdwmconf->selected_tags[j]) taglayouts[j] = jdwmconf->current_layout; } @@ -269,7 +268,7 @@ uicb_zoom(Display *disp __attribute__ ((unused)), const char *arg __attribute__ ((unused))) { Client *c; - if(!sel || ((c = sel) == nexttiled(clients, jdwmconf->ntags) && !(c = nexttiled(c->next, jdwmconf->ntags)))) + if(!sel || ((c = sel) == nexttiled(clients, jdwmconf->selected_tags, jdwmconf->ntags) && !(c = nexttiled(c->next, jdwmconf->selected_tags, jdwmconf->ntags)))) return; detach(c); attach(c); diff --git a/layout.h b/layout.h index 223677d4d..7ee4407e9 100644 --- a/layout.h +++ b/layout.h @@ -9,7 +9,7 @@ void arrange(Display *, jdwm_config *); /* arranges all windows depending on the layout in use */ void initlayouts(jdwm_config *); /* initialize layout array */ -Client *nexttiled(Client *, int); /* returns tiled successor of c */ +Client *nexttiled(Client *, Bool *, int); /* returns tiled successor of c */ void restack(Display *, jdwm_config *); /* restores z layers of all clients */ void uicb_focusnext(Display *, jdwm_config *, const char *); /* focuses next visible client */ void uicb_focusprev(Display *, jdwm_config *, const char *); /* focuses prev visible client */ diff --git a/layouts/floating.c b/layouts/floating.c index 4183a5987..dc772a76d 100644 --- a/layouts/floating.c +++ b/layouts/floating.c @@ -12,7 +12,7 @@ floating(Display *disp __attribute__ ((unused)), jdwm_config *jdwmconf) Client *c; for(c = clients; c; c = c->next) - if(isvisible(c, jdwmconf->ntags)) + if(isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags)) { if(c->ftview) { diff --git a/layouts/grid.c b/layouts/grid.c index cfc8b886c..8119d3050 100644 --- a/layouts/grid.c +++ b/layouts/grid.c @@ -15,7 +15,7 @@ grid(Display *disp, jdwm_config *jdwmconf) unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows; Client *c; - for(n = 0, c = nexttiled(clients, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->ntags)) + for(n = 0, c = nexttiled(clients, jdwmconf->selected_tags, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->selected_tags, jdwmconf->ntags)) n++; /* grid dimensions */ @@ -29,7 +29,7 @@ grid(Display *disp, jdwm_config *jdwmconf) cw = waw / (cols ? cols : 1); for(i = 0, c = clients; c; c = c->next) - if(isvisible(c, jdwmconf->ntags)) + if(isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags)) { unban(c); if(c->isfloating) diff --git a/layouts/spiral.c b/layouts/spiral.c index 0bb132330..1e3638a97 100644 --- a/layouts/spiral.c +++ b/layouts/spiral.c @@ -18,7 +18,7 @@ fibonacci(Display *disp, jdwm_config *jdwmconf, int shape) ny = 0; nw = waw; nh = wah; - for(n = 0, c = nexttiled(clients, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->ntags)) + for(n = 0, c = nexttiled(clients, jdwmconf->selected_tags, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->selected_tags, jdwmconf->ntags)) n++; for(i = 0, c = clients; c; c = c->next) { diff --git a/layouts/tile.c b/layouts/tile.c index 4cd3902df..cdf23e54c 100644 --- a/layouts/tile.c +++ b/layouts/tile.c @@ -76,7 +76,7 @@ _tile(jdwm_config *jdwmconf, const Bool right) int n, th, i, mh; Client *c; - for(n = 0, c = nexttiled(clients, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->ntags)) + for(n = 0, c = nexttiled(clients, jdwmconf->selected_tags, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->selected_tags, jdwmconf->ntags)) n++; /* window geoms */ @@ -88,7 +88,7 @@ _tile(jdwm_config *jdwmconf, const Bool right) nx = wax; ny = way; - for(i = 0, c = nexttiled(clients, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->ntags), i++) + for(i = 0, c = nexttiled(clients, jdwmconf->selected_tags, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->selected_tags, jdwmconf->ntags), i++) { c->ismax = False; if(i < nmaster) @@ -143,7 +143,7 @@ _bstack(jdwm_config *jdwmconf, Bool portrait) int i, n, nx, ny, nw, nh, mw, mh, tw, th; Client *c; - for(n = 0, c = nexttiled(clients, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->ntags)) + for(n = 0, c = nexttiled(clients, jdwmconf->selected_tags, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->selected_tags, jdwmconf->ntags)) n++; /* window geoms */ @@ -152,7 +152,7 @@ _bstack(jdwm_config *jdwmconf, Bool portrait) th = (n > nmaster) ? (wah * (1 - mwfact)) / (portrait ? 1 : n - nmaster) : 0; tw = (n > nmaster) ? waw / (portrait ? n - nmaster : 1) : 0; - for(i = 0, c = nexttiled(clients, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->ntags), i++) + for(i = 0, c = nexttiled(clients, jdwmconf->selected_tags, jdwmconf->ntags); c; c = nexttiled(c->next, jdwmconf->selected_tags, jdwmconf->ntags), i++) { c->ismax = False; nx = wax; diff --git a/tag.c b/tag.c index cf299c830..479896c2b 100644 --- a/tag.c +++ b/tag.c @@ -10,7 +10,7 @@ #include "tag.h" extern Client *sel; /* global client list */ -extern Bool *seltags, *prevtags; +extern Bool *prevtags; extern Layout ** taglayouts; static Regs *regs = NULL; @@ -65,7 +65,7 @@ applyrules(Client * c, jdwm_config *jdwmconf) XFree(ch.res_name); if(!matched) for(i = 0; i < jdwmconf->ntags; i++) - c->tags[i] = seltags[i]; + c->tags[i] = jdwmconf->selected_tags[i]; } void @@ -99,18 +99,20 @@ compileregs(jdwm_config * jdwmconf) } -/** Returns True if a client is visible on - * one of the currently selected tag, false otherwise. +/** Returns True if a client is tagged + * with one of the tags * \param c Client + * \param tags tag to check + * \param ntags number of tags in *tags * \return True or False */ Bool -isvisible(Client * c, int ntags) +isvisible(Client * c, Bool * tags, int ntags) { int i; for(i = 0; i < ntags; i++) - if(c->tags[i] && seltags[i]) + if(c->tags[i] && tags[i]) return True; return False; } @@ -203,10 +205,10 @@ uicb_toggleview(Display *disp, int j; i = idxoftag(arg, jdwmconf->tags, jdwmconf->ntags); - seltags[i] = !seltags[i]; - for(j = 0; j < jdwmconf->ntags && !seltags[j]; j++); + jdwmconf->selected_tags[i] = !jdwmconf->selected_tags[i]; + for(j = 0; j < jdwmconf->ntags && !jdwmconf->selected_tags[j]; j++); if(j == jdwmconf->ntags) - seltags[i] = True; /* cannot toggle last view */ + jdwmconf->selected_tags[i] = True; /* cannot toggle last view */ savejdwmprops(disp, jdwmconf); arrange(disp, jdwmconf); } @@ -225,13 +227,13 @@ uicb_view(Display *disp, for(i = 0; i < jdwmconf->ntags; i++) { - prevtags[i] = seltags[i]; - seltags[i] = arg == NULL; + prevtags[i] = jdwmconf->selected_tags[i]; + jdwmconf->selected_tags[i] = arg == NULL; } i = idxoftag(arg, jdwmconf->tags, jdwmconf->ntags); if(i >= 0 && i < jdwmconf->ntags) { - seltags[i] = True; + jdwmconf->selected_tags[i] = True; jdwmconf->current_layout = taglayouts[i]; } savejdwmprops(disp, jdwmconf); @@ -253,8 +255,8 @@ uicb_viewprevtags(Display * disp, for(i = 0; i < jdwmconf->ntags; i++) { - t = seltags[i]; - seltags[i] = prevtags[i]; + t = jdwmconf->selected_tags[i]; + jdwmconf->selected_tags[i] = prevtags[i]; prevtags[i] = t; } arrange(disp, jdwmconf); @@ -275,13 +277,13 @@ uicb_tag_viewnext(Display *disp, for(i = 0; i < jdwmconf->ntags; i++) { - if(firsttag < 0 && seltags[i]) + if(firsttag < 0 && jdwmconf->selected_tags[i]) firsttag = i; - seltags[i] = False; + jdwmconf->selected_tags[i] = False; } if(++firsttag >= jdwmconf->ntags) firsttag = 0; - seltags[firsttag] = True; + jdwmconf->selected_tags[firsttag] = True; savejdwmprops(disp, jdwmconf); arrange(disp, jdwmconf); } @@ -301,13 +303,13 @@ uicb_tag_viewprev(Display *disp, for(i = jdwmconf->ntags - 1; i >= 0; i--) { - if(firsttag < 0 && seltags[i]) + if(firsttag < 0 && jdwmconf->selected_tags[i]) firsttag = i; - seltags[i] = False; + jdwmconf->selected_tags[i] = False; } if(--firsttag < 0) firsttag = jdwmconf->ntags - 1; - seltags[firsttag] = True; + jdwmconf->selected_tags[firsttag] = True; savejdwmprops(disp, jdwmconf); arrange(disp, jdwmconf); } diff --git a/tag.h b/tag.h index b451b6125..b51db4928 100644 --- a/tag.h +++ b/tag.h @@ -7,7 +7,7 @@ #include "client.h" void compileregs(jdwm_config *); /* initialize regexps of rules defined in config.h */ -Bool isvisible(Client *, int); /* returns True if client is visible */ +Bool isvisible(Client *, Bool *, int); void applyrules(Client * c, jdwm_config *); /* applies rules to c */ void uicb_tag(Display *, jdwm_config *, const char *); /* tags sel with arg's index */ void uicb_togglefloating(Display *, jdwm_config *, const char *); /* toggles sel between floating/tiled state */