Re: [dwm] clientspertag status message

From: Ritesh Kumar <ritesh_AT_cs.unc.edu>
Date: Fri, 26 Oct 2007 05:32:32 -0400

Okay, I revisited the patch and made some improvements.
 - variable names should be saner.
 - the status bar now shows the number of windows hidden instead of
the actual cpt value.

_r

diff -r 32c4d4563805 config.h
--- a/config.h Thu Oct 25 19:24:28 2007 -0400
+++ b/config.h Fri Oct 26 05:08:55 2007 -0400
@@ -37,6 +37,9 @@ Layout layouts[] = {
        { "[]=", tile },
        { "><>", floating },
 };
+
+/* Status text */
+char* statusbar[] = { cptstext, inputtext };

 /* key definitions */
 #define MODKEY Mod1Mask
diff -r 32c4d4563805 dwm.c
--- a/dwm.c Thu Oct 25 19:24:28 2007 -0400
+++ b/dwm.c Fri Oct 26 05:22:22 2007 -0400
@@ -167,6 +167,7 @@ void setclientstate(Client *c, long stat
 void setclientstate(Client *c, long state);
 void setlayout(const char *arg);
 void setmwfact(const char *arg);
+void setstext(void);
 void setup(void);
 void spawn(const char *arg);
 void tag(const char *arg);
@@ -192,7 +193,8 @@ void zoom(const char *arg);
 void zoom(const char *arg);

 /* variables */
-char stext[256];
+char inputtext[256];
+char stext[512];
 double mwfact;
 int screen, sx, sy, sw, sh, wax, way, waw, wah;
 int (*xerrorxlib)(Display *, XErrorEvent *);
@@ -551,6 +553,7 @@ drawbar(void) {
        dc.w = blw;
        drawtext(layouts[ltidx].symbol, dc.norm);
        x = dc.x + dc.w;
+ setstext();
        dc.w = textw(stext);
        dc.x = sw - dc.w;
        if(dc.x < x) {
@@ -1312,21 +1315,21 @@ run(void) {
                        eprint("select failed\n");
                }
                if(FD_ISSET(STDIN_FILENO, &rd)) {
- switch(r = read(STDIN_FILENO, stext, sizeof
stext - 1)) {
+ switch(r = read(STDIN_FILENO, inputtext,
sizeof inputtext - 1)) {
                        case -1:
- strncpy(stext, strerror(errno), sizeof
stext - 1);
- stext[sizeof stext - 1] = '\0';
+ strncpy(inputtext, strerror(errno),
sizeof inputtext - 1);
+ inputtext[sizeof inputtext - 1] = '\0';
                                readin = False;
                                break;
                        case 0:
- strncpy(stext, "EOF", 4);
+ strncpy(inputtext, "EOF", 4);
                                readin = False;
                                break;
                        default:
- for(stext[r] = '\0', p = stext +
strlen(stext) - 1; p >= stext && *p == '\n'; *
- for(; p >= stext && *p != '\n'; --p);
- if(p > stext)
- strncpy(stext, p + 1, sizeof stext);
+ for(inputtext[r] = '\0', p = inputtext
+ strlen(inputtext) - 1; p >= inputtext
+ for(; p >= inputtext && *p != '\n'; --p);
+ if(p > inputtext)
+ strncpy(inputtext, p + 1,
sizeof inputtext);
                        }
                        drawbar();
                }
@@ -1418,6 +1421,14 @@ setmwfact(const char *arg) {
 }

 void
+setstext(void) {
+ int i;
+ stext[0] = '\0';
+ for(i=0; i<sizeof(statusbar)/sizeof(char*); i++)
+ strncat(stext, statusbar[i], sizeof(stext) - strlen(stext));
+}
+
+void
 setup(void) {
        int d;
        unsigned int i, j, mask;
@@ -1498,7 +1509,7 @@ setup(void) {
        XDefineCursor(dpy, barwin, cursor[CurNormal]);
        updatebarpos();
        XMapRaised(dpy, barwin);
- strcpy(stext, "dwm-"VERSION);
+ strcpy(inputtext, "dwm-"VERSION);
        dc.drawable = XCreatePixmap(dpy, root, sw, bh,
DefaultDepth(dpy, screen));
        dc.gc = XCreateGC(dpy, root, 0, 0);
        XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
diff -r 32c4d4563805 nmaster.c
--- a/nmaster.c Thu Oct 25 19:24:28 2007 -0400
+++ b/nmaster.c Fri Oct 26 05:20:54 2007 -0400
@@ -69,6 +69,8 @@ Layout layouts[] = {
 #endif

 int cpt = -1;
+char cptstext[8];
+
 void clientspertag(const char *arg) {
         if (arg[0]=='^') {
                 if (cpt==-1) cpt = atoi(arg+1);
@@ -77,6 +79,18 @@ void clientspertag(const char *arg) {
         arrange();
 }

+int getclientspertag(int n)
+{
+ if(cpt!=-1 && n>cpt){
+ snprintf(cptstext, 8, "{%d} ", n-cpt);
+ return cpt;
+ }
+
+ cptstext[0] = '\0';
+ drawbar();
+ return n;
+}
+
 #ifdef NMASTER
 int nmaster = NMASTER;
 void
@@ -87,7 +101,7 @@ ntile(void) {
        for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
                n++;

- if (cpt!=-1 && n>cpt) n = cpt;
+ n = getclientspertag(n);

        /* window geoms */
        mh = (n <= nmaster) ? wah / (n > 0 ? n : 1) : wah / nmaster;
@@ -136,7 +150,7 @@ dntile(void) {

        for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
                n++;
- if (cpt!=-1 && n>cpt) n = cpt;
+ n = getclientspertag(n);

        /* dynamic nmaster */
        if (n<5) inc = 0;
@@ -266,7 +280,7 @@ tilecols(void) {
        else
                rows = nrows;

- if (cpt!=-1 && n>cpt) n = cpt;
+ n = getclientspertag(n);

        /* window geoms */
        mh = (n <= nmaster) ? wah / (n > 0 ? n : 1) : wah / nmaster;

On 10/25/07, Ritesh Kumar <ritesh_AT_cs.unc.edu> wrote:
> Hi,
> I am new to the list, so hi again :)
> I developed a small patch for dwm with pancake's clientspertag to
> show if clientspertag is active. This basically adds additional status
> text of the form '{n}' to the current status text where n is the
> number of clientspertag currently active.
> However, I think a flexible way to show status messages could be
> used by additional patches to show some textual data on the dwm status
> bar. clientspertag seemed like a good candidate but I don't know about
> any others. I was curious to know what you guys think.
> And thanks for developing dwm... its truly wonderful :)
>
> _r
>
>
> diff -r 32c4d4563805 config.h
> --- a/config.h Thu Oct 25 19:24:28 2007 -0400
> +++ b/config.h Thu Oct 25 20:28:00 2007 -0400
> @@ -37,6 +37,9 @@ Layout layouts[] = {
> { "[]=", tile },
> { "><>", floating },
> };
> +
> +/* Status text */
> +char* status_text[] = { cpt_stext, stext };
>
> /* key definitions */
> #define MODKEY Mod1Mask
> diff -r 32c4d4563805 dwm.c
> --- a/dwm.c Thu Oct 25 19:24:28 2007 -0400
> +++ b/dwm.c Thu Oct 25 22:36:55 2007 -0400
> @@ -167,6 +167,7 @@ void setclientstate(Client *c, long stat
> void setclientstate(Client *c, long state);
> void setlayout(const char *arg);
> void setmwfact(const char *arg);
> +void setitext(void);
> void setup(void);
> void spawn(const char *arg);
> void tag(const char *arg);
> @@ -193,6 +194,7 @@ void zoom(const char *arg);
>
> /* variables */
> char stext[256];
> +char itext[512];
> double mwfact;
> int screen, sx, sy, sw, sh, wax, way, waw, wah;
> int (*xerrorxlib)(Display *, XErrorEvent *);
> @@ -551,13 +553,14 @@ drawbar(void) {
> dc.w = blw;
> drawtext(layouts[ltidx].symbol, dc.norm);
> x = dc.x + dc.w;
> - dc.w = textw(stext);
> + setitext();
> + dc.w = textw(itext);
> dc.x = sw - dc.w;
> if(dc.x < x) {
> dc.x = x;
> dc.w = sw - x;
> }
> - drawtext(stext, dc.norm);
> + drawtext(itext, dc.norm);
> if((dc.w = dc.x - x) > bh) {
> dc.x = x;
> if(sel) {
> @@ -1418,6 +1421,14 @@ setmwfact(const char *arg) {
> }
>
> void
> +setitext(void) {
> + int i;
> + itext[0] = '\0';
> + for(i=0; i<sizeof(status_text)/sizeof(char*); i++)
> + strncat(itext, status_text[i], sizeof(itext) - strlen(itext));
> +}
> +
> +void
> setup(void) {
> int d;
> unsigned int i, j, mask;
> diff -r 32c4d4563805 nmaster.c
> --- a/nmaster.c Thu Oct 25 19:24:28 2007 -0400
> +++ b/nmaster.c Thu Oct 25 22:33:05 2007 -0400
> @@ -69,11 +69,18 @@ Layout layouts[] = {
> #endif
>
> int cpt = -1;
> +char cpt_stext[8];
> +
> void clientspertag(const char *arg) {
> if (arg[0]=='^') {
> if (cpt==-1) cpt = atoi(arg+1);
> else cpt = -1;
> } else cpt = atoi(arg);
> + if(cpt == -1)
> + cpt_stext[0] = '\0';
> + else
> + snprintf(cpt_stext, 8, "{%d} ", cpt);
> + drawbar();
> arrange();
> }
>
Received on Fri Oct 26 2007 - 11:32:36 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:02:14 UTC