[wiki] [sites] [dwm][pertag-tab] Update against git HEAD || Ivan Tham

From: <git_AT_suckless.org>
Date: Sat, 31 Oct 2015 05:58:28 +0100

commit af0161698dd97f04d64c5f07ea2486fe25cf3860
Author: Ivan Tham <pickfire_AT_riseup.net>
Date: Sat Oct 31 12:58:22 2015 +0800

    [dwm][pertag-tab] Update against git HEAD

diff --git a/dwm.suckless.org/patches/dwm-7e1182c-pertag-tab.diff b/dwm.suckless.org/patches/dwm-7e1182c-pertag-tab.diff
new file mode 100644
index 0000000..aa5e9dd
--- /dev/null
+++ b/dwm.suckless.org/patches/dwm-7e1182c-pertag-tab.diff
_AT_@ -0,0 +1,692 @@
+diff --git a/config.def.h b/config.def.h
+index 3fde3cf..ef6d4d3 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -15,10 +15,22 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
+ static const unsigned int snap = 32; /* snap pixel */
+ static const Bool showbar = True; /* False means no bar */
+ static const Bool topbar = True; /* False means bottom bar */
++/* Display modes of the tab bar: never shown, always shown, shown only in */
++/* monocle mode in presence of several windows. */
++/* Modes after showtab_nmodes are disabled */
++enum showtab_modes { showtab_never, showtab_auto, showtab_nmodes, showtab_always};
++static const int showtab = showtab_auto; /* Default tab bar show mode */
++static const Bool toptab = False; /* False means bottom tab bar */
++
+
+ /* tagging */
+ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+
++/* default layout per tags */
++/* The first element is for all-tag view, following i-th element corresponds to */
++/* tags[i]. Layout is referred using the layouts array index.*/
++static int def_layouts[1 + LENGTH(tags)] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
++
+ static const Rule rules[] = {
+ /* xprop(1):
+ * WM_CLASS(STRING) = instance, class
+_AT_@ -32,7 +44,7 @@ static const Rule rules[] = {
+ /* layout(s) */
+ static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
+ static const int nmaster = 1; /* number of clients in master area */
+-static const Bool resizehints = True; /* True means respect size hints in tiled resizals */
++static const Bool resizehints = False; /* True means respect size hints in tiled resizals */
+
+ static const Layout layouts[] = {
+ /* symbol arrange function */
+_AT_@ -62,6 +74,7 @@ static Key keys[] = {
+ { MODKEY, XK_p, spawn, {.v = dmenucmd } },
+ { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
+ { MODKEY, XK_b, togglebar, {0} },
++ { MODKEY, XK_w, tabmode, {-1} },
+ { MODKEY, XK_j, focusstack, {.i = +1 } },
+ { MODKEY, XK_k, focusstack, {.i = -1 } },
+ { MODKEY, XK_i, incnmaster, {.i = +1 } },
+_AT_@ -109,5 +122,6 @@ static Button buttons[] = {
+ { ClkTagBar, 0, Button3, toggleview, {0} },
+ { ClkTagBar, MODKEY, Button1, tag, {0} },
+ { ClkTagBar, MODKEY, Button3, toggletag, {0} },
++ { ClkTabBar, 0, Button1, focuswin, {0} },
+ };
+
+diff --git a/dwm.1 b/dwm.1
+index 6687011..077d92b 100644
+--- a/dwm.1
++++ b/dwm.1
+_AT_@ -19,14 +19,22 @@ layout applied.
+ Windows are grouped by tags. Each window can be tagged with one or multiple
+ tags. Selecting certain tags displays all windows with these tags.
+ .P
+-Each screen contains a small status bar which displays all available tags, the
+-layout, the title of the focused window, and the text read from the root window
+-name property, if the screen is focused. A floating window is indicated with an
+-empty square and a maximised floating window is indicated with a filled square
+-before the windows title. The selected tags are indicated with a different
+-color. The tags of the focused window are indicated with a filled square in the
+-top left corner. The tags which are applied to one or more windows are
+-indicated with an empty square in the top left corner.
++Each screen contains two small status bars.
++.P
++One bar displays all available tags, the layout, the title of the focused
++window, and the text read from the root window name property, if the screen is
++focused. A floating window is indicated with an empty square and a maximised
++floating window is indicated with a filled square before the windows title. The
++selected tags are indicated with a different color. The tags of the focused
++window are indicated with a filled square in the top left corner. The tags
++which are applied to one or more windows are indicated with an empty square in
++the top left corner.
++.P
++Another bar contains a tab for each window of the current view and allows
++navigation between windows, especially in the monocle mode. The different
++display modes of this bar are described under the Mod1\-w Keybord command
++section. When a single tag is selected, that tag is indicated in the left corner
++of the tab bar.
+ .P
+ dwm draws a small border around windows to indicate the focus state.
+ .SH OPTIONS
+_AT_@ -43,7 +51,8 @@ command.
+ .TP
+ .B Button1
+ click on a tag label to display all windows with that tag, click on the layout
+-label toggles between tiled and floating layout.
++label toggles between tiled and floating layout, click on a window name in the
++tab bar brings focus to that window.
+ .TP
+ .B Button3
+ click on a tag label adds/removes all windows with that tag to/from the view.
+_AT_@ -104,6 +113,12 @@ Increase master area size.
+ .B Mod1\-h
+ Decrease master area size.
+ .TP
++.B Mod1\-w
++Cycle over the tab bar display modes: never displayed, always displayed,
++displayed only in monocle mode when the view contains than one window (auto
++mode). Some display modes can be disabled in the configuration, config.h. In
++the default configuration only "never" and "auto" display modes are enabled.
++.TP
+ .B Mod1\-Return
+ Zooms/cycles focused window to/from master area (tiled layouts only).
+ .TP
+diff --git a/dwm.c b/dwm.c
+index 96b43f7..c0aab5d 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -64,7 +64,7 @@ enum { NetSupported, NetWMName, NetWMState,
+ NetWMFullscreen, NetActiveWindow, NetWMWindowType,
+ NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
+ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
+-enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
++enum { ClkTagBar, ClkTabBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
+ ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
+
+ typedef union {
+_AT_@ -111,25 +111,35 @@ typedef struct {
+ void (*arrange)(Monitor *);
+ } Layout;
+
++#define MAXTABS 50
++
++typedef struct Pertag Pertag;
+ struct Monitor {
+ char ltsymbol[16];
+ float mfact;
+ int nmaster;
+ int num;
+ int by; /* bar geometry */
++ int ty; /* tab bar geometry */
+ int mx, my, mw, mh; /* screen size */
+ int wx, wy, ww, wh; /* window area */
+ unsigned int seltags;
+ unsigned int sellt;
+ unsigned int tagset[2];
+ Bool showbar;
++ Bool showtab;
+ Bool topbar;
++ Bool toptab;
+ Client *clients;
+ Client *sel;
+ Client *stack;
+ Monitor *next;
+ Window barwin;
++ Window tabwin;
++ int ntabs;
++ int tab_widths[MAXTABS];
+ const Layout *lt[2];
++ Pertag *pertag;
+ };
+
+ typedef struct {
+_AT_@ -164,12 +174,15 @@ static void detachstack(Client *c);
+ static Monitor *dirtomon(int dir);
+ static void drawbar(Monitor *m);
+ static void drawbars(void);
++static void drawtab(Monitor *m);
++static void drawtabs(void);
+ static void enternotify(XEvent *e);
+ static void expose(XEvent *e);
+ static void focus(Client *c);
+ static void focusin(XEvent *e);
+ static void focusmon(const Arg *arg);
+ static void focusstack(const Arg *arg);
++static void focuswin(const Arg* arg);
+ static Bool getrootptr(int *x, int *y);
+ static long getstate(Window w);
+ static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
+_AT_@ -206,6 +219,7 @@ static void setup(void);
+ static void showhide(Client *c);
+ static void sigchld(int unused);
+ static void spawn(const Arg *arg);
++static void tabmode(const Arg *arg);
+ static void tag(const Arg *arg);
+ static void tagmon(const Arg *arg);
+ static void tile(Monitor *);
+_AT_@ -240,6 +254,7 @@ static char stext[256];
+ static int screen;
+ static int sw, sh; /* X display screen geometry width, height */
+ static int bh, blw = 0; /* bar geometry */
++static int th = 0; /* tab bar geometry */
+ static int (*xerrorxlib)(Display *, XErrorEvent *);
+ static unsigned int numlockmask = 0;
+ static void (*handler[LASTEvent]) (XEvent *) = {
+_AT_@ -270,6 +285,16 @@ static Window root;
+ /* configuration, allows nested code to access above variables */
+ #include "config.h"
+
++struct Pertag {
++ unsigned int curtag, prevtag; /* current and previous tag */
++ int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
++ float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
++ unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
++ const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */
++ Bool showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
++ Client *prevzooms[LENGTH(tags) + 1]; /* store zoom information */
++};
++
+ /* compile-time check if all tags fit into an unsigned int bit array. */
+ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+
+_AT_@ -389,6 +414,9 @@ arrange(Monitor *m) {
+
+ void
+ arrangemon(Monitor *m) {
++ updatebarpos(m);
++ XMoveResizeWindow(dpy, m->tabwin, m->wx, m->ty, m->ww, th);
++
+ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
+ if(m->lt[m->sellt]->arrange)
+ m->lt[m->sellt]->arrange(m);
+_AT_@ -437,14 +465,32 @@ buttonpress(XEvent *e) {
+ else
+ click = ClkWinTitle;
+ }
++ if(ev->window == selmon->tabwin) {
++ i = 0; x = 0;
++ for(c = selmon->clients; c; c = c->next){
++ if(!ISVISIBLE(c)) continue;
++ x += selmon->tab_widths[i];
++ if (ev->x > x)
++ ++i;
++ else
++ break;
++ if(i >= m->ntabs) break;
++ }
++ if(c) {
++ click = ClkTabBar;
++ arg.ui = i;
++ }
++ }
+ else if((c = wintoclient(ev->window))) {
+ focus(c);
+ click = ClkClientWin;
+ }
+ for(i = 0; i < LENGTH(buttons); i++)
+ if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
+- && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
+- buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
++ && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)){
++ buttons[i].func(((click == ClkTagBar || click == ClkTabBar)
++ && buttons[i].arg.i == 0) ? &arg : &buttons[i].arg);
++ }
+ }
+
+ void
+_AT_@ -497,6 +543,8 @@ cleanupmon(Monitor *mon) {
+ }
+ XUnmapWindow(dpy, mon->barwin);
+ XDestroyWindow(dpy, mon->barwin);
++ XUnmapWindow(dpy, mon->tabwin);
++ XDestroyWindow(dpy, mon->tabwin);
+ free(mon);
+ }
+
+_AT_@ -516,6 +564,7 @@ void
+ clientmessage(XEvent *e) {
+ XClientMessageEvent *cme = &e->xclient;
+ Client *c = wintoclient(cme->window);
++ int i;
+
+ if(!c)
+ return;
+_AT_@ -528,6 +577,8 @@ clientmessage(XEvent *e) {
+ if(!ISVISIBLE(c)) {
+ c->mon->seltags ^= 1;
+ c->mon->tagset[c->mon->seltags] = c->tags;
++ for(i=0; !(c->tags & 1 << i); i++);
++ view(&(Arg){.ui = 1 << i});
+ }
+ pop(c);
+ }
+_AT_@ -565,8 +616,11 @@ configurenotify(XEvent *e) {
+ if(updategeom() || dirty) {
+ drw_resize(drw, sw, bh);
+ updatebars();
+- for(m = mons; m; m = m->next)
++ //refreshing display of status bar. The tab bar is handled by the arrange()
++ //method, which is called below
++ for(m = mons; m; m = m->next){
+ XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
++ }
+ focus(NULL);
+ arrange(NULL);
+ }
+_AT_@ -629,16 +683,41 @@ configurerequest(XEvent *e) {
+ Monitor *
+ createmon(void) {
+ Monitor *m;
++ int i;
+
+ m = ecalloc(1, sizeof(Monitor));
+ m->tagset[0] = m->tagset[1] = 1;
+ m->mfact = mfact;
+ m->nmaster = nmaster;
+ m->showbar = showbar;
++ m->showtab = showtab;
+ m->topbar = topbar;
+- m->lt[0] = &layouts[0];
++ m->toptab = toptab;
++ m->ntabs = 0;
++ m->lt[0] = &layouts[def_layouts[1] % LENGTH(layouts)];
+ m->lt[1] = &layouts[1 % LENGTH(layouts)];
+ strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
++ if(!(m->pertag = (Pertag *)calloc(1, sizeof(Pertag))))
++ die("fatal: could not malloc() %u bytes
", sizeof(Pertag));
++ m->pertag->curtag = m->pertag->prevtag = 1;
++ for(i=0; i <= LENGTH(tags); i++) {
++ /* init nmaster */
++ m->pertag->nmasters[i] = m->nmaster;
++
++ /* init mfacts */
++ m->pertag->mfacts[i] = m->mfact;
++
++ /* init layouts */
++ m->pertag->ltidxs[i][0] = &layouts[def_layouts[i % LENGTH(def_layouts)] % LENGTH(layouts)];
++ m->pertag->ltidxs[i][1] = m->lt[1];
++ m->pertag->sellts[i] = m->sellt;
++
++ /* init showbar */
++ m->pertag->showbars[i] = m->showbar;
++
++ /* swap focus and zoomswap*/
++ m->pertag->prevzooms[i] = NULL;
++ }
+ return m;
+ }
+
+_AT_@ -749,6 +828,104 @@ drawbars(void) {
+ }
+
+ void
++drawtabs(void) {
++ Monitor *m;
++
++ for(m = mons; m; m = m->next)
++ drawtab(m);
++}
++
++static int
++cmpint(const void *p1, const void *p2) {
++ /* The actual arguments to this function are "pointers to
++ pointers to char", but strcmp(3) arguments are "pointers
++ to char", hence the following cast plus dereference */
++ return *((int*) p1) > * (int*) p2;
++}
++
++
++void
++drawtab(Monitor *m) {
++ Client *c;
++ int i;
++ int itag = -1;
++ char view_info[50];
++ int view_info_w = 0;
++ int sorted_label_widths[MAXTABS];
++ int tot_width;
++ int maxsize = bh;
++ int x = 0;
++ int w = 0;
++
++ //view_info: indicate the tag which is displayed in the view
++ for(i = 0; i < LENGTH(tags); ++i){
++ if((selmon->tagset[selmon->seltags] >> i) & 1) {
++ if(itag >=0){ //more than one tag selected
++ itag = -1;
++ break;
++ }
++ itag = i;
++ }
++ }
++ if(0 <= itag && itag < LENGTH(tags)){
++ snprintf(view_info, sizeof view_info, "[%s]", tags[itag]);
++ } else {
++ strncpy(view_info, "[...]", sizeof view_info);
++ }
++ view_info[sizeof(view_info) - 1 ] = 0;
++ view_info_w = TEXTW(view_info);
++ tot_width = view_info_w;
++
++ /* Calculates number of labels and their width */
++ m->ntabs = 0;
++ for(c = m->clients; c; c = c->next){
++ if(!ISVISIBLE(c)) continue;
++ m->tab_widths[m->ntabs] = TEXTW(c->name);
++ tot_width += m->tab_widths[m->ntabs];
++ ++m->ntabs;
++ if(m->ntabs >= MAXTABS) break;
++ }
++
++ if(tot_width > m->ww){ //not enough space to display the labels, they need to be truncated
++ memcpy(sorted_label_widths, m->tab_widths, sizeof(int) * m->ntabs);
++ qsort(sorted_label_widths, m->ntabs, sizeof(int), cmpint);
++ tot_width = view_info_w;
++ for(i = 0; i < m->ntabs; ++i){
++ if(tot_width + (m->ntabs - i) * sorted_label_widths[i] > m->ww)
++ break;
++ tot_width += sorted_label_widths[i];
++ }
++ maxsize = (m->ww - tot_width) / (m->ntabs - i);
++ } else{
++ maxsize = m->ww;
++ }
++ i = 0;
++ for(c = m->clients; c; c = c->next){
++ if(!ISVISIBLE(c)) continue;
++ if(i >= m->ntabs) break;
++ if(m->tab_widths[i] > maxsize) m->tab_widths[i] = maxsize;
++ w = m->tab_widths[i];
++ drw_setscheme(drw, (c == m->sel) ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
++ drw_text(drw, x, 0, w, th, c->name, 0);
++ x += w;
++ ++i;
++ }
++
++ drw_setscheme(drw, &scheme[SchemeNorm]);
++
++ /* cleans interspace between window names and current viewed tag label */
++ w = m->ww - view_info_w - x;
++ drw_text(drw, x, 0, w, th, NULL, 0);
++
++ /* view info */
++ x += w;
++ w = view_info_w;
++ drw_text(drw, x, 0, w, th, view_info, 0);
++
++ drw_map(drw, m->tabwin, 0, 0, m->ww, th);
++}
++
++void
+ enternotify(XEvent *e) {
+ Client *c;
+ Monitor *m;
+_AT_@ -772,8 +949,10 @@ expose(XEvent *e) {
+ Monitor *m;
+ XExposeEvent *ev = &e->xexpose;
+
+- if(ev->count == 0 && (m = wintomon(ev->window)))
++ if(ev->count == 0 && (m = wintomon(ev->window))){
+ drawbar(m);
++ drawtab(m);
++ }
+ }
+
+ void
+_AT_@ -800,6 +979,7 @@ focus(Client *c) {
+ }
+ selmon->sel = c;
+ drawbars();
++ drawtabs();
+ }
+
+ void
+_AT_@ -850,6 +1030,19 @@ focusstack(const Arg *arg) {
+ }
+ }
+
++void
++focuswin(const Arg* arg){
++ int iwin = arg->i;
++ Client* c = NULL;
++ for(c = selmon->clients; c && (iwin || !ISVISIBLE(c)) ; c = c->next){
++ if(ISVISIBLE(c)) --iwin;
++ };
++ if(c) {
++ focus(c);
++ restack(selmon);
++ }
++}
++
+ Atom
+ getatomprop(Client *c, Atom prop) {
+ int di;
+_AT_@ -957,7 +1150,7 @@ grabkeys(void) {
+
+ void
+ incnmaster(const Arg *arg) {
+- selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
++ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
+ arrange(selmon);
+ }
+
+_AT_@ -1215,12 +1408,14 @@ propertynotify(XEvent *e) {
+ case XA_WM_HINTS:
+ updatewmhints(c);
+ drawbars();
++ drawtabs();
+ break;
+ }
+ if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
+ updatetitle(c);
+ if(c == c->mon->sel)
+ drawbar(c->mon);
++ drawtab(c->mon);
+ }
+ if(ev->atom == netatom[NetWMWindowType])
+ updatewindowtype(c);
+_AT_@ -1328,6 +1523,7 @@ restack(Monitor *m) {
+ XWindowChanges wc;
+
+ drawbar(m);
++ drawtab(m);
+ if(!m->sel)
+ return;
+ if(m->sel->isfloating || !m->lt[m->sellt]->arrange)
+_AT_@ -1469,10 +1665,13 @@ setfullscreen(Client *c, Bool fullscreen) {
+
+ void
+ setlayout(const Arg *arg) {
+- if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
+- selmon->sellt ^= 1;
++ if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) {
++ selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
++ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
++ }
+ if(arg && arg->v)
+- selmon->lt[selmon->sellt] = (Layout *)arg->v;
++ selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
++ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
+ strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
+ if(selmon->sel)
+ arrange(selmon);
+_AT_@ -1490,7 +1689,7 @@ setmfact(const Arg *arg) {
+ f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
+ if(f < 0.1 || f > 0.9)
+ return;
+- selmon->mfact = f;
++ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
+ arrange(selmon);
+ }
+
+_AT_@ -1511,6 +1710,8 @@ setup(void) {
+ if (!drw->fontcount)
+ die("no fonts could be loaded.
");
+ bh = drw->fonts[0]->h + 2;
++ th = bh;
++
+ updategeom();
+ /* init atoms */
+ wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
+_AT_@ -1635,13 +1836,23 @@ tile(Monitor *m) {
+
+ void
+ togglebar(const Arg *arg) {
+- selmon->showbar = !selmon->showbar;
++ selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
+ updatebarpos(selmon);
+ XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
+ arrange(selmon);
+ }
+
+ void
++tabmode(const Arg *arg) {
++ if(arg && arg->i >= 0)
++ selmon->showtab = arg->ui % showtab_nmodes;
++ else
++ selmon->showtab = (selmon->showtab + 1 ) % showtab_nmodes;
++ arrange(selmon);
++}
++
++
++void
+ togglefloating(const Arg *arg) {
+ if(!selmon->sel)
+ return;
+_AT_@ -1671,9 +1882,29 @@ toggletag(const Arg *arg) {
+ void
+ toggleview(const Arg *arg) {
+ unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
++ int i;
+
+ if(newtagset) {
++ if(newtagset == ~0) {
++ selmon->pertag->prevtag = selmon->pertag->curtag;
++ selmon->pertag->curtag = 0;
++ }
++ /* test if the user did not select the same tag */
++ if(!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
++ selmon->pertag->prevtag = selmon->pertag->curtag;
++ for (i=0; !(newtagset & 1 << i); i++) ;
++ selmon->pertag->curtag = i + 1;
++ }
+ selmon->tagset[selmon->seltags] = newtagset;
++
++ /* apply settings for this view */
++ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
++ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
++ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
++ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
++ selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
++ if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
++ togglebar(NULL);
+ focus(NULL);
+ arrange(selmon);
+ }
+_AT_@ -1745,20 +1976,43 @@ updatebars(void) {
+ CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+ XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
+ XMapRaised(dpy, m->barwin);
++ m->tabwin = XCreateWindow(dpy, root, m->wx, m->ty, m->ww, th, 0, DefaultDepth(dpy, screen),
++ CopyFromParent, DefaultVisual(dpy, screen),
++ CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
++ XDefineCursor(dpy, m->tabwin, cursor[CurNormal]->cursor);
++ XMapRaised(dpy, m->tabwin);
+ }
+ }
+
+ void
+ updatebarpos(Monitor *m) {
++ Client *c;
++ int nvis = 0;
++
+ m->wy = m->my;
+ m->wh = m->mh;
+ if(m->showbar) {
+ m->wh -= bh;
+ m->by = m->topbar ? m->wy : m->wy + m->wh;
+- m->wy = m->topbar ? m->wy + bh : m->wy;
+- }
+- else
++ if ( m->topbar )
++ m->wy += bh;
++ } else {
+ m->by = -bh;
++ }
++
++ for(c = m->clients; c; c = c->next){
++ if(ISVISIBLE(c)) ++nvis;
++ }
++
++ if(m->showtab == showtab_always
++ || ((m->showtab == showtab_auto) && (nvis > 1) && (m->lt[m->sellt]->arrange == monocle))){
++ m->wh -= th;
++ m->ty = m->toptab ? m->wy : m->wy + m->wh;
++ if ( m->toptab )
++ m->wy += th;
++ } else {
++ m->ty = -th;
++ }
+ }
+
+ void
+_AT_@ -1967,11 +2221,33 @@ updatewmhints(Client *c) {
+
+ void
+ view(const Arg *arg) {
++ int i;
++ unsigned int tmptag;
++
+ if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+ return;
+ selmon->seltags ^= 1; /* toggle sel tagset */
+- if(arg->ui & TAGMASK)
++ if(arg->ui & TAGMASK) {
++ selmon->pertag->prevtag = selmon->pertag->curtag;
+ selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
++ if(arg->ui == ~0)
++ selmon->pertag->curtag = 0;
++ else {
++ for (i=0; !(arg->ui & 1 << i); i++) ;
++ selmon->pertag->curtag = i + 1;
++ }
++ } else {
++ tmptag = selmon->pertag->prevtag;
++ selmon->pertag->prevtag = selmon->pertag->curtag;
++ selmon->pertag->curtag = tmptag;
++ }
++ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
++ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
++ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
++ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
++ selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
++ if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
++ togglebar(NULL);
+ focus(NULL);
+ arrange(selmon);
+ }
+_AT_@ -1997,7 +2273,7 @@ wintomon(Window w) {
+ if(w == root && getrootptr(&x, &y))
+ return recttomon(x, y, 1, 1);
+ for(m = mons; m; m = m->next)
+- if(w == m->barwin)
++ if(w == m->barwin || w == m->tabwin)
+ return m;
+ if((c = wintoclient(w)))
+ return c->mon;
diff --git a/dwm.suckless.org/patches/dwm-master_2015-03-05_14343e-pertag-tab-v2b.diff b/dwm.suckless.org/patches/dwm-master_2015-03-05_14343e-pertag-tab-v2b.diff
deleted file mode 100644
index 58aade9..0000000
--- a/dwm.suckless.org/patches/dwm-master_2015-03-05_14343e-pertag-tab-v2b.diff
+++ /dev/null
_AT_@ -1,693 +0,0 @@
-diff --git a/config.def.h b/config.def.h
-index eaae8f3..a07814b 100644
---- a/config.def.h
-+++ b/config.def.h
-_AT_@ -17,10 +17,22 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
- static const unsigned int snap = 32; /* snap pixel */
- static const Bool showbar = True; /* False means no bar */
- static const Bool topbar = True; /* False means bottom bar */
-+/* Display modes of the tab bar: never shown, always shown, shown only in */
-+/* monocle mode in presence of several windows. */
-+/* Modes after showtab_nmodes are disabled */
-+enum showtab_modes { showtab_never, showtab_auto, showtab_nmodes, showtab_always};
-+static const int showtab = showtab_auto; /* Default tab bar show mode */
-+static const Bool toptab = False; /* False means bottom tab bar */
-+
-
- /* tagging */
- static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
-
-+/* default layout per tags */
-+/* The first element is for all-tag view, following i-th element corresponds to */
-+/* tags[i]. Layout is referred using the layouts array index.*/
-+static int def_layouts[1 + LENGTH(tags)] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-+
- static const Rule rules[] = {
- /* xprop(1):
- * WM_CLASS(STRING) = instance, class
-_AT_@ -34,7 +46,7 @@ static const Rule rules[] = {
- /* layout(s) */
- static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
- static const int nmaster = 1; /* number of clients in master area */
--static const Bool resizehints = True; /* True means respect size hints in tiled resizals */
-+static const Bool resizehints = False; /* True means respect size hints in tiled resizals */
-
- static const Layout layouts[] = {
- /* symbol arrange function */
-_AT_@ -64,6 +76,7 @@ static Key keys[] = {
- { MODKEY, XK_p, spawn, {.v = dmenucmd } },
- { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
- { MODKEY, XK_b, togglebar, {0} },
-+ { MODKEY, XK_w, tabmode, {-1} },
- { MODKEY, XK_j, focusstack, {.i = +1 } },
- { MODKEY, XK_k, focusstack, {.i = -1 } },
- { MODKEY, XK_i, incnmaster, {.i = +1 } },
-_AT_@ -111,5 +124,6 @@ static Button buttons[] = {
- { ClkTagBar, 0, Button3, toggleview, {0} },
- { ClkTagBar, MODKEY, Button1, tag, {0} },
- { ClkTagBar, MODKEY, Button3, toggletag, {0} },
-+ { ClkTabBar, 0, Button1, focuswin, {0} },
- };
-
-diff --git a/dwm.1 b/dwm.1
-index 6687011..077d92b 100644
---- a/dwm.1
-+++ b/dwm.1
-_AT_@ -19,14 +19,22 @@ layout applied.
- Windows are grouped by tags. Each window can be tagged with one or multiple
- tags. Selecting certain tags displays all windows with these tags.
- .P
--Each screen contains a small status bar which displays all available tags, the
--layout, the title of the focused window, and the text read from the root window
--name property, if the screen is focused. A floating window is indicated with an
--empty square and a maximised floating window is indicated with a filled square
--before the windows title. The selected tags are indicated with a different
--color. The tags of the focused window are indicated with a filled square in the
--top left corner. The tags which are applied to one or more windows are
--indicated with an empty square in the top left corner.
-+Each screen contains two small status bars.
-+.P
-+One bar displays all available tags, the layout, the title of the focused
-+window, and the text read from the root window name property, if the screen is
-+focused. A floating window is indicated with an empty square and a maximised
-+floating window is indicated with a filled square before the windows title. The
-+selected tags are indicated with a different color. The tags of the focused
-+window are indicated with a filled square in the top left corner. The tags
-+which are applied to one or more windows are indicated with an empty square in
-+the top left corner.
-+.P
-+Another bar contains a tab for each window of the current view and allows
-+navigation between windows, especially in the monocle mode. The different
-+display modes of this bar are described under the Mod1\-w Keybord command
-+section. When a single tag is selected, that tag is indicated in the left corner
-+of the tab bar.
- .P
- dwm draws a small border around windows to indicate the focus state.
- .SH OPTIONS
-_AT_@ -43,7 +51,8 @@ command.
- .TP
- .B Button1
- click on a tag label to display all windows with that tag, click on the layout
--label toggles between tiled and floating layout.
-+label toggles between tiled and floating layout, click on a window name in the
-+tab bar brings focus to that window.
- .TP
- .B Button3
- click on a tag label adds/removes all windows with that tag to/from the view.
-_AT_@ -104,6 +113,12 @@ Increase master area size.
- .B Mod1\-h
- Decrease master area size.
- .TP
-+.B Mod1\-w
-+Cycle over the tab bar display modes: never displayed, always displayed,
-+displayed only in monocle mode when the view contains than one window (auto
-+mode). Some display modes can be disabled in the configuration, config.h. In
-+the default configuration only "never" and "auto" display modes are enabled.
-+.TP
- .B Mod1\-Return
- Zooms/cycles focused window to/from master area (tiled layouts only).
- .TP
-diff --git a/dwm.c b/dwm.c
-index 169adcb..515a30f 100644
---- a/dwm.c
-+++ b/dwm.c
-_AT_@ -64,7 +64,7 @@ enum { NetSupported, NetWMName, NetWMState,
- NetWMFullscreen, NetActiveWindow, NetWMWindowType,
- NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
- enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
--enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
-+enum { ClkTagBar, ClkTabBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
- ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
-
- typedef union {
-_AT_@ -111,25 +111,35 @@ typedef struct {
- void (*arrange)(Monitor *);
- } Layout;
-
-+#define MAXTABS 50
-+
-+typedef struct Pertag Pertag;
- struct Monitor {
- char ltsymbol[16];
- float mfact;
- int nmaster;
- int num;
- int by; /* bar geometry */
-+ int ty; /* tab bar geometry */
- int mx, my, mw, mh; /* screen size */
- int wx, wy, ww, wh; /* window area */
- unsigned int seltags;
- unsigned int sellt;
- unsigned int tagset[2];
- Bool showbar;
-+ Bool showtab;
- Bool topbar;
-+ Bool toptab;
- Client *clients;
- Client *sel;
- Client *stack;
- Monitor *next;
- Window barwin;
-+ Window tabwin;
-+ int ntabs;
-+ int tab_widths[MAXTABS];
- const Layout *lt[2];
-+ Pertag *pertag;
- };
-
- typedef struct {
-_AT_@ -164,12 +174,15 @@ static void detachstack(Client *c);
- static Monitor *dirtomon(int dir);
- static void drawbar(Monitor *m);
- static void drawbars(void);
-+static void drawtab(Monitor *m);
-+static void drawtabs(void);
- static void enternotify(XEvent *e);
- static void expose(XEvent *e);
- static void focus(Client *c);
- static void focusin(XEvent *e);
- static void focusmon(const Arg *arg);
- static void focusstack(const Arg *arg);
-+static void focuswin(const Arg* arg);
- static Bool getrootptr(int *x, int *y);
- static long getstate(Window w);
- static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
-_AT_@ -206,6 +219,7 @@ static void setup(void);
- static void showhide(Client *c);
- static void sigchld(int unused);
- static void spawn(const Arg *arg);
-+static void tabmode(const Arg *arg);
- static void tag(const Arg *arg);
- static void tagmon(const Arg *arg);
- static void tile(Monitor *);
-_AT_@ -240,6 +254,7 @@ static char stext[256];
- static int screen;
- static int sw, sh; /* X display screen geometry width, height */
- static int bh, blw = 0; /* bar geometry */
-+static int th = 0; /* tab bar geometry */
- static int (*xerrorxlib)(Display *, XErrorEvent *);
- static unsigned int numlockmask = 0;
- static void (*handler[LASTEvent]) (XEvent *) = {
-_AT_@ -270,6 +285,16 @@ static Window root;
- /* configuration, allows nested code to access above variables */
- #include "config.h"
-
-+struct Pertag {
-+ unsigned int curtag, prevtag; /* current and previous tag */
-+ int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
-+ float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
-+ unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
-+ const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */
-+ Bool showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
-+ Client *prevzooms[LENGTH(tags) + 1]; /* store zoom information */
-+};
-+
- /* compile-time check if all tags fit into an unsigned int bit array. */
- struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
-
-_AT_@ -389,6 +414,9 @@ arrange(Monitor *m) {
-
- void
- arrangemon(Monitor *m) {
-+ updatebarpos(m);
-+ XMoveResizeWindow(dpy, m->tabwin, m->wx, m->ty, m->ww, th);
-+
- strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
- if(m->lt[m->sellt]->arrange)
- m->lt[m->sellt]->arrange(m);
-_AT_@ -437,14 +465,32 @@ buttonpress(XEvent *e) {
- else
- click = ClkWinTitle;
- }
-+ if(ev->window == selmon->tabwin) {
-+ i = 0; x = 0;
-+ for(c = selmon->clients; c; c = c->next){
-+ if(!ISVISIBLE(c)) continue;
-+ x += selmon->tab_widths[i];
-+ if (ev->x > x)
-+ ++i;
-+ else
-+ break;
-+ if(i >= m->ntabs) break;
-+ }
-+ if(c) {
-+ click = ClkTabBar;
-+ arg.ui = i;
-+ }
-+ }
- else if((c = wintoclient(ev->window))) {
- focus(c);
- click = ClkClientWin;
- }
- for(i = 0; i < LENGTH(buttons); i++)
- if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
-- && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
-- buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
-+ && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)){
-+ buttons[i].func(((click == ClkTagBar || click == ClkTabBar)
-+ && buttons[i].arg.i == 0) ? &arg : &buttons[i].arg);
-+ }
- }
-
- void
-_AT_@ -498,6 +544,8 @@ cleanupmon(Monitor *mon) {
- }
- XUnmapWindow(dpy, mon->barwin);
- XDestroyWindow(dpy, mon->barwin);
-+ XUnmapWindow(dpy, mon->tabwin);
-+ XDestroyWindow(dpy, mon->tabwin);
- free(mon);
- }
-
-_AT_@ -517,6 +565,7 @@ void
- clientmessage(XEvent *e) {
- XClientMessageEvent *cme = &e->xclient;
- Client *c = wintoclient(cme->window);
-+ int i;
-
- if(!c)
- return;
-_AT_@ -529,6 +578,8 @@ clientmessage(XEvent *e) {
- if(!ISVISIBLE(c)) {
- c->mon->seltags ^= 1;
- c->mon->tagset[c->mon->seltags] = c->tags;
-+ for(i=0; !(c->tags & 1 << i); i++);
-+ view(&(Arg){.ui = 1 << i});
- }
- pop(c);
- }
-_AT_@ -566,8 +617,11 @@ configurenotify(XEvent *e) {
- if(updategeom() || dirty) {
- drw_resize(drw, sw, bh);
- updatebars();
-- for(m = mons; m; m = m->next)
-+ //refreshing display of status bar. The tab bar is handled by the arrange()
-+ //method, which is called below
-+ for(m = mons; m; m = m->next){
- XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
-+ }
- focus(NULL);
- arrange(NULL);
- }
-_AT_@ -630,6 +684,7 @@ configurerequest(XEvent *e) {
- Monitor *
- createmon(void) {
- Monitor *m;
-+ int i;
-
- if(!(m = (Monitor *)calloc(1, sizeof(Monitor))))
- die("fatal: could not malloc() %u bytes
", sizeof(Monitor));
-_AT_@ -637,10 +692,34 @@ createmon(void) {
- m->mfact = mfact;
- m->nmaster = nmaster;
- m->showbar = showbar;
-+ m->showtab = showtab;
- m->topbar = topbar;
-- m->lt[0] = &layouts[0];
-+ m->toptab = toptab;
-+ m->ntabs = 0;
-+ m->lt[0] = &layouts[def_layouts[1] % LENGTH(layouts)];
- m->lt[1] = &layouts[1 % LENGTH(layouts)];
- strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
-+ if(!(m->pertag = (Pertag *)calloc(1, sizeof(Pertag))))
-+ die("fatal: could not malloc() %u bytes
", sizeof(Pertag));
-+ m->pertag->curtag = m->pertag->prevtag = 1;
-+ for(i=0; i <= LENGTH(tags); i++) {
-+ /* init nmaster */
-+ m->pertag->nmasters[i] = m->nmaster;
-+
-+ /* init mfacts */
-+ m->pertag->mfacts[i] = m->mfact;
-+
-+ /* init layouts */
-+ m->pertag->ltidxs[i][0] = &layouts[def_layouts[i % LENGTH(def_layouts)] % LENGTH(layouts)];
-+ m->pertag->ltidxs[i][1] = m->lt[1];
-+ m->pertag->sellts[i] = m->sellt;
-+
-+ /* init showbar */
-+ m->pertag->showbars[i] = m->showbar;
-+
-+ /* swap focus and zoomswap*/
-+ m->pertag->prevzooms[i] = NULL;
-+ }
- return m;
- }
-
-_AT_@ -749,6 +828,104 @@ drawbars(void) {
- }
-
- void
-+drawtabs(void) {
-+ Monitor *m;
-+
-+ for(m = mons; m; m = m->next)
-+ drawtab(m);
-+}
-+
-+static int
-+cmpint(const void *p1, const void *p2) {
-+ /* The actual arguments to this function are "pointers to
-+ pointers to char", but strcmp(3) arguments are "pointers
-+ to char", hence the following cast plus dereference */
-+ return *((int*) p1) > * (int*) p2;
-+}
-+
-+
-+void
-+drawtab(Monitor *m) {
-+ Client *c;
-+ int i;
-+ int itag = -1;
-+ char view_info[50];
-+ int view_info_w = 0;
-+ int sorted_label_widths[MAXTABS];
-+ int tot_width;
-+ int maxsize = bh;
-+ int x = 0;
-+ int w = 0;
-+
-+ //view_info: indicate the tag which is displayed in the view
-+ for(i = 0; i < LENGTH(tags); ++i){
-+ if((selmon->tagset[selmon->seltags] >> i) & 1) {
-+ if(itag >=0){ //more than one tag selected
-+ itag = -1;
-+ break;
-+ }
-+ itag = i;
-+ }
-+ }
-+ if(0 <= itag && itag < LENGTH(tags)){
-+ snprintf(view_info, sizeof view_info, "[%s]", tags[itag]);
-+ } else {
-+ strncpy(view_info, "[...]", sizeof view_info);
-+ }
-+ view_info[sizeof(view_info) - 1 ] = 0;
-+ view_info_w = TEXTW(view_info);
-+ tot_width = view_info_w;
-+
-+ /* Calculates number of labels and their width */
-+ m->ntabs = 0;
-+ for(c = m->clients; c; c = c->next){
-+ if(!ISVISIBLE(c)) continue;
-+ m->tab_widths[m->ntabs] = TEXTW(c->name);
-+ tot_width += m->tab_widths[m->ntabs];
-+ ++m->ntabs;
-+ if(m->ntabs >= MAXTABS) break;
-+ }
-+
-+ if(tot_width > m->ww){ //not enough space to display the labels, they need to be truncated
-+ memcpy(sorted_label_widths, m->tab_widths, sizeof(int) * m->ntabs);
-+ qsort(sorted_label_widths, m->ntabs, sizeof(int), cmpint);
-+ tot_width = view_info_w;
-+ for(i = 0; i < m->ntabs; ++i){
-+ if(tot_width + (m->ntabs - i) * sorted_label_widths[i] > m->ww)
-+ break;
-+ tot_width += sorted_label_widths[i];
-+ }
-+ maxsize = (m->ww - tot_width) / (m->ntabs - i);
-+ } else{
-+ maxsize = m->ww;
-+ }
-+ i = 0;
-+ for(c = m->clients; c; c = c->next){
-+ if(!ISVISIBLE(c)) continue;
-+ if(i >= m->ntabs) break;
-+ if(m->tab_widths[i] > maxsize) m->tab_widths[i] = maxsize;
-+ w = m->tab_widths[i];
-+ drw_setscheme(drw, (c == m->sel) ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
-+ drw_text(drw, x, 0, w, th, c->name, 0);
-+ x += w;
-+ ++i;
-+ }
-+
-+ drw_setscheme(drw, &scheme[SchemeNorm]);
-+
-+ /* cleans interspace between window names and current viewed tag label */
-+ w = m->ww - view_info_w - x;
-+ drw_text(drw, x, 0, w, th, NULL, 0);
-+
-+ /* view info */
-+ x += w;
-+ w = view_info_w;
-+ drw_text(drw, x, 0, w, th, view_info, 0);
-+
-+ drw_map(drw, m->tabwin, 0, 0, m->ww, th);
-+}
-+
-+void
- enternotify(XEvent *e) {
- Client *c;
- Monitor *m;
-_AT_@ -772,8 +949,10 @@ expose(XEvent *e) {
- Monitor *m;
- XExposeEvent *ev = &e->xexpose;
-
-- if(ev->count == 0 && (m = wintomon(ev->window)))
-+ if(ev->count == 0 && (m = wintomon(ev->window))){
- drawbar(m);
-+ drawtab(m);
-+ }
- }
-
- void
-_AT_@ -800,6 +979,7 @@ focus(Client *c) {
- }
- selmon->sel = c;
- drawbars();
-+ drawtabs();
- }
-
- void
-_AT_@ -850,6 +1030,19 @@ focusstack(const Arg *arg) {
- }
- }
-
-+void
-+focuswin(const Arg* arg){
-+ int iwin = arg->i;
-+ Client* c = NULL;
-+ for(c = selmon->clients; c && (iwin || !ISVISIBLE(c)) ; c = c->next){
-+ if(ISVISIBLE(c)) --iwin;
-+ };
-+ if(c) {
-+ focus(c);
-+ restack(selmon);
-+ }
-+}
-+
- Atom
- getatomprop(Client *c, Atom prop) {
- int di;
-_AT_@ -957,7 +1150,7 @@ grabkeys(void) {
-
- void
- incnmaster(const Arg *arg) {
-- selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
-+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
- arrange(selmon);
- }
-
-_AT_@ -1216,12 +1409,14 @@ propertynotify(XEvent *e) {
- case XA_WM_HINTS:
- updatewmhints(c);
- drawbars();
-+ drawtabs();
- break;
- }
- if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
- updatetitle(c);
- if(c == c->mon->sel)
- drawbar(c->mon);
-+ drawtab(c->mon);
- }
- if(ev->atom == netatom[NetWMWindowType])
- updatewindowtype(c);
-_AT_@ -1329,6 +1524,7 @@ restack(Monitor *m) {
- XWindowChanges wc;
-
- drawbar(m);
-+ drawtab(m);
- if(!m->sel)
- return;
- if(m->sel->isfloating || !m->lt[m->sellt]->arrange)
-_AT_@ -1470,10 +1666,13 @@ setfullscreen(Client *c, Bool fullscreen) {
-
- void
- setlayout(const Arg *arg) {
-- if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
-- selmon->sellt ^= 1;
-+ if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) {
-+ selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
-+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
-+ }
- if(arg && arg->v)
-- selmon->lt[selmon->sellt] = (Layout *)arg->v;
-+ selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
-+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
- strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
- if(selmon->sel)
- arrange(selmon);
-_AT_@ -1491,7 +1690,7 @@ setmfact(const Arg *arg) {
- f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
- if(f < 0.1 || f > 0.9)
- return;
-- selmon->mfact = f;
-+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
- arrange(selmon);
- }
-
-_AT_@ -1512,6 +1711,8 @@ setup(void) {
- if (!drw->fontcount)
- die("No fonts could be loaded.
");
- bh = drw->fonts[0]->h + 2;
-+ th = bh;
-+
- updategeom();
- /* init atoms */
- wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
-_AT_@ -1636,13 +1837,23 @@ tile(Monitor *m) {
-
- void
- togglebar(const Arg *arg) {
-- selmon->showbar = !selmon->showbar;
-+ selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
- updatebarpos(selmon);
- XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
- arrange(selmon);
- }
-
- void
-+tabmode(const Arg *arg) {
-+ if(arg && arg->i >= 0)
-+ selmon->showtab = arg->ui % showtab_nmodes;
-+ else
-+ selmon->showtab = (selmon->showtab + 1 ) % showtab_nmodes;
-+ arrange(selmon);
-+}
-+
-+
-+void
- togglefloating(const Arg *arg) {
- if(!selmon->sel)
- return;
-_AT_@ -1672,9 +1883,29 @@ toggletag(const Arg *arg) {
- void
- toggleview(const Arg *arg) {
- unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
-+ int i;
-
- if(newtagset) {
-+ if(newtagset == ~0) {
-+ selmon->pertag->prevtag = selmon->pertag->curtag;
-+ selmon->pertag->curtag = 0;
-+ }
-+ /* test if the user did not select the same tag */
-+ if(!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
-+ selmon->pertag->prevtag = selmon->pertag->curtag;
-+ for (i=0; !(newtagset & 1 << i); i++) ;
-+ selmon->pertag->curtag = i + 1;
-+ }
- selmon->tagset[selmon->seltags] = newtagset;
-+
-+ /* apply settings for this view */
-+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
-+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
-+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
-+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
-+ selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
-+ if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
-+ togglebar(NULL);
- focus(NULL);
- arrange(selmon);
- }
-_AT_@ -1746,20 +1977,43 @@ updatebars(void) {
- CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
- XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
- XMapRaised(dpy, m->barwin);
-+ m->tabwin = XCreateWindow(dpy, root, m->wx, m->ty, m->ww, th, 0, DefaultDepth(dpy, screen),
-+ CopyFromParent, DefaultVisual(dpy, screen),
-+ CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
-+ XDefineCursor(dpy, m->tabwin, cursor[CurNormal]->cursor);
-+ XMapRaised(dpy, m->tabwin);
- }
- }
-
- void
- updatebarpos(Monitor *m) {
-+ Client *c;
-+ int nvis = 0;
-+
- m->wy = m->my;
- m->wh = m->mh;
- if(m->showbar) {
- m->wh -= bh;
- m->by = m->topbar ? m->wy : m->wy + m->wh;
-- m->wy = m->topbar ? m->wy + bh : m->wy;
-- }
-- else
-+ if ( m->topbar )
-+ m->wy += bh;
-+ } else {
- m->by = -bh;
-+ }
-+
-+ for(c = m->clients; c; c = c->next){
-+ if(ISVISIBLE(c)) ++nvis;
-+ }
-+
-+ if(m->showtab == showtab_always
-+ || ((m->showtab == showtab_auto) && (nvis > 1) && (m->lt[m->sellt]->arrange == monocle))){
-+ m->wh -= th;
-+ m->ty = m->toptab ? m->wy : m->wy + m->wh;
-+ if ( m->toptab )
-+ m->wy += th;
-+ } else {
-+ m->ty = -th;
-+ }
- }
-
- void
-_AT_@ -1969,11 +2223,33 @@ updatewmhints(Client *c) {
-
- void
- view(const Arg *arg) {
-+ int i;
-+ unsigned int tmptag;
-+
- if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
- return;
- selmon->seltags ^= 1; /* toggle sel tagset */
-- if(arg->ui & TAGMASK)
-+ if(arg->ui & TAGMASK) {
-+ selmon->pertag->prevtag = selmon->pertag->curtag;
- selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
-+ if(arg->ui == ~0)
-+ selmon->pertag->curtag = 0;
-+ else {
-+ for (i=0; !(arg->ui & 1 << i); i++) ;
-+ selmon->pertag->curtag = i + 1;
-+ }
-+ } else {
-+ tmptag = selmon->pertag->prevtag;
-+ selmon->pertag->prevtag = selmon->pertag->curtag;
-+ selmon->pertag->curtag = tmptag;
-+ }
-+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
-+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
-+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
-+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
-+ selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
-+ if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
-+ togglebar(NULL);
- focus(NULL);
- arrange(selmon);
- }
-_AT_@ -1999,7 +2275,7 @@ wintomon(Window w) {
- if(w == root && getrootptr(&x, &y))
- return recttomon(x, y, 1, 1);
- for(m = mons; m; m = m->next)
-- if(w == m->barwin)
-+ if(w == m->barwin || w == m->tabwin)
- return m;
- if((c = wintoclient(w)))
- return c->mon;
diff --git a/dwm.suckless.org/patches/tab.md b/dwm.suckless.org/patches/tab.md
index 9268757..57e8871 100644
--- a/dwm.suckless.org/patches/tab.md
+++ b/dwm.suckless.org/patches/tab.md
_AT_@ -130,7 +130,7 @@ Download
  * Combined patch of tab and the [pertag](pertag) patch from Jan Christoph Ebersbach.
    * Follow the [link](pertag) for the description of this patch and the credits. The possibility to define the default layout per view has been added.
    * For dwm 6.0: [dwm-6.0-pertag-tab-v2b.diff](dwm-6.0-pertag-tab-v2b.diff)
- * For dwm from the git master branch: [dwm-master\_2015-03-05\_14343e-pertag-tab-v2b.diff](dwm-master\_2015-03-05\_14343e-pertag-tab-v2b.diff)
+ * For dwm from the git master branch: [dwm-7e1182c-pertag-tab.diff](dwm-7e1182c-pertag-tab.diff)
 
 Old versions
 
Received on Sat Oct 31 2015 - 05:58:28 CET

This archive was generated by hypermail 2.3.0 : Sat Oct 31 2015 - 06:00:13 CET