dwm-dualstatus-6.1.diff 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. diff --git a/config.def.h b/config.def.h
  2. index 7054c06..b96107a 100644
  3. --- a/config.def.h
  4. +++ b/config.def.h
  5. @@ -15,6 +15,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
  6. static const unsigned int snap = 32; /* snap pixel */
  7. static const int showbar = 1; /* 0 means no bar */
  8. static const int topbar = 1; /* 0 means bottom bar */
  9. +static const int extrabar = 1; /* 0 means no extra bar */
  10. /* tagging */
  11. static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  12. @@ -62,6 +63,7 @@ static Key keys[] = {
  13. { MODKEY, XK_p, spawn, {.v = dmenucmd } },
  14. { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
  15. { MODKEY, XK_b, togglebar, {0} },
  16. + { MODKEY, XK_b, toggleextrabar, {0} },
  17. { MODKEY, XK_j, focusstack, {.i = +1 } },
  18. { MODKEY, XK_k, focusstack, {.i = -1 } },
  19. { MODKEY, XK_i, incnmaster, {.i = +1 } },
  20. diff --git a/dwm.c b/dwm.c
  21. index 0362114..9b7cd74 100644
  22. --- a/dwm.c
  23. +++ b/dwm.c
  24. @@ -141,6 +141,13 @@ typedef struct {
  25. int monitor;
  26. } Rule;
  27. +typedef struct {
  28. + int y;
  29. + int show;
  30. + Window win;
  31. + char text[256];
  32. +} Bar;
  33. +
  34. /* function declarations */
  35. static void applyrules(Client *c);
  36. static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
  37. @@ -210,6 +217,7 @@ static void tag(const Arg *arg);
  38. static void tagmon(const Arg *arg);
  39. static void tile(Monitor *);
  40. static void togglebar(const Arg *arg);
  41. +static void toggleextrabar(const Arg *arg);
  42. static void togglefloating(const Arg *arg);
  43. static void toggletag(const Arg *arg);
  44. static void toggleview(const Arg *arg);
  45. @@ -266,6 +274,7 @@ static Display *dpy;
  46. static Drw *drw;
  47. static Monitor *mons, *selmon;
  48. static Window root;
  49. +static Bar eb;
  50. /* configuration, allows nested code to access above variables */
  51. #include "config.h"
  52. @@ -477,6 +486,8 @@ cleanup(void)
  53. while (m->stack)
  54. unmanage(m->stack, 0);
  55. XUngrabKey(dpy, AnyKey, AnyModifier, root);
  56. + XUnmapWindow(dpy, eb.win);
  57. + XDestroyWindow(dpy, eb.win);
  58. while (mons)
  59. cleanupmon(mons);
  60. for (i = 0; i < CurLast; i++)
  61. @@ -578,6 +589,7 @@ configurenotify(XEvent *e)
  62. updatebars();
  63. for (m = mons; m; m = m->next)
  64. XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
  65. + XMoveResizeWindow(dpy, eb.win, mons->wx, eb.y, mons->ww, bh);
  66. focus(NULL);
  67. arrange(NULL);
  68. }
  69. @@ -751,6 +763,9 @@ drawbar(Monitor *m)
  70. }
  71. }
  72. drw_map(drw, m->barwin, 0, 0, m->ww, bh);
  73. + drw_setscheme(drw, &scheme[SchemeNorm]);
  74. + drw_text(drw, 0, 0, mons->ww, bh, eb.text, 0);
  75. + drw_map(drw, eb.win, 0, 0, mons->ww, bh);
  76. }
  77. void
  78. @@ -1558,6 +1573,7 @@ setup(void)
  79. root = RootWindow(dpy, screen);
  80. drw = drw_create(dpy, screen, root, sw, sh);
  81. drw_load_fonts(drw, fonts, LENGTH(fonts));
  82. + eb.show = extrabar;
  83. if (!drw->fontcount)
  84. die("no fonts could be loaded.\n");
  85. bh = drw->fonts[0]->h + 2;
  86. @@ -1699,6 +1715,17 @@ togglebar(const Arg *arg)
  87. }
  88. void
  89. +toggleextrabar(const Arg *arg)
  90. +{
  91. + if(selmon == mons) {
  92. + eb.show = !eb.show;
  93. + updatebarpos(selmon);
  94. + XMoveResizeWindow(dpy, eb.win, selmon->wx, eb.y, selmon->ww, bh);
  95. + arrange(selmon);
  96. + }
  97. +}
  98. +
  99. +void
  100. togglefloating(const Arg *arg)
  101. {
  102. if (!selmon->sel)
  103. @@ -1810,6 +1837,13 @@ updatebars(void)
  104. XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
  105. XMapRaised(dpy, m->barwin);
  106. }
  107. + if(!eb.win) {
  108. + eb.win = XCreateWindow(dpy, root, mons->wx, eb.y, mons->ww, bh, 0, DefaultDepth(dpy, screen),
  109. + CopyFromParent, DefaultVisual(dpy, screen),
  110. + CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
  111. + XDefineCursor(dpy, eb.win, cursor[CurNormal]->cursor);
  112. + XMapRaised(dpy, eb.win);
  113. + }
  114. }
  115. void
  116. @@ -1823,6 +1857,13 @@ updatebarpos(Monitor *m)
  117. m->wy = m->topbar ? m->wy + bh : m->wy;
  118. } else
  119. m->by = -bh;
  120. + if(m == mons && eb.show) {
  121. + m->wh -= bh;
  122. + eb.y = topbar ? m->wy + m->wh : m->wy;
  123. + m->wy = m->topbar ? m->wy : m->wy + bh;
  124. + }
  125. + else
  126. + eb.y = -bh;
  127. }
  128. void
  129. @@ -1992,8 +2033,21 @@ updatetitle(Client *c)
  130. void
  131. updatestatus(void)
  132. {
  133. - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
  134. + char text[512];
  135. + if(!gettextprop(root, XA_WM_NAME, text, sizeof(text))) {
  136. strcpy(stext, "dwm-"VERSION);
  137. + eb.text[0] = '\0';
  138. + }
  139. + else {
  140. + char *e = strchr(text, ';');
  141. + if(e) {
  142. + *e = '\0'; e++;
  143. + strncpy(eb.text, e, sizeof(eb.text)-1);
  144. + }
  145. + else
  146. + eb.text[0] = '\0';
  147. + strncpy(stext, text, sizeof(stext)-1);
  148. + }
  149. drawbar(selmon);
  150. }