You are not logged in.

#1301 2013-11-18 18:34:38

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: DWM Hackers Unite! Share (or request) dwm patches.

That patch does seem to remove drawsquare, but you can select the part that you need. It will require updating, as well.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#1302 2013-11-21 00:50:38

markoer
Member
Registered: 2010-12-15
Posts: 57

Re: DWM Hackers Unite! Share (or request) dwm patches.

I create patch for my demand earlier, also I somehow change my mind as bolder tags are not nice at all, so this patch bold fonts in statusbar. it's based on patch mentioned by ivoarch in prev post. Patch requires xft, statuscolor.
config example:

static const char boldfont[]						= "Nimbus Sans:pixelsize=12:antialias=true:autohint=true:style=bold";
--- dwm.c	2013-11-21 00:44:46.142862319 +0100
+++ dwm.c	2013-11-21 00:46:43.395560285 +0100
@@ -118,16 +118,19 @@
 };
 
 typedef struct {
+	int ascent;
+	int descent;
+	int height;
+	XftFont *xfont;
+} Fount;
+
+typedef struct {
 	int x, y, w, h;
 	XftColor colors[MAXCOLORS][ColLast];
 	Drawable drawable;
 	GC gc;
-	struct {
-		int ascent;
-		int descent;
-		int height;
-		XftFont *xfont;
-	} font;
+	Fount font;
+	Fount boldfont;
 } DC; /* draw context */
 
 typedef struct {
@@ -204,7 +207,7 @@
 static void drawbars(void);
 static void drawcoloredtext(char *text);
 static void drawsquare(Bool filled, Bool empty, XftColor col[ColLast]);
-static void drawtext(const char *text, XftColor col[ColLast], Bool pad);
+static void drawtext(const char *text, XftColor col[ColLast], Bool pad, Bool occupied);
 static void enternotify(XEvent *e);
 static void expose(XEvent *e);
 static void focus(Client *c);
@@ -220,7 +223,7 @@
 static void grabbuttons(Client *c, Bool focused);
 static void grabkeys(void);
 static void incnmaster(const Arg *arg);
-static void initfont(const char *fontstr);
+static void initfont(Fount *fount, const char *fontstr);
 static void keypress(XEvent *e);
 static void killclient(const Arg *arg);
 static void manage(Window w, XWindowAttributes *wa);
@@ -814,12 +817,12 @@
 	for(i = 0; i < LENGTH(tags); i++) {
 		dc.w = TEXTW(tags[i]);
 		col = dc.colors[ (m->tagset[m->seltags] & 1 << i) ? 1 : (urg & 1 << i ? 2:0) ];
-    drawtext(tags[i], col, True);
+    drawtext(tags[i], col, True, False);
 		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.colors[0], False);
+	drawtext(m->ltsymbol, dc.colors[0], False, False);
 	dc.x += dc.w;
 	x = dc.x;
 	if(m == selmon) { /* status is only drawn on selected monitor */
@@ -840,11 +843,11 @@
 		dc.x = x;
 		if(m->sel) {
 			col = dc.colors[ m == selmon ? 1 : 0 ];
-			drawtext(m->sel->name, col, True);
+			drawtext(m->sel->name, col, False, False);
 			drawsquare(m->sel->isfixed, m->sel->isfloating, col);
 		}
 		else
-			drawtext(NULL, dc.colors[0], False);
+			drawtext(NULL, dc.colors[0], False, False);
 	}
 	XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
 	XSync(dpy, False);
@@ -872,14 +875,14 @@
         *ptr=0;
             if( i ) {
             dc.w = selmon->ww - dc.x;
-            drawtext(buf, col, False);
+            drawtext(buf, col, False, True);
             dc.x += textnw(buf, i);
             }
         *ptr = c;
         col = dc.colors[ c-1 ];
         buf = ++ptr;
         }
-    drawtext(buf, col, False);
+    drawtext(buf, col, False, True);
     dc.x = ox;
 }
 
@@ -896,10 +899,11 @@
 }
 
 void
-drawtext(const char *text, XftColor col[ColLast], Bool pad) {
+drawtext(const char *text, XftColor col[ColLast], Bool pad, Bool occupied) {
 	char buf[256];
 	int i, x, y, h, len, olen;
 	XftDraw *d;
+	Fount *fount = occupied ? &dc.boldfont : &dc.font;
 
 	XSetForeground(dpy, dc.gc, col[ColBG].pixel);
 	XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h);
@@ -919,7 +923,7 @@
 
 	d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy,screen));
 
-	XftDrawStringUtf8(d, (XftColor *) &col[ColFG].pixel, dc.font.xfont, x, y, (XftChar8 *) buf, len);
+	XftDrawStringUtf8(d, (XftColor *) &col[ColFG].pixel, fount->xfont, x, y, (XftChar8 *) buf, len);
 	XftDrawDestroy(d);
 }
 
@@ -1046,7 +1050,6 @@
 
 XftColor
 getcolor(const char *colstr) {
-	Colormap cmap = DefaultColormap(dpy, screen);
 	XftColor color;
 
 	if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color))
@@ -1161,15 +1164,16 @@
 }
 
 void
-initfont(const char *fontstr) {
+initfont(Fount *fount, const char *fontstr) {
 
-	if(!(dc.font.xfont = XftFontOpenName(dpy,screen,fontstr))
-	&& !(dc.font.xfont = XftFontOpenName(dpy,screen,"fixed")))
+	if(!(fount->xfont = XftFontOpenName(dpy,screen,fontstr))
+	&& !(fount->xfont = XftFontOpenName(dpy,screen,"fixed")))
 		die("error, cannot load font: '%s'\n", fontstr);
 
-	dc.font.ascent = dc.font.xfont->ascent;
-	dc.font.descent = dc.font.xfont->descent;
-	dc.font.height = dc.font.ascent + dc.font.descent;
+	fount->ascent = fount->xfont->ascent;
+	fount->descent = fount->xfont->descent;
+	fount->height = fount->ascent + fount->descent;
+	
 }
 
 #ifdef XINERAMA
@@ -1755,7 +1759,8 @@
 	/* init screen */
 	screen = DefaultScreen(dpy);
 	root = RootWindow(dpy, screen);
-	initfont(font);
+	initfont(&dc.font, font);
+	initfont(&dc.boldfont, boldfont);
 	sw = DisplayWidth(dpy, screen);
 	sh = DisplayHeight(dpy, screen);
 	bh = dc.h = dc.font.height + 2;

if you wan't to bold occupied tags, replace in

 for(i = 0; i < LENGTH(tags); i++) {
	dc.w = TEXTW(tags[i]);
	col = dc.colors[ (m->tagset[m->seltags] & 1 << i) ? 1 : (urg & 1 << i ? 2:0) ];
-	drawtext(tags[i], col, True, False);
+	drawtext(tags[i], col, True, occ & 1 << i ? True:False);

Last edited by markoer (2013-11-21 00:53:58)

Offline

#1303 2013-11-21 15:15:13

markoer
Member
Registered: 2010-12-15
Posts: 57

Re: DWM Hackers Unite! Share (or request) dwm patches.

@unia
did you try within your smfact patch to implement resizing clients verticaly up and down, this is working of course but it's not possible to resize to down bottom client of stack

Last edited by markoer (2013-11-21 15:25:06)

Offline

#1304 2013-11-21 17:53:30

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: DWM Hackers Unite! Share (or request) dwm patches.

That is a limitation in the code of DWM.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#1305 2013-11-22 00:05:21

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: DWM Hackers Unite! Share (or request) dwm patches.

markoer wrote:

@unia
did you try within your smfact patch to implement resizing clients verticaly up and down, this is working of course but it's not possible to resize to down bottom client of stack

I may be misunderstanding here, but if your goal is to have multiple clients in the stack, but to hide all but one of them at a time, check out the deck layout patch (which I think is one of Unia's original patches, if I recall correctly)

Offline

#1306 2013-11-22 00:16:27

markoer
Member
Registered: 2010-12-15
Posts: 57

Re: DWM Hackers Unite! Share (or request) dwm patches.

I may be misunderstanding here, but if your goal is to have multiple clients in the stack, but to hide all but one of them at a time, check out the deck layout patch (which I think is one of Unia's original patches, if I recall correctly)

no, unia responded to my question, but i whish he explain little bit about "dwm limitation".

Offline

#1307 2013-11-22 10:38:07

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: DWM Hackers Unite! Share (or request) dwm patches.

In the way DWM currently handles its layouts, I can only choose to resize in one direction - upwards or downwards. Out of personal preference, I chose the upwards variant but if you want to, you are free to change this. If you want to have both, I'm afraid you'll have to re-write the methods used to position the window, or complicate the whole matter and bloat the code.

Unles, of course, I am missing something obvious...


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#1308 2013-11-28 16:20:56

markoer
Member
Registered: 2010-12-15
Posts: 57

Re: DWM Hackers Unite! Share (or request) dwm patches.

Unia@
I have an idea which will maybe solve clients increasing/decreasing smfact in stack area. If in function setsmfact, sf is negative, it will allow resizing top client to the specified factor of sf to the bottom. So my idea is, when resizeing of stack area is in action, check if top and bottom window in stack area have minimum client window height. if top or bottom window is greater then minimum allowed of window size, then incrise or decrese smfact, otherwise return.
I'll tried to accomplish this but I am not able to get height of first and last window in stack.

What do you think, is this possible, would it make sense at all?

Offline

#1309 2013-11-28 16:33:57

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: DWM Hackers Unite! Share (or request) dwm patches.

To be honest, I haven't looked at the code in so long that I can't tell for sure if that is going to work - and I don't have time to get familiar with it again right now. I could guide you to implementing this, though, which takes less time for me and might teach you something as well. If you're interested, send me an email explaining what you have tried already and why that didn't work.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#1310 2013-12-08 05:42:28

anuser
Member
Registered: 2013-12-06
Posts: 4

Re: DWM Hackers Unite! Share (or request) dwm patches.

Sorry to revive an old topic that was mentioned in this thread previous (on this page), but is there a new statuscolors patch that works with the most recent dwm, after xft support was changed significantly in this commit?

Previously, dwm.c contained (as an example of something that has been changed significantly) a struct for the context:

typedef struct {
	int x, y, w, h;
	unsigned long norm[ColLast];
	unsigned long sel[ColLast];
	Drawable drawable;
	GC gc;
	struct {
		int ascent;
		int descent;
		int height;
		XFontSet set;
		XFontStruct *xfont;
	} font;
} DC; /* draw context */

which Unia's status colors patch changes to incorporate Xft/colors. However, in the commit referenced above, this entire structure has been removed, so I'm not sure how to apply the patch, even manually. Is there a more recent patch that allows statuscolors to be used, even in the most recent version of dwm (the one cloned from the repository as of today, for example)?

Last edited by anuser (2013-12-08 23:28:23)

Offline

#1311 2013-12-08 05:52:11

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: DWM Hackers Unite! Share (or request) dwm patches.

Don't crosspost: you have a thread for this already https://wiki.archlinux.org/index.php/Fo … ss-Posting

If you feel that the thread is in the wrong place, report it and ask to have it moved/merged. I'll delete the other one and leave this here.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#1312 2013-12-08 15:07:27

anuser
Member
Registered: 2013-12-06
Posts: 4

Re: DWM Hackers Unite! Share (or request) dwm patches.

Sorry about the cross post; this is definitely a better place for my question than the separate post. Thanks!

Offline

#1313 2013-12-09 23:29:12

holomorph
Member
Registered: 2012-10-19
Posts: 6

Re: DWM Hackers Unite! Share (or request) dwm patches.

I took a crack at adjusting the statuscolours patch for dwm git.  It "works", just not
correctly; something is wrong with calculating widths.  For instance, in

xsetroot -name "$(printf "a\x01b\x02c")"

both `a` and `b` would get buried.

Perhaps someone here can see what's wrong:

 config.def.h | 14 ++++++-------
 drw.c        | 30 +++++++++++++++++++++-------
 drw.h        |  6 ++++--
 dwm.c        | 64 ++++++++++++++++++++++++++++++++++++++++++++----------------
 4 files changed, 81 insertions(+), 33 deletions(-)

diff --git a/config.def.h b/config.def.h
index 875885b..1e4357e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -2,12 +2,12 @@
 
 /* appearance */
 static const char font[]            = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
-static const char normbordercolor[] = "#444444";
-static const char normbgcolor[]     = "#222222";
-static const char normfgcolor[]     = "#bbbbbb";
-static const char selbordercolor[]  = "#005577";
-static const char selbgcolor[]      = "#005577";
-static const char selfgcolor[]      = "#eeeeee";
+static const char schemes[NUMSCHEMES][ColLast][8] = {
+	/* border background foreground */
+	{ "#444444", "#222222", "#bbbbbb" }, /* 0 = normal */
+	{ "#005577", "#005577", "#eeeeee" }, /* 1 = selected */
+	{ "#444444", "#222222", "#aa4444" }, /* 2 = urgent */
+};
 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 */
@@ -51,7 +51,7 @@ static const Layout layouts[] = {
 
 /* commands */
 static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
-static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
+static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", schemes[0][ColBG], "-nf", schemes[0][ColFG], "-sb", schemes[1][ColBG], "-sf", schemes[1][ColFG], NULL };
 static const char *termcmd[]  = { "st", NULL };
 
 static Key keys[] = {
diff --git a/drw.c b/drw.c
index b130405..c784752 100644
--- a/drw.c
+++ b/drw.c
@@ -126,12 +126,12 @@ drw_setscheme(Drw *drw, ClrScheme *scheme) {
 }
 
 void
-drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert) {
+drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty) {
 	int dx;
 
 	if(!drw || !drw->font || !drw->scheme)
 		return;
-	XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->rgb : drw->scheme->fg->rgb);
+	XSetForeground(drw->dpy, drw->gc, drw->scheme->fg->rgb);
 	dx = (drw->font->ascent + drw->font->descent + 2) / 4;
 	if(filled)
 		XFillRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx+1, dx+1);
@@ -140,14 +140,14 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int
 }
 
 void
-drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert) {
+drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text) {
 	char buf[256];
 	int i, tx, ty, th, len, olen;
 	Extnts tex;
 
 	if(!drw || !drw->scheme)
 		return;
-	XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg->rgb : drw->scheme->bg->rgb);
+	XSetForeground(drw->dpy, drw->gc, drw->scheme->bg->rgb);
 	XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
 	if(!text || !drw->font)
 		return;
@@ -164,7 +164,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex
 	memcpy(buf, text, len);
 	if(len < olen)
 		for(i = len; i && i > len - 3; buf[--i] = '.');
-	XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->rgb : drw->scheme->fg->rgb);
+	XSetForeground(drw->dpy, drw->gc, drw->scheme->fg->rgb);
 	if(drw->font->set)
 		XmbDrawString(drw->dpy, drw->drawable, drw->font->set, drw->gc, tx, ty, buf, len);
 	else
@@ -182,18 +182,34 @@ drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) {
 
 void
 drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex) {
+	/* remove non-printing color codes before calculating width */
+	char *ptr = (char *) text;
+	unsigned int i, ibuf, lenbuf = len;
+	char buf[len + 1];
 	XRectangle r;
 
+	for(i = 0, ibuf = 0; *ptr && i < len; i++, ptr++) {
+		if(*ptr <= NUMSCHEMES && *ptr > 0) {
+			if(i < len)
+				lenbuf--;
+		}
+		else {
+			buf[ibuf] = *ptr;
+			ibuf++;
+		}
+	}
+	buf[ibuf] = 0;
+
 	if(!font || !text)
 		return;
 	if(font->set) {
-		XmbTextExtents(font->set, text, len, NULL, &r);
+		XmbTextExtents(font->set, buf, lenbuf, NULL, &r);
 		tex->w = r.width;
 		tex->h = r.height;
 	}
 	else {
 		tex->h = font->ascent + font->descent;
-		tex->w = XTextWidth(font->xfont, text, len);
+		tex->w = XTextWidth(font->xfont, buf, lenbuf);
 	}
 }
 
diff --git a/drw.h b/drw.h
index a5f34e0..17ada80 100644
--- a/drw.h
+++ b/drw.h
@@ -1,5 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 
+#define NUMSCHEMES              10
+
 typedef struct {
 	unsigned long rgb;
 } Clr;
@@ -62,8 +64,8 @@ void drw_setfont(Drw *drw, Fnt *font);
 void drw_setscheme(Drw *drw, ClrScheme *scheme);
 
 /* Drawing functions */
-void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert);
-void drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert);
+void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty);
+void drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text);
 
 /* Map functions */
 void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
diff --git a/dwm.c b/dwm.c
index 1bbb4b3..789e94a 100644
--- a/dwm.c
+++ b/dwm.c
@@ -59,6 +59,7 @@
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
 enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */
+enum { ColBorder, ColBG, ColFG, ColLast }; /* scheme elements */
 enum { NetSupported, NetWMName, NetWMState,
        NetWMFullscreen, NetActiveWindow, NetWMWindowType,
        NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
@@ -163,6 +164,7 @@ static void detachstack(Client *c);
 static Monitor *dirtomon(int dir);
 static void drawbar(Monitor *m);
 static void drawbars(void);
+static void drawcoloredtext(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text);
 static void enternotify(XEvent *e);
 static void expose(XEvent *e);
 static void focus(Client *c);
@@ -260,7 +262,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
 static Atom wmatom[WMLast], netatom[NetLast];
 static Bool running = True;
 static Cur *cursor[CurLast];
-static ClrScheme scheme[SchemeLast];
+static ClrScheme scheme[NUMSCHEMES];
 static Display *dpy;
 static Drw *drw;
 static Fnt *fnt;
@@ -691,6 +693,32 @@ dirtomon(int dir) {
 }
 
 void
+drawcoloredtext(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text) {
+	char *buf = (char *)text, *ptr = buf, c = 1;
+	ClrScheme col = scheme[SchemeNorm];
+	int i, ox = x;
+
+	while(*ptr) {
+		for(i = 0; *ptr < 0 || *ptr > NUMSCHEMES; i++, ptr++);
+		if(!*ptr) break;
+		c = *ptr;
+		*ptr = 0;
+		if(i) {
+			w = selmon->ww - x;
+			drw_setscheme(drw, &col);
+			drw_text(drw, x, 0, w, bh, buf);
+			x += drw_font_getexts_width(drw->font, buf, i);
+		}
+		*ptr = c;
+		col = scheme[c - 1];
+		buf = ++ptr;
+	}
+	drw_setscheme(drw, &col);
+	drw_text(drw, x, 0, w, bh, buf);
+	x = ox;
+}
+
+void
 drawbar(Monitor *m) {
 	int x, xx, w;
 	unsigned int i, occ = 0, urg = 0;
@@ -704,15 +732,15 @@ drawbar(Monitor *m) {
 	x = 0;
 	for(i = 0; i < LENGTH(tags); i++) {
 		w = TEXTW(tags[i]);
-		drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
-		drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i);
+		drw_setscheme(drw, &scheme[(m->tagset[m->seltags] & 1 << i) ? 1 : (urg & 1 << i ? 2:0)]);
+		drw_text(drw, x, 0, w, bh, tags[i]);
 		drw_rect(drw, x, 0, w, bh, m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
-		           occ & 1 << i, urg & 1 << i);
+		           occ & 1 << i);
 		x += w;
 	}
 	w = blw = TEXTW(m->ltsymbol);
 	drw_setscheme(drw, &scheme[SchemeNorm]);
-	drw_text(drw, x, 0, w, bh, m->ltsymbol, 0);
+	drw_text(drw, x, 0, w, bh, m->ltsymbol);
 	x += w;
 	xx = x;
 	if(m == selmon) { /* status is only drawn on selected monitor */
@@ -722,20 +750,20 @@ drawbar(Monitor *m) {
 			x = xx;
 			w = m->ww - xx;
 		}
-		drw_text(drw, x, 0, w, bh, stext, 0);
+		drawcoloredtext(drw, x, 0, w, bh, stext);
 	}
 	else
 		x = m->ww;
 	if((w = x - xx) > bh) {
 		x = xx;
 		if(m->sel) {
-			drw_setscheme(drw, m == selmon ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
-			drw_text(drw, x, 0, w, bh, m->sel->name, 0);
-			drw_rect(drw, x, 0, w, bh, m->sel->isfixed, m->sel->isfloating, 0);
+			drw_setscheme(drw, &scheme[m == selmon ? SchemeSel : SchemeNorm]);
+			drw_text(drw, x, 0, w, bh, m->sel->name);
+			drw_rect(drw, x, 0, w, bh, m->sel->isfixed, m->sel->isfloating);
 		}
 		else {
 			drw_setscheme(drw, &scheme[SchemeNorm]);
-			drw_text(drw, x, 0, w, bh, NULL, 0);
+			drw_text(drw, x, 0, w, bh, NULL);
 		}
 	}
 	drw_map(drw, m->barwin, 0, 0, m->ww, bh);
@@ -1522,12 +1550,11 @@ setup(void) {
 	cursor[CurResize] = drw_cur_create(drw, XC_sizing);
 	cursor[CurMove] = drw_cur_create(drw, XC_fleur);
 	/* init appearance */
-	scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor);
-	scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
-	scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
-	scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor);
-	scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
-	scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
+	for(int i = 0; i < NUMSCHEMES; i++) {
+		scheme[i].border = drw_clr_create(drw, schemes[i][ColBorder]);
+		scheme[i].bg = drw_clr_create(drw, schemes[i][ColBG]);
+		scheme[i].fg = drw_clr_create(drw, schemes[i][ColFG]);
+	}
 	/* init bars */
 	updatebars();
 	updatestatus();
@@ -1948,8 +1975,11 @@ updatewmhints(Client *c) {
 			wmh->flags &= ~XUrgencyHint;
 			XSetWMHints(dpy, c->win, wmh);
 		}
-		else
+		else {
 			c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
+			if(c->isurgent)
+				XSetWindowBorder(dpy, c->win, scheme[SchemeLast].border->rgb);
+		}
 		if(wmh->flags & InputHint)
 			c->neverfocus = !wmh->input;
 		else

Offline

#1314 2013-12-10 11:14:16

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: DWM Hackers Unite! Share (or request) dwm patches.

Nevermind

Last edited by Unia (2013-12-10 11:15:18)


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#1315 2013-12-10 12:05:42

pks
Member
From: Germany
Registered: 2012-07-20
Posts: 110

Re: DWM Hackers Unite! Share (or request) dwm patches.

holomorph wrote:

I took a crack at adjusting the statuscolours patch for dwm git.  It "works", just not
correctly; something is wrong with calculating widths.  For instance, in

xsetroot -name "$(printf "a\x01b\x02c")"

both `a` and `b` would get buried.

Perhaps someone here can see what's wrong:

 config.def.h | 14 ++++++-------
 drw.c        | 30 +++++++++++++++++++++-------
 drw.h        |  6 ++++--
 dwm.c        | 64 ++++++++++++++++++++++++++++++++++++++++++++----------------
 4 files changed, 81 insertions(+), 33 deletions(-)

diff --git a/config.def.h b/config.def.h
index 875885b..1e4357e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -2,12 +2,12 @@
 
 /* appearance */
 static const char font[]            = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
-static const char normbordercolor[] = "#444444";
-static const char normbgcolor[]     = "#222222";
-static const char normfgcolor[]     = "#bbbbbb";
-static const char selbordercolor[]  = "#005577";
-static const char selbgcolor[]      = "#005577";
-static const char selfgcolor[]      = "#eeeeee";
+static const char schemes[NUMSCHEMES][ColLast][8] = {
+	/* border background foreground */
+	{ "#444444", "#222222", "#bbbbbb" }, /* 0 = normal */
+	{ "#005577", "#005577", "#eeeeee" }, /* 1 = selected */
+	{ "#444444", "#222222", "#aa4444" }, /* 2 = urgent */
+};
 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 */
@@ -51,7 +51,7 @@ static const Layout layouts[] = {
 
 /* commands */
 static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
-static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
+static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", schemes[0][ColBG], "-nf", schemes[0][ColFG], "-sb", schemes[1][ColBG], "-sf", schemes[1][ColFG], NULL };
 static const char *termcmd[]  = { "st", NULL };
 
 static Key keys[] = {
diff --git a/drw.c b/drw.c
index b130405..c784752 100644
--- a/drw.c
+++ b/drw.c
@@ -126,12 +126,12 @@ drw_setscheme(Drw *drw, ClrScheme *scheme) {
 }
 
 void
-drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert) {
+drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty) {
 	int dx;
 
 	if(!drw || !drw->font || !drw->scheme)
 		return;
-	XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->rgb : drw->scheme->fg->rgb);
+	XSetForeground(drw->dpy, drw->gc, drw->scheme->fg->rgb);
 	dx = (drw->font->ascent + drw->font->descent + 2) / 4;
 	if(filled)
 		XFillRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx+1, dx+1);
@@ -140,14 +140,14 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int
 }
 
 void
-drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert) {
+drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text) {
 	char buf[256];
 	int i, tx, ty, th, len, olen;
 	Extnts tex;
 
 	if(!drw || !drw->scheme)
 		return;
-	XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg->rgb : drw->scheme->bg->rgb);
+	XSetForeground(drw->dpy, drw->gc, drw->scheme->bg->rgb);
 	XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
 	if(!text || !drw->font)
 		return;
@@ -164,7 +164,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex
 	memcpy(buf, text, len);
 	if(len < olen)
 		for(i = len; i && i > len - 3; buf[--i] = '.');
-	XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->rgb : drw->scheme->fg->rgb);
+	XSetForeground(drw->dpy, drw->gc, drw->scheme->fg->rgb);
 	if(drw->font->set)
 		XmbDrawString(drw->dpy, drw->drawable, drw->font->set, drw->gc, tx, ty, buf, len);
 	else
@@ -182,18 +182,34 @@ drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) {
 
 void
 drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex) {
+	/* remove non-printing color codes before calculating width */
+	char *ptr = (char *) text;
+	unsigned int i, ibuf, lenbuf = len;
+	char buf[len + 1];
 	XRectangle r;
 
+	for(i = 0, ibuf = 0; *ptr && i < len; i++, ptr++) {
+		if(*ptr <= NUMSCHEMES && *ptr > 0) {
+			if(i < len)
+				lenbuf--;
+		}
+		else {
+			buf[ibuf] = *ptr;
+			ibuf++;
+		}
+	}
+	buf[ibuf] = 0;
+
 	if(!font || !text)
 		return;
 	if(font->set) {
-		XmbTextExtents(font->set, text, len, NULL, &r);
+		XmbTextExtents(font->set, buf, lenbuf, NULL, &r);
 		tex->w = r.width;
 		tex->h = r.height;
 	}
 	else {
 		tex->h = font->ascent + font->descent;
-		tex->w = XTextWidth(font->xfont, text, len);
+		tex->w = XTextWidth(font->xfont, buf, lenbuf);
 	}
 }
 
diff --git a/drw.h b/drw.h
index a5f34e0..17ada80 100644
--- a/drw.h
+++ b/drw.h
@@ -1,5 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 
+#define NUMSCHEMES              10
+
 typedef struct {
 	unsigned long rgb;
 } Clr;
@@ -62,8 +64,8 @@ void drw_setfont(Drw *drw, Fnt *font);
 void drw_setscheme(Drw *drw, ClrScheme *scheme);
 
 /* Drawing functions */
-void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert);
-void drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert);
+void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty);
+void drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text);
 
 /* Map functions */
 void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
diff --git a/dwm.c b/dwm.c
index 1bbb4b3..789e94a 100644
--- a/dwm.c
+++ b/dwm.c
@@ -59,6 +59,7 @@
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
 enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */
+enum { ColBorder, ColBG, ColFG, ColLast }; /* scheme elements */
 enum { NetSupported, NetWMName, NetWMState,
        NetWMFullscreen, NetActiveWindow, NetWMWindowType,
        NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
@@ -163,6 +164,7 @@ static void detachstack(Client *c);
 static Monitor *dirtomon(int dir);
 static void drawbar(Monitor *m);
 static void drawbars(void);
+static void drawcoloredtext(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text);
 static void enternotify(XEvent *e);
 static void expose(XEvent *e);
 static void focus(Client *c);
@@ -260,7 +262,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
 static Atom wmatom[WMLast], netatom[NetLast];
 static Bool running = True;
 static Cur *cursor[CurLast];
-static ClrScheme scheme[SchemeLast];
+static ClrScheme scheme[NUMSCHEMES];
 static Display *dpy;
 static Drw *drw;
 static Fnt *fnt;
@@ -691,6 +693,32 @@ dirtomon(int dir) {
 }
 
 void
+drawcoloredtext(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text) {
+	char *buf = (char *)text, *ptr = buf, c = 1;
+	ClrScheme col = scheme[SchemeNorm];
+	int i, ox = x;
+
+	while(*ptr) {
+		for(i = 0; *ptr < 0 || *ptr > NUMSCHEMES; i++, ptr++);
+		if(!*ptr) break;
+		c = *ptr;
+		*ptr = 0;
+		if(i) {
+			w = selmon->ww - x;
+			drw_setscheme(drw, &col);
+			drw_text(drw, x, 0, w, bh, buf);
+			x += drw_font_getexts_width(drw->font, buf, i);
+		}
+		*ptr = c;
+		col = scheme[c - 1];
+		buf = ++ptr;
+	}
+	drw_setscheme(drw, &col);
+	drw_text(drw, x, 0, w, bh, buf);
+	x = ox;
+}
+
+void
 drawbar(Monitor *m) {
 	int x, xx, w;
 	unsigned int i, occ = 0, urg = 0;
@@ -704,15 +732,15 @@ drawbar(Monitor *m) {
 	x = 0;
 	for(i = 0; i < LENGTH(tags); i++) {
 		w = TEXTW(tags[i]);
-		drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
-		drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i);
+		drw_setscheme(drw, &scheme[(m->tagset[m->seltags] & 1 << i) ? 1 : (urg & 1 << i ? 2:0)]);
+		drw_text(drw, x, 0, w, bh, tags[i]);
 		drw_rect(drw, x, 0, w, bh, m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
-		           occ & 1 << i, urg & 1 << i);
+		           occ & 1 << i);
 		x += w;
 	}
 	w = blw = TEXTW(m->ltsymbol);
 	drw_setscheme(drw, &scheme[SchemeNorm]);
-	drw_text(drw, x, 0, w, bh, m->ltsymbol, 0);
+	drw_text(drw, x, 0, w, bh, m->ltsymbol);
 	x += w;
 	xx = x;
 	if(m == selmon) { /* status is only drawn on selected monitor */
@@ -722,20 +750,20 @@ drawbar(Monitor *m) {
 			x = xx;
 			w = m->ww - xx;
 		}
-		drw_text(drw, x, 0, w, bh, stext, 0);
+		drawcoloredtext(drw, x, 0, w, bh, stext);
 	}
 	else
 		x = m->ww;
 	if((w = x - xx) > bh) {
 		x = xx;
 		if(m->sel) {
-			drw_setscheme(drw, m == selmon ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
-			drw_text(drw, x, 0, w, bh, m->sel->name, 0);
-			drw_rect(drw, x, 0, w, bh, m->sel->isfixed, m->sel->isfloating, 0);
+			drw_setscheme(drw, &scheme[m == selmon ? SchemeSel : SchemeNorm]);
+			drw_text(drw, x, 0, w, bh, m->sel->name);
+			drw_rect(drw, x, 0, w, bh, m->sel->isfixed, m->sel->isfloating);
 		}
 		else {
 			drw_setscheme(drw, &scheme[SchemeNorm]);
-			drw_text(drw, x, 0, w, bh, NULL, 0);
+			drw_text(drw, x, 0, w, bh, NULL);
 		}
 	}
 	drw_map(drw, m->barwin, 0, 0, m->ww, bh);
@@ -1522,12 +1550,11 @@ setup(void) {
 	cursor[CurResize] = drw_cur_create(drw, XC_sizing);
 	cursor[CurMove] = drw_cur_create(drw, XC_fleur);
 	/* init appearance */
-	scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor);
-	scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
-	scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
-	scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor);
-	scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
-	scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
+	for(int i = 0; i < NUMSCHEMES; i++) {
+		scheme[i].border = drw_clr_create(drw, schemes[i][ColBorder]);
+		scheme[i].bg = drw_clr_create(drw, schemes[i][ColBG]);
+		scheme[i].fg = drw_clr_create(drw, schemes[i][ColFG]);
+	}
 	/* init bars */
 	updatebars();
 	updatestatus();
@@ -1948,8 +1975,11 @@ updatewmhints(Client *c) {
 			wmh->flags &= ~XUrgencyHint;
 			XSetWMHints(dpy, c->win, wmh);
 		}
-		else
+		else {
 			c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
+			if(c->isurgent)
+				XSetWindowBorder(dpy, c->win, scheme[SchemeLast].border->rgb);
+		}
 		if(wmh->flags & InputHint)
 			c->neverfocus = !wmh->input;
 		else

I don't really get the use of the lenbuf variable in drw_font_getexts(...). Instead of setting lenbuf to len and decrementing with every non-printable you could instead just use ibuf, which will contain the buffers length after the for-loop. No idea though if that'd change anything but it's confusing never the less.

Offline

#1316 2013-12-16 08:06:55

holomorph
Member
Registered: 2012-10-19
Posts: 6

Re: DWM Hackers Unite! Share (or request) dwm patches.

Agreed, thanks.  It doesn't change anything, but it is much less confusing without lenbuf.

Edit: Looked over the old patches and my attempt more closely.  There are many inconsistencies between my patch and the 6.0 one that need to be fixed.

Last edited by holomorph (2013-12-18 04:07:27)

Offline

#1317 2013-12-26 12:15:07

alphur
Member
Registered: 2011-04-23
Posts: 9

Re: DWM Hackers Unite! Share (or request) dwm patches.

using unia's patches: uselessgaps and statuscolors don't seem to work. i use cycle then push patches in that order.

Offline

#1318 2014-01-05 19:50:36

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: DWM Hackers Unite! Share (or request) dwm patches.

alphur wrote:

using unia's patches: uselessgaps and statuscolors don't seem to work. i use cycle then push patches in that order.

What exactly doesn't work? Sorry for the late reply, I was away for a few days.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#1319 2014-01-06 16:54:17

pks
Member
From: Germany
Registered: 2012-07-20
Posts: 110

Re: DWM Hackers Unite! Share (or request) dwm patches.

(Cross-post from monthly screenshot thread) I've implemented a patch for dwm that allows me to have per-client facts (cfacts) that let me weight each client on its own. It can be seen in action on the right monitor.

qJu1NW1s.png

Offline

#1320 2014-01-06 17:09:56

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: DWM Hackers Unite! Share (or request) dwm patches.

pks wrote:

(Cross-post from monthly screenshot thread) I've implemented a patch for dwm that allows me to have per-client facts (cfacts) that let me weight each client on its own. It can be seen in action on the right monitor.

http://i.imgur.com/qJu1NW1s.png

Cool! Where can I find the patch?


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#1321 2014-01-06 18:08:29

pks
Member
From: Germany
Registered: 2012-07-20
Posts: 110

Re: DWM Hackers Unite! Share (or request) dwm patches.

Unia wrote:
pks wrote:

(Cross-post from monthly screenshot thread) I've implemented a patch for dwm that allows me to have per-client facts (cfacts) that let me weight each client on its own. It can be seen in action on the right monitor.

http://i.imgur.com/qJu1NW1s.png

Cool! Where can I find the patch?

You can find it in my repository. It won't apply to vanilla dwm but it should be fairly easy to extract the necessary bits as the patch is rather simple. Let me know if any problems arise and I'll try to help you.

Offline

#1322 2014-01-06 18:53:18

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: DWM Hackers Unite! Share (or request) dwm patches.

Cheers! I'll try to hack it in later. You should make a version for vanilla and upload it on the Suckless website wink I'm sure many people will find this usefull.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#1323 2014-01-06 19:09:49

pks
Member
From: Germany
Registered: 2012-07-20
Posts: 110

Re: DWM Hackers Unite! Share (or request) dwm patches.

Unia wrote:

Cheers! I'll try to hack it in later. You should make a version for vanilla and upload it on the Suckless website wink I'm sure many people will find this usefull.

I've ported my patch to the current dwm tip. I'd like at least one more person to test it and voice his opinion before I send it to the suckless mailing list.

Edit: See this post for an updated version of this patch.

Last edited by pks (2014-01-07 11:53:15)

Offline

#1324 2014-01-06 19:22:45

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: DWM Hackers Unite! Share (or request) dwm patches.

I'll hack it in right now wink I'll be back

EDIT: Not sure if this is intended behaviour, but if I have three clients in the stack and I resize the bottom one to the smallest, I expected the other two would equally share the remaining space but this is not the case.

Last edited by Unia (2014-01-06 19:35:39)


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#1325 2014-01-06 19:45:10

pks
Member
From: Germany
Registered: 2012-07-20
Posts: 110

Re: DWM Hackers Unite! Share (or request) dwm patches.

Unia wrote:

I'll hack it in right now wink I'll be back

EDIT: Not sure if this is intended behaviour, but if I have three clients in the stack and I resize the bottom one to the smallest, I expected the other two would equally share the remaining space but this is not the case.

Eh? Well, what can I say... for me it works as you did expect it to work.

Edit: Are you sure you didn't accidentaly modify the other client's cfacts?

Last edited by pks (2014-01-06 19:53:59)

Offline

Board footer

Powered by FluxBB