dwm-dwmblocks-6.2.diff (12401B)
1 diff -ruN dwm-6.2-ori/config.def.h dwm-6.2/config.def.h 2 --- dwm-6.2-ori/config.def.h 2019-02-02 18:25:28.000000000 +0530 3 +++ dwm-6.2/config.def.h 2020-08-18 03:43:45.933763395 +0530 4 @@ -12,10 +12,34 @@ 5 static const char col_gray3[] = "#bbbbbb"; 6 static const char col_gray4[] = "#eeeeee"; 7 static const char col_cyan[] = "#005577"; 8 +static const char col1[] = "#ffffff"; 9 +static const char col2[] = "#ffffff"; 10 +static const char col3[] = "#ffffff"; 11 +static const char col4[] = "#ffffff"; 12 +static const char col5[] = "#ffffff"; 13 +static const char col6[] = "#ffffff"; 14 +static const char col7[] = "#ffffff"; 15 +static const char col8[] = "#ffffff"; 16 +static const char col9[] = "#ffffff"; 17 +static const char col10[] = "#ffffff"; 18 +static const char col11[] = "#ffffff"; 19 +static const char col12[] = "#ffffff"; 20 static const char *colors[][3] = { 21 /* fg bg border */ 22 - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, 23 - [SchemeSel] = { col_gray4, col_cyan, col_cyan }, 24 + [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, 25 + [SchemeCol1] = { col1, col_gray1, col_gray2 }, 26 + [SchemeCol2] = { col2, col_gray1, col_gray2 }, 27 + [SchemeCol3] = { col3, col_gray1, col_gray2 }, 28 + [SchemeCol4] = { col4, col_gray1, col_gray2 }, 29 + [SchemeCol5] = { col5, col_gray1, col_gray2 }, 30 + [SchemeCol6] = { col6, col_gray1, col_gray2 }, 31 + [SchemeCol7] = { col7, col_gray1, col_gray2 }, 32 + [SchemeCol8] = { col8, col_gray1, col_gray2 }, 33 + [SchemeCol9] = { col8, col_gray1, col_gray2 }, 34 + [SchemeCol10] = { col10, col_gray1, col_gray2 }, 35 + [SchemeCol11] = { col11, col_gray1, col_gray2 }, 36 + [SchemeCol12] = { col12, col_gray1, col_gray2 }, 37 + [SchemeSel] = { col_gray4, col_cyan, col_cyan }, 38 }; 39 40 /* tagging */ 41 @@ -103,7 +127,9 @@ 42 { ClkLtSymbol, 0, Button1, setlayout, {0} }, 43 { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, 44 { ClkWinTitle, 0, Button2, zoom, {0} }, 45 - { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, 46 + { ClkStatusText, 0, Button1, sigdwmblocks, {.i = 1} }, 47 + { ClkStatusText, 0, Button2, sigdwmblocks, {.i = 2} }, 48 + { ClkStatusText, 0, Button3, sigdwmblocks, {.i = 3} }, 49 { ClkClientWin, MODKEY, Button1, movemouse, {0} }, 50 { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, 51 { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, 52 diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c 53 --- dwm-6.2-ori/dwm.c 2019-02-02 18:25:28.000000000 +0530 54 +++ dwm-6.2/dwm.c 2020-09-30 21:52:33.227950503 +0530 55 @@ -40,6 +40,8 @@ 56 #include <X11/extensions/Xinerama.h> 57 #endif /* XINERAMA */ 58 #include <X11/Xft/Xft.h> 59 +#include <fcntl.h> 60 +#include <sys/prctl.h> 61 62 #include "drw.h" 63 #include "util.h" 64 @@ -56,10 +58,15 @@ 65 #define HEIGHT(X) ((X)->h + 2 * (X)->bw) 66 #define TAGMASK ((1 << LENGTH(tags)) - 1) 67 #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) 68 +#define TTEXTW(X) (drw_fontset_getwidth(drw, (X))) 69 + 70 +#define DWMBLOCKSLOCKFILE "/tmp/dwmblocks.pid" 71 72 /* enums */ 73 -enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ 74 -enum { SchemeNorm, SchemeSel }; /* color schemes */ 75 +enum { CurNormal, CurHand, CurResize, CurMove, CurLast }; /* cursor */ 76 +enum { SchemeNorm, SchemeCol1, SchemeCol2, SchemeCol3, SchemeCol4, 77 + SchemeCol5, SchemeCol6, SchemeCol7, SchemeCol8, SchemeCol9, 78 + SchemeCol10, SchemeCol11, SchemeCol12, SchemeSel }; /* color schemes */ 79 enum { NetSupported, NetWMName, NetWMState, NetWMCheck, 80 NetWMFullscreen, NetActiveWindow, NetWMWindowType, 81 NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ 82 @@ -205,6 +212,7 @@ 83 static void seturgent(Client *c, int urg); 84 static void showhide(Client *c); 85 static void sigchld(int unused); 86 +static void sigdwmblocks(const Arg *arg); 87 static void spawn(const Arg *arg); 88 static void tag(const Arg *arg); 89 static void tagmon(const Arg *arg); 90 @@ -219,6 +227,7 @@ 91 static void updatebarpos(Monitor *m); 92 static void updatebars(void); 93 static void updateclientlist(void); 94 +static void updatedwmblockssig(int x); 95 static int updategeom(void); 96 static void updatenumlockmask(void); 97 static void updatesizehints(Client *c); 98 @@ -236,7 +245,11 @@ 99 100 /* variables */ 101 static const char broken[] = "broken"; 102 -static char stext[256]; 103 +static char stextc[256]; 104 +static char stexts[256]; 105 +static int wstext; 106 +static unsigned int dwmblockssig; 107 +static int statushandcursor; 108 static int screen; 109 static int sw, sh; /* X display screen geometry width, height */ 110 static int bh, blw = 0; /* bar geometry */ 111 @@ -416,7 +429,8 @@ 112 void 113 buttonpress(XEvent *e) 114 { 115 - unsigned int i, x, click; 116 + unsigned int i, click; 117 + int x; 118 Arg arg = {0}; 119 Client *c; 120 Monitor *m; 121 @@ -430,7 +444,7 @@ 122 focus(NULL); 123 } 124 if (ev->window == selmon->barwin) { 125 - i = x = 0; 126 + i = 0, x = 0; 127 do 128 x += TEXTW(tags[i]); 129 while (ev->x >= x && ++i < LENGTH(tags)); 130 @@ -439,10 +453,14 @@ 131 arg.ui = 1 << i; 132 } else if (ev->x < x + blw) 133 click = ClkLtSymbol; 134 - else if (ev->x > selmon->ww - TEXTW(stext)) 135 - click = ClkStatusText; 136 - else 137 - click = ClkWinTitle; 138 + else if (ev->x < selmon->ww - wstext) 139 + click = ClkWinTitle; 140 + else if (ev->x < selmon->ww - lrpad / 2 141 + && (x = selmon->ww - wstext + lrpad / 2 - ev->x) <= 0) { 142 + updatedwmblockssig(x); 143 + click = ClkStatusText; 144 + } else 145 + return; 146 } else if ((c = wintoclient(ev->window))) { 147 focus(c); 148 restack(selmon); 149 @@ -695,7 +713,7 @@ 150 void 151 drawbar(Monitor *m) 152 { 153 - int x, w, sw = 0; 154 + int x, w; 155 int boxs = drw->fonts->h / 9; 156 int boxw = drw->fonts->h / 6 + 2; 157 unsigned int i, occ = 0, urg = 0; 158 @@ -703,9 +721,30 @@ 159 160 /* draw status first so it can be overdrawn by tags later */ 161 if (m == selmon) { /* status is only drawn on selected monitor */ 162 - drw_setscheme(drw, scheme[SchemeNorm]); 163 - sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ 164 - drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0); 165 + char *ts = stextc; 166 + char *tp = stextc; 167 + char ctmp; 168 + 169 + drw_setscheme(drw, scheme[SchemeNorm]); 170 + x = drw_text(drw, m->ww - wstext, 0, lrpad / 2, bh, 0, "", 0); /* to keep left padding clean */ 171 + for (;;) { 172 + if ((unsigned char)*ts > LENGTH(colors) + 10) { 173 + ts++; 174 + continue; 175 + } 176 + ctmp = *ts; 177 + *ts = '\0'; 178 + if (*tp != '\0') 179 + x = drw_text(drw, x, 0, TTEXTW(tp), bh, 0, tp, 0); 180 + if (ctmp == '\0') 181 + break; 182 + /* - 11 to compensate for + 10 above */ 183 + drw_setscheme(drw, scheme[ctmp - 11]); 184 + *ts = ctmp; 185 + tp = ++ts; 186 + } 187 + drw_setscheme(drw, scheme[SchemeNorm]); 188 + drw_text(drw, x, 0, m->ww - x, bh, 0, "", 0); /* to keep right padding clean */ 189 } 190 191 for (c = m->clients; c; c = c->next) { 192 @@ -728,7 +767,7 @@ 193 drw_setscheme(drw, scheme[SchemeNorm]); 194 x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); 195 196 - if ((w = m->ww - sw - x) > bh) { 197 + if ((w = m->ww - wstext - x) > bh) { 198 if (m->sel) { 199 drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); 200 drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); 201 @@ -1122,8 +1161,20 @@ 202 Monitor *m; 203 XMotionEvent *ev = &e->xmotion; 204 205 - if (ev->window != root) 206 + if (ev->window != root) { 207 + if (ev->window == selmon->barwin) { 208 + int x; 209 + 210 + if (ev->x < selmon->ww - lrpad / 2 211 + && (x = selmon->ww - wstext + lrpad / 2 - ev->x) <= 0) 212 + updatedwmblockssig(x); 213 + else if (statushandcursor) { 214 + statushandcursor = 0; 215 + XDefineCursor(dpy, selmon->barwin, cursor[CurNormal]->cursor); 216 + } 217 + } 218 return; 219 + } 220 if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) { 221 unfocus(selmon->sel, 1); 222 selmon = m; 223 @@ -1564,6 +1615,7 @@ 224 netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); 225 /* init cursors */ 226 cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr); 227 + cursor[CurHand] = drw_cur_create(drw, XC_hand2); 228 cursor[CurResize] = drw_cur_create(drw, XC_sizing); 229 cursor[CurMove] = drw_cur_create(drw, XC_fleur); 230 /* init appearance */ 231 @@ -1637,6 +1689,28 @@ 232 } 233 234 void 235 +sigdwmblocks(const Arg *arg) 236 +{ 237 + int fd; 238 + struct flock fl; 239 + union sigval sv; 240 + 241 + if (!dwmblockssig) 242 + return; 243 + sv.sival_int = (dwmblockssig << 8) | arg->i; 244 + fd = open(DWMBLOCKSLOCKFILE, O_RDONLY); 245 + if (fd == -1) 246 + return; 247 + fl.l_type = F_WRLCK; 248 + fl.l_start = 0; 249 + fl.l_whence = SEEK_SET; 250 + fl.l_len = 0; 251 + if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type == F_UNLCK) 252 + return; 253 + sigqueue(fl.l_pid, SIGRTMIN, sv); 254 +} 255 + 256 +void 257 spawn(const Arg *arg) 258 { 259 if (arg->v == dmenucmd) 260 @@ -1805,7 +1879,7 @@ 261 XSetWindowAttributes wa = { 262 .override_redirect = True, 263 .background_pixmap = ParentRelative, 264 - .event_mask = ButtonPressMask|ExposureMask 265 + .event_mask = ButtonPressMask|ExposureMask|PointerMotionMask 266 }; 267 XClassHint ch = {"dwm", "dwm"}; 268 for (m = mons; m; m = m->next) { 269 @@ -1847,6 +1921,42 @@ 270 (unsigned char *) &(c->win), 1); 271 } 272 273 +void 274 +updatedwmblockssig(int x) 275 +{ 276 + char *ts = stexts; 277 + char *tp = stexts; 278 + char ctmp; 279 + 280 + while (*ts != '\0') { 281 + if ((unsigned char)*ts > 10) { 282 + ts++; 283 + continue; 284 + } 285 + ctmp = *ts; 286 + *ts = '\0'; 287 + x += TTEXTW(tp); 288 + *ts = ctmp; 289 + if (x >= 0) { 290 + if (ctmp == 10) 291 + goto cursorondelimiter; 292 + if (!statushandcursor) { 293 + statushandcursor = 1; 294 + XDefineCursor(dpy, selmon->barwin, cursor[CurHand]->cursor); 295 + } 296 + dwmblockssig = ctmp; 297 + return; 298 + } 299 + tp = ++ts; 300 + } 301 +cursorondelimiter: 302 + if (statushandcursor) { 303 + statushandcursor = 0; 304 + XDefineCursor(dpy, selmon->barwin, cursor[CurNormal]->cursor); 305 + } 306 + dwmblockssig = 0; 307 +} 308 + 309 int 310 updategeom(void) 311 { 312 @@ -1987,9 +2097,27 @@ 313 void 314 updatestatus(void) 315 { 316 - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) 317 - strcpy(stext, "dwm-"VERSION); 318 - drawbar(selmon); 319 + char rawstext[256]; 320 + 321 + if (gettextprop(root, XA_WM_NAME, rawstext, sizeof rawstext)) { 322 + char stextt[256]; 323 + char *stc = stextc, *sts = stexts, *stt = stextt; 324 + 325 + for (char *rt = rawstext; *rt != '\0'; rt++) 326 + if ((unsigned char)*rt >= ' ') 327 + *(stc++) = *(sts++) = *(stt++) = *rt; 328 + else if ((unsigned char)*rt > 10) 329 + *(stc++) = *rt; 330 + else 331 + *(sts++) = *rt; 332 + *stc = *sts = *stt = '\0'; 333 + wstext = TEXTW(stextt); 334 + } else { 335 + strcpy(stextc, "dwm-"VERSION); 336 + strcpy(stexts, stextc); 337 + wstext = TEXTW(stextc); 338 + } 339 + drawbar(selmon); 340 } 341 342 void