dwm-dualstatus-6.0.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
dwm-dualstatus-6.0.diff (4794B)
---
1 diff --git a/config.def.h b/config.def.h
2 index 77ff358..ea9758d 100644
3 --- a/config.def.h
4 +++ b/config.def.h
5 @@ -12,6 +12,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
6 static const unsigned int snap = 32; /* snap pixel */
7 static const Bool showbar = True; /* False means no bar */
8 static const Bool topbar = True; /* False means bottom bar */
9 +static const Bool extrabar = True; /* False means no extra bar */
10
11 /* tagging */
12 static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
13 @@ -54,6 +55,7 @@ static Key keys[] = {
14 { MODKEY, XK_p, spawn, {.v = dmenucmd } },
15 { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
16 { MODKEY, XK_b, togglebar, {0} },
17 + { MODKEY, XK_b, toggleextrabar, {0} },
18 { MODKEY, XK_j, focusstack, {.i = +1 } },
19 { MODKEY, XK_k, focusstack, {.i = -1 } },
20 { MODKEY, XK_i, incnmaster, {.i = +1 } },
21 diff --git a/dwm.c b/dwm.c
22 index 1d78655..b322ff5 100644
23 --- a/dwm.c
24 +++ b/dwm.c
25 @@ -154,6 +154,13 @@ typedef struct {
26 int monitor;
27 } Rule;
28
29 +typedef struct {
30 + int y;
31 + Bool show;
32 + Window win;
33 + char text[256];
34 +} Bar;
35 +
36 /* function declarations */
37 static void applyrules(Client *c);
38 static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact);
39 @@ -229,6 +236,7 @@ static void tagmon(const Arg *arg);
40 static int textnw(const char *text, unsigned int len);
41 static void tile(Monitor *);
42 static void togglebar(const Arg *arg);
43 +static void toggleextrabar(const Arg *arg);
44 static void togglefloating(const Arg *arg);
45 static void toggletag(const Arg *arg);
46 static void toggleview(const Arg *arg);
47 @@ -283,6 +291,7 @@ static Display *dpy;
48 static DC dc;
49 static Monitor *mons = NULL, *selmon = NULL;
50 static Window root;
51 +static Bar eb;
52
53 /* configuration, allows nested code to access above variables */
54 #include "config.h"
55 @@ -495,6 +504,8 @@ cleanup(void) {
56 XFreeCursor(dpy, cursor[CurNormal]);
57 XFreeCursor(dpy, cursor[CurResize]);
58 XFreeCursor(dpy, cursor[CurMove]);
59 + XUnmapWindow(dpy, eb.win);
60 + XDestroyWindow(dpy, eb.win);
61 while(mons)
62 cleanupmon(mons);
63 XSync(dpy, False);
64 @@ -584,6 +595,7 @@ configurenotify(XEvent *e) {
65 updatebars();
66 for(m = mons; m; m = m->next)
67 XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
68 + XMoveResizeWindow(dpy, eb.win, mons->wx, eb.y, mons->ww, bh);
69 focus(NULL);
70 arrange(NULL);
71 }
72 @@ -762,6 +774,10 @@ drawbar(Monitor *m) {
73 drawtext(NULL, dc.norm, False);
74 }
75 XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
76 + dc.x = 0;
77 + dc.w = m->ww;
78 + drawtext(eb.text, dc.norm, False);
79 + XCopyArea(dpy, dc.drawable, eb.win, dc.gc, 0, 0, m->ww, bh, 0, 0);
80 XSync(dpy, False);
81 }
82
83 @@ -1594,6 +1610,7 @@ setup(void) {
84 sw = DisplayWidth(dpy, screen);
85 sh = DisplayHeight(dpy, screen);
86 bh = dc.h = dc.font.height + 2;
87 + eb.show = extrabar;
88 updategeom();
89 /* init atoms */
90 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
91 @@ -1736,6 +1753,16 @@ togglebar(const Arg *arg) {
92 }
93
94 void
95 +toggleextrabar(const Arg *arg) {
96 + if(selmon == mons) {
97 + eb.show = !eb.show;
98 + updatebarpos(selmon);
99 + XMoveResizeWindow(dpy, eb.win, selmon->wx, eb.y, selmon->ww, bh);
100 + arrange(selmon);
101 + }
102 +}
103 +
104 +void
105 togglefloating(const Arg *arg) {
106 if(!selmon->sel)
107 return;
108 @@ -1833,6 +1860,13 @@ updatebars(void) {
109 XDefineCursor(dpy, m->barwin, cursor[CurNormal]);
110 XMapRaised(dpy, m->barwin);
111 }
112 + if(!eb.win) {
113 + eb.win = XCreateWindow(dpy, root, mons->wx, eb.y, mons->ww, bh, 0, DefaultDepth(dpy, screen),
114 + CopyFromParent, DefaultVisual(dpy, screen),
115 + CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
116 + XDefineCursor(dpy, eb.win, cursor[CurNormal]);
117 + XMapRaised(dpy, eb.win);
118 + }
119 }
120
121 void
122 @@ -1846,6 +1880,13 @@ updatebarpos(Monitor *m) {
123 }
124 else
125 m->by = -bh;
126 + if(m == mons && eb.show) {
127 + m->wh -= bh;
128 + eb.y = topbar ? m->wy + m->wh : m->wy;
129 + m->wy = m->topbar ? m->wy : m->wy + bh;
130 + }
131 + else
132 + eb.y = -bh;
133 }
134
135 Bool
136 @@ -2005,8 +2046,21 @@ updatetitle(Client *c) {
137
138 void
139 updatestatus(void) {
140 - if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
141 + char text[512];
142 + if(!gettextprop(root, XA_WM_NAME, text, sizeof(text))) {
143 strcpy(stext, "dwm-"VERSION);
144 + eb.text[0] = '\0';
145 + }
146 + else {
147 + char *e = strchr(text, ';');
148 + if(e) {
149 + *e = '\0'; e++;
150 + strncpy(eb.text, e, sizeof(eb.text)-1);
151 + }
152 + else
153 + eb.text[0] = '\0';
154 + strncpy(stext, text, sizeof(stext)-1);
155 + }
156 drawbar(selmon);
157 }
158