dotfiles

personal configuration files and scripts
git clone https://tongong.net/git/dotfiles.git
Log | Files | Refs | README

dwm-dsblocks-6.2.diff (14459B)


      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-12-27 19:45:35.127385861 +0530
      4 @@ -12,10 +12,26 @@
      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 +
     15 +enum { SchemeNorm, SchemeCol1, SchemeCol2, SchemeCol3, SchemeCol4,
     16 +       SchemeCol5, SchemeCol6, SchemeSel }; /* color schemes */
     17 +
     18  static const char *colors[][3]      = {
     19  	/*               fg         bg         border   */
     20 -	[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
     21 -	[SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
     22 +	[SchemeNorm]  = { col_gray3, col_gray1, col_gray2 },
     23 +	[SchemeCol1]  = { col1,      col_gray1, col_gray2 },
     24 +	[SchemeCol2]  = { col2,      col_gray1, col_gray2 },
     25 +	[SchemeCol3]  = { col3,      col_gray1, col_gray2 },
     26 +	[SchemeCol4]  = { col4,      col_gray1, col_gray2 },
     27 +	[SchemeCol5]  = { col5,      col_gray1, col_gray2 },
     28 +	[SchemeCol6]  = { col6,      col_gray1, col_gray2 },
     29 +	[SchemeSel]   = { col_gray4, col_cyan,  col_cyan  },
     30  };
     31  
     32  /* tagging */
     33 @@ -103,7 +119,9 @@
     34  	{ ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
     35  	{ ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
     36  	{ ClkWinTitle,          0,              Button2,        zoom,           {0} },
     37 -	{ ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
     38 +	{ ClkStatusText,        0,              Button1,        sigdsblocks,    {.i = 1} },
     39 +	{ ClkStatusText,        0,              Button2,        sigdsblocks,    {.i = 2} },
     40 +	{ ClkStatusText,        0,              Button3,        sigdsblocks,    {.i = 3} },
     41  	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
     42  	{ ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
     43  	{ ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
     44 diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c
     45 --- dwm-6.2-ori/dwm.c	2019-02-02 18:25:28.000000000 +0530
     46 +++ dwm-6.2/dwm.c	2021-01-25 16:29:30.411870905 +0530
     47 @@ -40,6 +40,7 @@
     48  #include <X11/extensions/Xinerama.h>
     49  #endif /* XINERAMA */
     50  #include <X11/Xft/Xft.h>
     51 +#include <fcntl.h>
     52  
     53  #include "drw.h"
     54  #include "util.h"
     55 @@ -56,10 +57,16 @@
     56  #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
     57  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
     58  #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
     59 +#define TTEXTW(X)               (drw_fontset_getwidth(drw, (X)))
     60 +
     61 +#define STATUSLENGTH            256
     62 +#define DSBLOCKSLOCKFILE        "/tmp/dsblocks.pid"
     63 +#define DELIMITERENDCHAR        10
     64 +#define LSPAD                   (lrpad / 2) /* padding on left side of status text */
     65 +#define RSPAD                   (lrpad / 2) /* padding on right side of status text */
     66  
     67  /* enums */
     68 -enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
     69 -enum { SchemeNorm, SchemeSel }; /* color schemes */
     70 +enum { CurNormal, CurHand, CurResize, CurMove, CurLast }; /* cursor */
     71  enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
     72         NetWMFullscreen, NetActiveWindow, NetWMWindowType,
     73         NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
     74 @@ -124,6 +131,7 @@
     75  	unsigned int tagset[2];
     76  	int showbar;
     77  	int topbar;
     78 +        int statushandcursor;
     79  	Client *clients;
     80  	Client *sel;
     81  	Client *stack;
     82 @@ -205,6 +213,7 @@
     83  static void seturgent(Client *c, int urg);
     84  static void showhide(Client *c);
     85  static void sigchld(int unused);
     86 +static void sigdsblocks(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 +228,7 @@
     91  static void updatebarpos(Monitor *m);
     92  static void updatebars(void);
     93  static void updateclientlist(void);
     94 +static void updatedsblockssig(int x);
     95  static int updategeom(void);
     96  static void updatenumlockmask(void);
     97  static void updatesizehints(Client *c);
     98 @@ -236,12 +246,15 @@
     99  
    100  /* variables */
    101  static const char broken[] = "broken";
    102 -static char stext[256];
    103 +static char stextc[STATUSLENGTH];
    104 +static char stexts[STATUSLENGTH];
    105  static int screen;
    106  static int sw, sh;           /* X display screen geometry width, height */
    107 -static int bh, blw = 0;      /* bar geometry */
    108 +static int bh, blw, ble;     /* bar geometry */
    109 +static int wstext;           /* width of status text */
    110  static int lrpad;            /* sum of left and right padding for text */
    111  static int (*xerrorxlib)(Display *, XErrorEvent *);
    112 +static unsigned int dsblockssig;
    113  static unsigned int numlockmask = 0;
    114  static void (*handler[LASTEvent]) (XEvent *) = {
    115  	[ButtonPress] = buttonpress,
    116 @@ -416,13 +429,13 @@
    117  void
    118  buttonpress(XEvent *e)
    119  {
    120 -	unsigned int i, x, click;
    121 +        int i, x;
    122 +        unsigned int click;
    123  	Arg arg = {0};
    124  	Client *c;
    125  	Monitor *m;
    126  	XButtonPressedEvent *ev = &e->xbutton;
    127  
    128 -	click = ClkRootWin;
    129  	/* focus monitor if necessary */
    130  	if ((m = wintomon(ev->window)) && m != selmon) {
    131  		unfocus(selmon->sel, 1);
    132 @@ -430,25 +443,29 @@
    133  		focus(NULL);
    134  	}
    135  	if (ev->window == selmon->barwin) {
    136 -		i = x = 0;
    137 -		do
    138 -			x += TEXTW(tags[i]);
    139 -		while (ev->x >= x && ++i < LENGTH(tags));
    140 -		if (i < LENGTH(tags)) {
    141 -			click = ClkTagBar;
    142 -			arg.ui = 1 << i;
    143 -		} else if (ev->x < x + blw)
    144 -			click = ClkLtSymbol;
    145 -		else if (ev->x > selmon->ww - TEXTW(stext))
    146 -			click = ClkStatusText;
    147 -		else
    148 -			click = ClkWinTitle;
    149 +                if (ev->x < ble - blw) {
    150 +                        i = -1, x = -ev->x;
    151 +                        do
    152 +                                x += TEXTW(tags[++i]);
    153 +                        while (x <= 0);
    154 +                        click = ClkTagBar;
    155 +                        arg.ui = 1 << i;
    156 +                } else if (ev->x < ble)
    157 +                        click = ClkLtSymbol;
    158 +                else if (ev->x < selmon->ww - wstext)
    159 +                        click = ClkWinTitle;
    160 +                else if ((x = selmon->ww - RSPAD - ev->x) > 0 && (x -= wstext - LSPAD - RSPAD) <= 0) {
    161 +                        updatedsblockssig(x);
    162 +                        click = ClkStatusText;
    163 +                } else
    164 +                        return;
    165  	} else if ((c = wintoclient(ev->window))) {
    166  		focus(c);
    167  		restack(selmon);
    168  		XAllowEvents(dpy, ReplayPointer, CurrentTime);
    169  		click = ClkClientWin;
    170 -	}
    171 +	} else
    172 +                click = ClkRootWin;
    173  	for (i = 0; i < LENGTH(buttons); i++)
    174  		if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
    175  		&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
    176 @@ -695,7 +712,7 @@
    177  void
    178  drawbar(Monitor *m)
    179  {
    180 -	int x, w, sw = 0;
    181 +	int x, w;
    182  	int boxs = drw->fonts->h / 9;
    183  	int boxw = drw->fonts->h / 6 + 2;
    184  	unsigned int i, occ = 0, urg = 0;
    185 @@ -703,9 +720,32 @@
    186  
    187  	/* draw status first so it can be overdrawn by tags later */
    188  	if (m == selmon) { /* status is only drawn on selected monitor */
    189 -		drw_setscheme(drw, scheme[SchemeNorm]);
    190 -		sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
    191 -		drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0);
    192 +                char *stc = stextc;
    193 +                char *stp = stextc;
    194 +                char tmp;
    195 +
    196 +                drw_setscheme(drw, scheme[SchemeNorm]);
    197 +                x = m->ww - wstext;
    198 +                drw_rect(drw, x, 0, LSPAD, bh, 1, 1); x += LSPAD; /* to keep left padding clean */
    199 +                for (;;) {
    200 +                        if ((unsigned char)*stc >= ' ') {
    201 +                                stc++;
    202 +                                continue;
    203 +                        }
    204 +                        tmp = *stc;
    205 +                        if (stp != stc) {
    206 +                                *stc = '\0';
    207 +                                x = drw_text(drw, x, 0, TTEXTW(stp), bh, 0, stp, 0);
    208 +                        }
    209 +                        if (tmp == '\0')
    210 +                                break;
    211 +                        if (tmp - DELIMITERENDCHAR - 1 < LENGTH(colors))
    212 +                                drw_setscheme(drw, scheme[tmp - DELIMITERENDCHAR - 1]);
    213 +                        *stc = tmp;
    214 +                        stp = ++stc;
    215 +                }
    216 +                drw_setscheme(drw, scheme[SchemeNorm]);
    217 +                drw_rect(drw, x, 0, m->ww - x, bh, 1, 1); /* to keep right padding clean */
    218  	}
    219  
    220  	for (c = m->clients; c; c = c->next) {
    221 @@ -724,11 +764,17 @@
    222  				urg & 1 << i);
    223  		x += w;
    224  	}
    225 -	w = blw = TEXTW(m->ltsymbol);
    226 +	w = TEXTW(m->ltsymbol);
    227  	drw_setscheme(drw, scheme[SchemeNorm]);
    228  	x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
    229  
    230 -	if ((w = m->ww - sw - x) > bh) {
    231 +        if (m == selmon) {
    232 +                blw = w, ble = x;
    233 +                w = m->ww - wstext - x;
    234 +        } else
    235 +                w = m->ww - x;
    236 +
    237 +	if (w > bh) {
    238  		if (m->sel) {
    239  			drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
    240  			drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
    241 @@ -1119,17 +1165,24 @@
    242  motionnotify(XEvent *e)
    243  {
    244  	static Monitor *mon = NULL;
    245 +        int x;
    246  	Monitor *m;
    247  	XMotionEvent *ev = &e->xmotion;
    248  
    249 -	if (ev->window != root)
    250 -		return;
    251 -	if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
    252 -		unfocus(selmon->sel, 1);
    253 -		selmon = m;
    254 -		focus(NULL);
    255 -	}
    256 -	mon = m;
    257 +        if (ev->window == root) {
    258 +                if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
    259 +                        unfocus(selmon->sel, 1);
    260 +                        selmon = m;
    261 +                        focus(NULL);
    262 +                }
    263 +                mon = m;
    264 +        } else if (ev->window == selmon->barwin && (x = selmon->ww - RSPAD - ev->x) > 0
    265 +                                                && (x -= wstext - LSPAD - RSPAD) <= 0)
    266 +                updatedsblockssig(x);
    267 +        else if (selmon->statushandcursor) {
    268 +                selmon->statushandcursor = 0;
    269 +                XDefineCursor(dpy, selmon->barwin, cursor[CurNormal]->cursor);
    270 +        }
    271  }
    272  
    273  void
    274 @@ -1564,6 +1617,7 @@
    275  	netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
    276  	/* init cursors */
    277  	cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
    278 +        cursor[CurHand] = drw_cur_create(drw, XC_hand2);
    279  	cursor[CurResize] = drw_cur_create(drw, XC_sizing);
    280  	cursor[CurMove] = drw_cur_create(drw, XC_fleur);
    281  	/* init appearance */
    282 @@ -1637,6 +1691,40 @@
    283  }
    284  
    285  void
    286 +sigdsblocks(const Arg *arg)
    287 +{
    288 +        static int fd = -1;
    289 +        struct flock fl;
    290 +        union sigval sv;
    291 +
    292 +        if (!dsblockssig)
    293 +                return;
    294 +        fl.l_type = F_WRLCK;
    295 +        fl.l_whence = SEEK_SET;
    296 +        fl.l_start = 0;
    297 +        fl.l_len = 0;
    298 +        if (fd == -1) {
    299 +                if ((fd = open(DSBLOCKSLOCKFILE, O_RDONLY)) == -1)
    300 +                        return;
    301 +                if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type == F_UNLCK)
    302 +                        return;
    303 +        } else {
    304 +                if (fcntl(fd, F_GETLK, &fl) == -1)
    305 +                        return;
    306 +                if (fl.l_type == F_UNLCK) {
    307 +                        close(fd);
    308 +                        if ((fd = open(DSBLOCKSLOCKFILE, O_RDONLY)) == -1)
    309 +                                return;
    310 +                        fl.l_type = F_WRLCK;
    311 +                        if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type == F_UNLCK)
    312 +                                return;
    313 +                }
    314 +        }
    315 +        sv.sival_int = (dsblockssig << 8) | arg->i;
    316 +        sigqueue(fl.l_pid, SIGRTMIN, sv);
    317 +}
    318 +
    319 +void
    320  spawn(const Arg *arg)
    321  {
    322  	if (arg->v == dmenucmd)
    323 @@ -1805,7 +1893,7 @@
    324  	XSetWindowAttributes wa = {
    325  		.override_redirect = True,
    326  		.background_pixmap = ParentRelative,
    327 -		.event_mask = ButtonPressMask|ExposureMask
    328 +		.event_mask = ButtonPressMask|ExposureMask|PointerMotionMask
    329  	};
    330  	XClassHint ch = {"dwm", "dwm"};
    331  	for (m = mons; m; m = m->next) {
    332 @@ -1847,6 +1935,41 @@
    333  				(unsigned char *) &(c->win), 1);
    334  }
    335  
    336 +void
    337 +updatedsblockssig(int x)
    338 +{
    339 +        char *sts = stexts;
    340 +        char *stp = stexts;
    341 +        char tmp;
    342 +
    343 +        while (*sts != '\0') {
    344 +                if ((unsigned char)*sts >= ' ') {
    345 +                        sts++;
    346 +                        continue;
    347 +                }
    348 +                tmp = *sts;
    349 +                *sts = '\0';
    350 +                x += TTEXTW(stp);
    351 +                *sts = tmp;
    352 +                if (x > 0) {
    353 +                        if (tmp == DELIMITERENDCHAR)
    354 +                                break;
    355 +                        if (!selmon->statushandcursor) {
    356 +                                selmon->statushandcursor = 1;
    357 +                                XDefineCursor(dpy, selmon->barwin, cursor[CurHand]->cursor);
    358 +                        }
    359 +                        dsblockssig = tmp;
    360 +                        return;
    361 +                }
    362 +                stp = ++sts;
    363 +        }
    364 +        if (selmon->statushandcursor) {
    365 +                selmon->statushandcursor = 0;
    366 +                XDefineCursor(dpy, selmon->barwin, cursor[CurNormal]->cursor);
    367 +        }
    368 +        dsblockssig = 0;
    369 +}
    370 +
    371  int
    372  updategeom(void)
    373  {
    374 @@ -1987,9 +2110,27 @@
    375  void
    376  updatestatus(void)
    377  {
    378 -	if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
    379 -		strcpy(stext, "dwm-"VERSION);
    380 -	drawbar(selmon);
    381 +	char rawstext[STATUSLENGTH];
    382 +
    383 +	if (gettextprop(root, XA_WM_NAME, rawstext, sizeof rawstext)) {
    384 +                char stextp[STATUSLENGTH];
    385 +                char *stp = stextp, *stc = stextc, *sts = stexts;
    386 +
    387 +                for (char *rst = rawstext; *rst != '\0'; rst++)
    388 +                        if ((unsigned char)*rst >= ' ')
    389 +                                *(stp++) = *(stc++) = *(sts++) = *rst;
    390 +                        else if ((unsigned char)*rst > DELIMITERENDCHAR)
    391 +                                *(stc++) = *rst;
    392 +                        else
    393 +                                *(sts++) = *rst;
    394 +                *stp = *stc = *sts = '\0';
    395 +                wstext = TTEXTW(stextp) + LSPAD + RSPAD;
    396 +        } else {
    397 +                strcpy(stextc, "dwm-"VERSION);
    398 +                strcpy(stexts, stextc);
    399 +                wstext = TTEXTW(stextc) + LSPAD + RSPAD;
    400 +        }
    401 +        drawbar(selmon);
    402  }
    403  
    404  void