dwm-pertag-20200914-61bb8b2.diff 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. diff --git a/dwm.c b/dwm.c
  2. index 664c527..ac8e4ec 100644
  3. --- a/dwm.c
  4. +++ b/dwm.c
  5. @@ -111,6 +111,7 @@ typedef struct {
  6. void (*arrange)(Monitor *);
  7. } Layout;
  8. +typedef struct Pertag Pertag;
  9. struct Monitor {
  10. char ltsymbol[16];
  11. float mfact;
  12. @@ -130,6 +131,7 @@ struct Monitor {
  13. Monitor *next;
  14. Window barwin;
  15. const Layout *lt[2];
  16. + Pertag *pertag;
  17. };
  18. typedef struct {
  19. @@ -272,6 +274,15 @@ static Window root, wmcheckwin;
  20. /* configuration, allows nested code to access above variables */
  21. #include "config.h"
  22. +struct Pertag {
  23. + unsigned int curtag, prevtag; /* current and previous tag */
  24. + int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
  25. + float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
  26. + unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
  27. + const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */
  28. + int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
  29. +};
  30. +
  31. /* compile-time check if all tags fit into an unsigned int bit array. */
  32. struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
  33. @@ -632,6 +643,7 @@ Monitor *
  34. createmon(void)
  35. {
  36. Monitor *m;
  37. + unsigned int i;
  38. m = ecalloc(1, sizeof(Monitor));
  39. m->tagset[0] = m->tagset[1] = 1;
  40. @@ -642,6 +654,20 @@ createmon(void)
  41. m->lt[0] = &layouts[0];
  42. m->lt[1] = &layouts[1 % LENGTH(layouts)];
  43. strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
  44. + m->pertag = ecalloc(1, sizeof(Pertag));
  45. + m->pertag->curtag = m->pertag->prevtag = 1;
  46. +
  47. + for (i = 0; i <= LENGTH(tags); i++) {
  48. + m->pertag->nmasters[i] = m->nmaster;
  49. + m->pertag->mfacts[i] = m->mfact;
  50. +
  51. + m->pertag->ltidxs[i][0] = m->lt[0];
  52. + m->pertag->ltidxs[i][1] = m->lt[1];
  53. + m->pertag->sellts[i] = m->sellt;
  54. +
  55. + m->pertag->showbars[i] = m->showbar;
  56. + }
  57. +
  58. return m;
  59. }
  60. @@ -967,7 +993,7 @@ grabkeys(void)
  61. void
  62. incnmaster(const Arg *arg)
  63. {
  64. - selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
  65. + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
  66. arrange(selmon);
  67. }
  68. @@ -1502,9 +1528,9 @@ void
  69. setlayout(const Arg *arg)
  70. {
  71. if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
  72. - selmon->sellt ^= 1;
  73. + selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
  74. if (arg && arg->v)
  75. - selmon->lt[selmon->sellt] = (Layout *)arg->v;
  76. + selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
  77. strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
  78. if (selmon->sel)
  79. arrange(selmon);
  80. @@ -1523,7 +1549,7 @@ setmfact(const Arg *arg)
  81. f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
  82. if (f < 0.05 || f > 0.95)
  83. return;
  84. - selmon->mfact = f;
  85. + selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
  86. arrange(selmon);
  87. }
  88. @@ -1702,7 +1728,7 @@ tile(Monitor *m)
  89. void
  90. togglebar(const Arg *arg)
  91. {
  92. - selmon->showbar = !selmon->showbar;
  93. + selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
  94. updatebarpos(selmon);
  95. XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
  96. arrange(selmon);
  97. @@ -1741,9 +1767,33 @@ void
  98. toggleview(const Arg *arg)
  99. {
  100. unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
  101. + int i;
  102. if (newtagset) {
  103. selmon->tagset[selmon->seltags] = newtagset;
  104. +
  105. + if (newtagset == ~0) {
  106. + selmon->pertag->prevtag = selmon->pertag->curtag;
  107. + selmon->pertag->curtag = 0;
  108. + }
  109. +
  110. + /* test if the user did not select the same tag */
  111. + if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
  112. + selmon->pertag->prevtag = selmon->pertag->curtag;
  113. + for (i = 0; !(newtagset & 1 << i); i++) ;
  114. + selmon->pertag->curtag = i + 1;
  115. + }
  116. +
  117. + /* apply settings for this view */
  118. + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
  119. + selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
  120. + selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
  121. + selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
  122. + selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
  123. +
  124. + if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
  125. + togglebar(NULL);
  126. +
  127. focus(NULL);
  128. arrange(selmon);
  129. }
  130. @@ -2038,11 +2088,37 @@ updatewmhints(Client *c)
  131. void
  132. view(const Arg *arg)
  133. {
  134. + int i;
  135. + unsigned int tmptag;
  136. +
  137. if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
  138. return;
  139. selmon->seltags ^= 1; /* toggle sel tagset */
  140. - if (arg->ui & TAGMASK)
  141. + if (arg->ui & TAGMASK) {
  142. selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
  143. + selmon->pertag->prevtag = selmon->pertag->curtag;
  144. +
  145. + if (arg->ui == ~0)
  146. + selmon->pertag->curtag = 0;
  147. + else {
  148. + for (i = 0; !(arg->ui & 1 << i); i++) ;
  149. + selmon->pertag->curtag = i + 1;
  150. + }
  151. + } else {
  152. + tmptag = selmon->pertag->prevtag;
  153. + selmon->pertag->prevtag = selmon->pertag->curtag;
  154. + selmon->pertag->curtag = tmptag;
  155. + }
  156. +
  157. + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
  158. + selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
  159. + selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
  160. + selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
  161. + selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
  162. +
  163. + if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
  164. + togglebar(NULL);
  165. +
  166. focus(NULL);
  167. arrange(selmon);
  168. }