Hi all,
I sent this directly to Marc, but I think it would be useful to post
here as well. The attached patch for an implementation in dvtm of the
dwm pertag patch. It actually plays much more nicely with multiple tags
than I had anticipated. I think it's appropriate for the master branch,
but that's not up to me. I'd love to hear some feedback!
Here's the summary of features:
The following settings are chosen individually for each tag. Each
starts out using the default settings from config.h.
* Layout
* Number of clients in the master window
* Percentage of the screen used by the master window
* Status bar position and visibility
When toggling to view multiple tags, the settings of the first
selected tag are respected. This remains true even when using the
View Previous Tag functionality.
Thanks! -Ross
diff --git a/dvtm.c b/dvtm.c
index 464a223..684cd3c 100644
--- a/dvtm.c
+++ b/dvtm.c
@@ -222,9 +222,19 @@ static char *title;
#include "config.h"
+typedef struct {
+ unsigned int curtag, prevtag;
+ int nmasters[LENGTH(tags) + 1];
+ float mfacts[LENGTH(tags) + 1];
+ Layout *layouts[LENGTH(tags) + 1];
+ int barpos[LENGTH(tags) + 1];
+ int barlastpos[LENGTH(tags) + 1];
+} Pertag;
+
/* global variables */
static const char *dvtm_name = "dvtm";
Screen screen = { .mfact = MFACT, .nmaster = NMASTER, .history = SCROLL_HISTORY };
+static Pertag pertag;
static Client *stack = NULL;
static Client *sel = NULL;
static Client *lastsel = NULL;
@@ -301,15 +311,15 @@ updatebarpos(void) {
static void
hidebar(void) {
if (bar.pos != BAR_OFF) {
- bar.lastpos = bar.pos;
- bar.pos = BAR_OFF;
+ bar.lastpos = pertag.barlastpos[pertag.curtag] = bar.pos;
+ bar.pos = pertag.barpos[pertag.curtag] = BAR_OFF;
}
}
static void
showbar(void) {
if (bar.pos == BAR_OFF)
- bar.pos = bar.lastpos;
+ bar.pos = pertag.barpos[pertag.curtag] = bar.lastpos;
}
static void
@@ -805,9 +815,32 @@ toggletag(const char *args[]) {
}
static void
+setpertag(void) {
+ screen.nmaster = pertag.nmasters[pertag.curtag];
+ screen.mfact = pertag.mfacts[pertag.curtag];
+ layout = pertag.layouts[pertag.curtag];
+ if (bar.pos != pertag.barpos[pertag.curtag]) {
+ bar.pos = pertag.barpos[pertag.curtag];
+ updatebarpos();
+ }
+ bar.lastpos = pertag.barlastpos[pertag.curtag];
+}
+
+static void
toggleview(const char *args[]) {
+ int i;
+
unsigned int newtagset = tagset[seltags] ^ (bitoftag(args[0]) & TAGMASK);
if (newtagset) {
+ if(newtagset == TAGMASK) {
+ pertag.prevtag = pertag.curtag;
+ pertag.curtag = 0;
+ } else if(!(newtagset & 1 << (pertag.curtag - 1))) {
+ pertag.prevtag = pertag.curtag;
+ for (i=0; !(newtagset &1 << i); i++) ;
+ pertag.curtag = i + 1;
+ }
+ setpertag();
tagset[seltags] = newtagset;
tagschanged();
}
@@ -815,9 +848,19 @@ toggleview(const char *args[]) {
static void
view(const char *args[]) {
+ int i;
+
unsigned int newtagset = bitoftag(args[0]) & TAGMASK;
if (tagset[seltags] != newtagset && newtagset) {
seltags ^= 1; /* toggle sel tagset */
+ pertag.prevtag = pertag.curtag;
+ if(args[0] == NULL)
+ pertag.curtag = 0;
+ else {
+ for (i = 0; (i < LENGTH(tags)) && (tags[i] != args[0]); i++) ;
+ pertag.curtag = i + 1;
+ }
+ setpertag();
tagset[seltags] = newtagset;
tagschanged();
}
@@ -825,7 +868,13 @@ view(const char *args[]) {
static void
viewprevtag(const char *args[]) {
+ unsigned int tmptag;
+
seltags ^= 1;
+ tmptag = pertag.prevtag;
+ pertag.prevtag = pertag.curtag;
+ pertag.curtag = tmptag;
+ setpertag();
tagschanged();
}
@@ -869,6 +918,20 @@ mouse_setup(void) {
#endif /* CONFIG_MOUSE */
}
+static void
+initpertag(void) {
+ int i;
+
+ pertag.curtag = pertag.prevtag = 1;
+ for(i=0; i <= LENGTH(tags); i++) {
+ pertag.nmasters[i] = screen.nmaster;
+ pertag.mfacts[i] = screen.mfact;
+ pertag.layouts[i] = layout;
+ pertag.barpos[i] = bar.pos;
+ pertag.barlastpos[i] = bar.lastpos;
+ }
+}
+
static bool
checkshell(const char *shell) {
if (shell == NULL || *shell == '\0' || *shell != '/')
@@ -914,6 +977,7 @@ setup(void) {
}
colors[i].pair = vt_color_reserve(colors[i].fg, colors[i].bg);
}
+ initpertag();
resize_screen();
struct sigaction sa;
sa.sa_flags = 0;
@@ -1242,6 +1306,7 @@ setlayout(const char *args[]) {
return;
layout = &layouts[i];
}
+ pertag.layouts[pertag.curtag] = layout;
arrange();
}
@@ -1262,6 +1327,7 @@ incnmaster(const char *args[]) {
if (screen.nmaster < 1)
screen.nmaster = 1;
}
+ pertag.nmasters[pertag.curtag] = screen.nmaster;
arrange();
}
@@ -1284,6 +1350,7 @@ setmfact(const char *args[]) {
else if (screen.mfact > 0.9)
screen.mfact = 0.9;
}
+ pertag.mfacts[pertag.curtag] = screen.mfact;
arrange();
}
@@ -1308,10 +1375,10 @@ static void
togglebarpos(const char *args[]) {
switch (bar.pos == BAR_OFF ? bar.lastpos : bar.pos) {
case BAR_TOP:
- bar.pos = BAR_BOTTOM;
+ bar.pos = pertag.barpos[pertag.curtag] = BAR_BOTTOM;
break;
case BAR_BOTTOM:
- bar.pos = BAR_TOP;
+ bar.pos = pertag.barpos[pertag.curtag] = BAR_TOP;
break;
}
updatebarpos();