You are not logged in.

#1 2011-08-17 17:07:45

BaconPie
Member
Registered: 2010-08-11
Posts: 209

DWM 5.9 statuscolors patch failing

Is there a tweaked statuscolors patch to work with dwm-5.9? When I apply the 5.8.2 patch I get the following output:

$ patch -p1 < ../../dwm-5.8.2-statuscolors.diff 
patching file config.def.h
patching file dwm.c
Hunk #4 succeeded at 737 (offset 40 lines).
Hunk #5 succeeded at 753 (offset 40 lines).
Hunk #6 FAILED at 740.
Hunk #7 FAILED at 761.
Hunk #8 succeeded at 811 (offset 30 lines).
Hunk #9 FAILED at 830.
Hunk #10 succeeded at 1137 with fuzz 1 (offset -2 lines).
Hunk #11 succeeded at 1550 (offset 6 lines).
Hunk #12 succeeded at 1715 (offset 5 lines).
3 out of 12 hunks FAILED -- saving rejects to file dwm.c.rej

The reject file is:

--- dwm.c       2010-11-03 20:36:50.000000000 +0100
+++ dwm.c       2010-06-04 12:39:15.000000000 +0200
@@ -740,42 +740,12 @@
 }
 
 void
-drawcoloredtext(char *text) {
-       Bool first=True;
-       char *buf = text, *ptr = buf, c = 1;
-       unsigned long *col = dc.colors[0];
-       int i, ox = dc.x;
-
-       while( *ptr ) {
-               for( i = 0; *ptr < 0 || *ptr > NUMCOLORS; i++, ptr++);
-               if( !*ptr ) break;
-               c=*ptr;
-               *ptr=0;
-               if( i ) {
-                       dc.w = selmon->ww - dc.x;
-                       drawtext(buf, col, first);
-                       dc.x += textnw(buf, i) + textnw(&c,1);
-                       if( first ) dc.x += ( dc.font.ascent + dc.font.descent ) / 2;
-                       first = False;
-               } else if( first ) {
-                       ox = dc.x += textnw(&c,1);
-               }
-               *ptr = c;
-               col = dc.colors[ c-1 ];
-               buf = ++ptr;
-       }
-       if( !first ) dc.x-=(dc.font.ascent+dc.font.descent)/2;
-       drawtext(buf, col, True);
-       dc.x = ox;
-}
-
-void
-drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
+drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
        int x;
        XGCValues gcv;
        XRectangle r = { dc.x, dc.y, dc.w, dc.h };
 
-       gcv.foreground = col[ ColFG ];
+       gcv.foreground = col[invert ? ColBG : ColFG];
        XChangeGC(dpy, dc.gc, GCForeground, &gcv);
        x = (dc.font.ascent + dc.font.descent + 2) / 4;
        r.x = dc.x + 1;
@@ -791,18 +761,18 @@
 }
 
 void
-drawtext(const char *text, unsigned long col[ColLast], Bool pad) {
+drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
        char buf[256];
        int i, x, y, h, len, olen;
        XRectangle r = { dc.x, dc.y, dc.w, dc.h };
 
-       XSetForeground(dpy, dc.gc, col[ ColBG ]);
+       XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
        XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
        if(!text)
                return;
        olen = strlen(text);

-       h = pad ? (dc.font.ascent + dc.font.descent) : 0;
-       y = dc.y + ((dc.h + dc.font.ascent - dc.font.descent) / 2);
+       h = dc.font.ascent + dc.font.descent;
+       y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
        x = dc.x + (h / 2);
        /* shorten text if necessary */
        for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
@@ -860,7 +830,7 @@
                detachstack(c);
                attachstack(c);
                grabbuttons(c, True);
-               XSetWindowBorder(dpy, c->win, dc.colors[1][ColBorder]);
+               XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
                XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
        }
        else

I'm assuming some things were changed in the 5.8.2 -> 5.9 transition (obviously tongue) which is my explanation for the patch failing to apply. I'd go in and do it manually but, before I go back to the stone age, I'd like to know if there is an easier solution.

Has anyone seen/got a 5.9 version of this patch?

Thanks.

Solution is in post 2.

Last edited by BaconPie (2011-08-17 22:00:55)

Offline

#2 2011-08-17 17:46:55

Meyithi
Member
From: Wirral, UK
Registered: 2009-06-21
Posts: 550
Website

Re: DWM 5.9 statuscolors patch failing

This one works with 5.9

--- a/config.def.h	2011-07-11 00:24:25.000000000 +0400
+++ b/config.def.h	2011-07-12 04:38:38.000000000 +0400
@@ -1,13 +1,16 @@
 /* See LICENSE file for copyright and license details. */
 
 /* appearance */
+#define NUMCOLORS         4             // need at least 3
+static const char colors[NUMCOLORS][ColLast][8] = {
+	// border   foreground  background
+	{ "#cccccc", "#000000", "#cccccc" },  // 0 = normal
+	{ "#0066ff", "#ffffff", "#0066ff" },  // 1 = selected
+	{ "#0066ff", "#0066ff", "#ffffff" },  // 2 = urgent/warning
+	{ "#ff0000", "#ffffff", "#ff0000" },  // 3 = error
+	// add more here
+};
 static const char font[]            = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
-static const char normbordercolor[] = "#cccccc";
-static const char normbgcolor[]     = "#cccccc";
-static const char normfgcolor[]     = "#000000";
-static const char selbordercolor[]  = "#0066ff";
-static const char selbgcolor[]      = "#0066ff";
-static const char selfgcolor[]      = "#ffffff";
 static const unsigned int borderpx  = 1;        /* border pixel of windows */
 static const unsigned int snap      = 32;       /* snap pixel */
 static const Bool showbar           = True;     /* False means no bar */
@@ -45,7 +48,7 @@ static const Layout layouts[] = {
 #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
 
 /* commands */
-static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
+static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", colors[0][ColBG], "-nf", colors[0][ColFG], "-sb", colors[1][ColBG], "-sf", colors[1][ColFG], NULL };
 static const char *termcmd[]  = { "uxterm", NULL };
 
 static Key keys[] = {
--- a//dwm.c	2011-07-11 00:24:25.000000000 +0400
+++ b/dwm.c	2011-07-12 04:53:47.000000000 +0400
@@ -48,6 +48,7 @@
 #define LENGTH(X)               (sizeof X / sizeof X[0])
 #define MAX(A, B)               ((A) > (B) ? (A) : (B))
 #define MIN(A, B)               ((A) < (B) ? (A) : (B))
+#define MAXCOLORS               8
 #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
 #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
 #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
@@ -97,8 +98,7 @@ struct Client {
 
 typedef struct {
 	int x, y, w, h;
-	unsigned long norm[ColLast];
-	unsigned long sel[ColLast];
+	unsigned long colors[MAXCOLORS][ColLast];
 	Drawable drawable;
 	GC gc;
 	struct {
@@ -175,8 +175,9 @@ static void die(const char *errstr, ...)
 static Monitor *dirtomon(int dir);
 static void drawbar(Monitor *m);
 static void drawbars(void);
-static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
-static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
+static void drawcoloredtext(char *text);
+static void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]);
+static void drawtext(const char *text, unsigned long col[ColLast], Bool pad);
 static void enternotify(XEvent *e);
 static void expose(XEvent *e);
 static void focus(Client *c);
@@ -736,14 +737,13 @@ drawbar(Monitor *m) {
 	dc.x = 0;
 	for(i = 0; i < LENGTH(tags); i++) {
 		dc.w = TEXTW(tags[i]);
-		col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
-		drawtext(tags[i], col, urg & 1 << i);
-		drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
-		           occ & 1 << i, urg & 1 << i, col);
+		col = dc.colors[ (m->tagset[m->seltags] & 1 << i ? 1:(urg & 1 << i ? 2:0))];
+		drawtext(tags[i], col, True);
+		drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, occ & 1 << i, col);
 		dc.x += dc.w;
 	}
 	dc.w = blw = TEXTW(m->ltsymbol);
-	drawtext(m->ltsymbol, dc.norm, False);
+	drawtext(m->ltsymbol, dc.colors[0], True);
 	dc.x += dc.w;
 	x = dc.x;
 	if(m == selmon) { /* status is only drawn on selected monitor */
@@ -753,19 +753,19 @@ drawbar(Monitor *m) {
 			dc.x = x;
 			dc.w = m->ww - x;
 		}
-		drawtext(stext, dc.norm, False);
+		drawcoloredtext(stext);
 	}
 	else
 		dc.x = m->ww;
 	if((dc.w = dc.x - x) > bh) {
 		dc.x = x;
 		if(m->sel) {
-			col = m == selmon ? dc.sel : dc.norm;
-			drawtext(m->sel->name, col, False);
-			drawsquare(m->sel->isfixed, m->sel->isfloating, False, col);
+			col = m == selmon ? dc.colors[1] : dc.colors[0];
+			drawtext(m->sel->name, col, True);
+			drawsquare(m->sel->isfixed, m->sel->isfloating, col);
 		}
 		else
-			drawtext(NULL, dc.norm, False);
+			drawtext(NULL, dc.colors[0], False);
 	}
 	XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
 	XSync(dpy, False);
@@ -780,10 +780,40 @@ drawbars(void) {
 }
 
 void
-drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
+drawcoloredtext(char *text) {
+	Bool first=True;
+	char *buf = text, *ptr = buf, c = 1;
+	unsigned long *col = dc.colors[0];
+	int i, ox = dc.x;
+
+	while( *ptr ) {
+		for( i = 0; *ptr < 0 || *ptr > NUMCOLORS; i++, ptr++);
+		if( !*ptr ) break;
+		c=*ptr;
+		*ptr=0;
+		if( i ) {
+			dc.w = selmon->ww - dc.x;
+			drawtext(buf, col, first);
+			dc.x += textnw(buf, i) + textnw(&c,1);
+			if( first ) dc.x += ( dc.font.ascent + dc.font.descent ) / 2;
+			first = False;
+		} else if( first ) {
+			ox = dc.x += textnw(&c,1);
+		}
+		*ptr = c;
+		col = dc.colors[ c-1 ];
+		buf = ++ptr;
+	}
+	if( !first ) dc.x-=(dc.font.ascent+dc.font.descent)/2;
+	drawtext(buf, col, True);
+	dc.x = ox;
+}
+
+void
+drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
 	int x;
 
-	XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
+	XSetForeground(dpy, dc.gc, col[ColFG]);
 	x = (dc.font.ascent + dc.font.descent + 2) / 4;
 	if(filled)
 		XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1);
@@ -792,17 +822,17 @@ drawsquare(Bool filled, Bool empty, Bool
 }
 
 void
-drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
+drawtext(const char *text, unsigned long col[ColLast], Bool pad) {
 	char buf[256];
 	int i, x, y, h, len, olen;
 
-	XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
+	XSetForeground(dpy, dc.gc, col[ ColBG ]);
 	XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h);
 	if(!text)
 		return;
 	olen = strlen(text);
-	h = dc.font.ascent + dc.font.descent;
-	y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
+	h = pad ? (dc.font.ascent + dc.font.descent) : 0;
+	y = dc.y + ((dc.h + dc.font.ascent - dc.font.descent) / 2);
 	x = dc.x + (h / 2);
 	/* shorten text if necessary */
 	for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
@@ -811,7 +841,7 @@ drawtext(const char *text, unsigned long
 	memcpy(buf, text, len);
 	if(len < olen)
 		for(i = len; i && i > len - 3; buf[--i] = '.');
-	XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
+	XSetForeground(dpy, dc.gc, col[ ColFG ]);
 	if(dc.font.set)
 		XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
 	else
@@ -861,7 +891,7 @@ focus(Client *c) {
 		detachstack(c);
 		attachstack(c);
 		grabbuttons(c, True);
-		XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
+		XSetWindowBorder(dpy, c->win, dc.colors[1][ColBorder]);
 		setfocus(c);
 	}
 	else
@@ -1137,7 +1167,7 @@ manage(Window w, XWindowAttributes *wa)
 	}
 	wc.border_width = c->bw;
 	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
-	XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
+	XSetWindowBorder(dpy, w, dc.colors[0][ColBorder]);
 	configure(c); /* propagates border_width, if size doesn't change */
 	updatesizehints(c);
 	updatewmhints(c);
@@ -1550,12 +1580,11 @@ setup(void) {
 	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
 	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
 	/* init appearance */
-	dc.norm[ColBorder] = getcolor(normbordercolor);
-	dc.norm[ColBG] = getcolor(normbgcolor);
-	dc.norm[ColFG] = getcolor(normfgcolor);
-	dc.sel[ColBorder] = getcolor(selbordercolor);
-	dc.sel[ColBG] = getcolor(selbgcolor);
-	dc.sel[ColFG] = getcolor(selfgcolor);
+	for(int i=0; i<NUMCOLORS; i++) {
+		dc.colors[i][ColBorder] = getcolor( colors[i][ColBorder] );
+		dc.colors[i][ColFG] = getcolor( colors[i][ColFG] );
+		dc.colors[i][ColBG] = getcolor( colors[i][ColBG] );
+	}
 	dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
 	dc.gc = XCreateGC(dpy, root, 0, NULL);
 	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
@@ -1716,7 +1745,7 @@ unfocus(Client *c, Bool setfocus) {
 	if(!c)
 		return;
 	grabbuttons(c, False);
-	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
+	XSetWindowBorder(dpy, c->win, dc.colors[0][ColBorder]);
 	if(setfocus)
 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
 }

The mind roams more freely in empty rooms.
dwm - colours - ncmpcpp - system
irc://irc.freenode.net:meyithi

Offline

#3 2011-08-17 18:03:39

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: DWM 5.9 statuscolors patch failing

@BaconPie - FWIW, this thread has lots of information on dwm patches -- https://bbs.archlinux.org/viewtopic.php?pid=976520

Offline

#4 2011-08-17 22:01:26

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: DWM 5.9 statuscolors patch failing

Thanks, Meyithi. That works great, though I did have to do a fresh install of DWM and update my config manually.

Last edited by BaconPie (2011-08-17 22:02:00)

Offline

Board footer

Powered by FluxBB