sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-nametag-prepend-6.1.diff (2525B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 875885b..222745d 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -14,7 +14,10 @@ static const Bool showbar           = True;     /* False means no bar */
      6  static const Bool topbar            = True;     /* False means bottom bar */
      7  
      8  /* tagging */
      9 -static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
     10 +#define MAX_TAGNAME_LEN 14		/* excludes TAG_PREPEND */
     11 +#define TAG_PREPEND "%1i:"		/* formatted as 2 chars */
     12 +#define MAX_TAGLEN 16			/* altogether */
     13 +static char tags[][MAX_TAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
     14  
     15  static const Rule rules[] = {
     16  	/* xprop(1):
     17 @@ -79,6 +82,7 @@ static Key keys[] = {
     18  	{ MODKEY,                       XK_period, focusmon,       {.i = +1 } },
     19  	{ MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
     20  	{ MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
     21 +	{ MODKEY,                       XK_n,      nametag,        {0} },
     22  	TAGKEYS(                        XK_1,                      0)
     23  	TAGKEYS(                        XK_2,                      1)
     24  	TAGKEYS(                        XK_3,                      2)
     25 diff --git a/dwm.c b/dwm.c
     26 index 1bbb4b3..fefdd69 100644
     27 --- a/dwm.c
     28 +++ b/dwm.c
     29 @@ -183,6 +183,7 @@ static void maprequest(XEvent *e);
     30  static void monocle(Monitor *m);
     31  static void motionnotify(XEvent *e);
     32  static void movemouse(const Arg *arg);
     33 +static void nametag(const Arg *arg);
     34  static Client *nexttiled(Client *c);
     35  static void pop(Client *);
     36  static void propertynotify(XEvent *e);
     37 @@ -1174,6 +1175,34 @@ movemouse(const Arg *arg) {
     38  	}
     39  }
     40  
     41 +void
     42 +nametag(const Arg *arg) {
     43 +	char *p, name[MAX_TAGNAME_LEN];
     44 +	FILE *f;
     45 +	int i;
     46 +
     47 +	errno = 0; // popen(3p) says on failure it "may" set errno
     48 +	if(!(f = popen("dmenu < /dev/null", "r"))) {
     49 +		fprintf(stderr, "dwm: popen 'dmenu < /dev/null' failed%s%s\n", errno ? ": " : "", errno ? strerror(errno) : "");
     50 +		return;
     51 +	}
     52 +	if (!(p = fgets(name, MAX_TAGNAME_LEN, f)) && (i = errno) && ferror(f))
     53 +		fprintf(stderr, "dwm: fgets failed: %s\n", strerror(i));
     54 +	if (pclose(f) < 0)
     55 +		fprintf(stderr, "dwm: pclose failed: %s\n", strerror(errno));
     56 +	if(!p)
     57 +		return;
     58 +	if((p = strchr(name, '\n')))
     59 +		*p = '\0';
     60 +
     61 +	for(i = 0; i < LENGTH(tags); i++)
     62 +		if(selmon->tagset[selmon->seltags] & (1 << i)) {
     63 +			sprintf(tags[i], TAG_PREPEND, i+1);
     64 +			strcat(tags[i], name);
     65 +		}
     66 +	drawbars();
     67 +}
     68 +
     69  Client *
     70  nexttiled(Client *c) {
     71  	for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);