sites

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

dwm-nametag-6.1.diff (2336B)


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