Don't interpret markup in window titles stil
authorStiletto <blasux@blasux.ru>
Sat, 11 May 2013 00:22:55 +0400
branchstil
changeset 1536 932900ff8dbb
parent 1535 d815765dfc53
child 1538 6718f0ba24fd
Don't interpret markup in window titles
dwm.c
--- a/dwm.c	Wed Jun 15 11:35:51 2011 +0400
+++ b/dwm.c	Sat May 11 00:22:55 2013 +0400
@@ -60,7 +60,8 @@
 #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
 #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
 #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
-#define TEXTW(X)                (textnw(X, strlen(X)) + dc.font.height)
+#define TEXTW(X)                (textnw(X, strlen(X), False) + dc.font.height)
+#define TEXTWM(X)               (textnw(X, strlen(X), True) + dc.font.height)
 
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
@@ -170,7 +171,7 @@
 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 drawtext(const char *text, unsigned long col[ColLast], Bool invert, Bool markup);
 static void enternotify(XEvent *e);
 static void expose(XEvent *e);
 static void focus(Client *c);
@@ -212,7 +213,7 @@
 static void spawn(const Arg *arg);
 static void tag(const Arg *arg);
 static void tagmon(const Arg *arg);
-static int textnw(const char *text, unsigned int len);
+static int textnw(const char *text, unsigned int len, Bool markup);
 static void tile(Monitor *);
 static void togglebar(const Arg *arg);
 static void togglefloating(const Arg *arg);
@@ -464,7 +465,7 @@
 		}
 		else if(ev->x < x + blw)
 			click = ClkLtSymbol;
-		else if(ev->x > selmon->wx + selmon->ww - TEXTW(stext))
+		else if(ev->x > selmon->wx + selmon->ww - TEXTWM(stext))
 			click = ClkStatusText;
 		else
 			click = ClkWinTitle;
@@ -722,23 +723,23 @@
 	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);
+		drawtext(tags[i], col, urg & 1 << i, False);
 		drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
 		           occ & 1 << i, urg & 1 << i, col);
 		dc.x += dc.w;
 	}
 	dc.w = blw = TEXTW(m->ltsymbol);
-	drawtext(m->ltsymbol, dc.norm, False);
+	drawtext(m->ltsymbol, dc.norm, False, False);
 	dc.x += dc.w;
 	x = dc.x;
 	if(m == selmon) { /* status is only drawn on selected monitor */
-		dc.w = TEXTW(stext);
+		dc.w = TEXTWM(stext);
 		dc.x = m->ww - dc.w;
 		if(dc.x < x) {
 			dc.x = x;
 			dc.w = m->ww - x;
 		}
-		drawtext(stext, dc.norm, False);
+		drawtext(stext, dc.norm, False, True);
 	}
 	else
 		dc.x = m->ww;
@@ -746,11 +747,11 @@
 		dc.x = x;
 		if(m->sel) {
 			col = m == selmon ? dc.sel : dc.norm;
-			drawtext(m->sel->name, col, False);
+			drawtext(m->sel->name, col, False, False);
 			drawsquare(m->sel->isfixed, m->sel->isfloating, False, col);
 		}
 		else
-			drawtext(NULL, dc.norm, False);
+			drawtext(NULL, dc.norm, False, False);
 	}
 	XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
 	XSync(dpy, False);
@@ -786,7 +787,7 @@
 }
 
 void
-drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
+drawtext(const char *text, unsigned long col[ColLast], Bool invert, Bool markup) {
 	char buf[256];
 	int i, x, y, h, len, olen;
 	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
@@ -801,13 +802,16 @@
 	y = dc.y;
 	x = dc.x + (h / 2);
 	/* shorten text if necessary */
-	for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
+	for(len = MIN(olen, sizeof buf); len && textnw(text, len, markup) > dc.w - h; len--);
 	if(!len)
 		return;
 	memcpy(buf, text, len);
 	if(len < olen)
 		for(i = len; i && i > len - 3; buf[--i] = '.');
-	pango_layout_set_markup(dc.plo, text, len);
+	if (markup)
+		pango_layout_set_markup(dc.plo, text, len);
+	else
+		pango_layout_set_text(dc.plo, text, len);
 	pango_xft_render_layout(dc.xftdrawable, (col==dc.norm?dc.xftnorm:dc.xftsel)+(invert?ColBG:ColFG), dc.plo, x * PANGO_SCALE, y * PANGO_SCALE);
 }
 
@@ -1617,9 +1621,14 @@
 }
 
 int
-textnw(const char *text, unsigned int len) {
+textnw(const char *text, unsigned int len, Bool markup) {
 	PangoRectangle r;
-	pango_layout_set_markup(dc.plo, text, len);
+	if (markup)
+		pango_layout_set_markup(dc.plo, text, len);
+	else {
+		pango_layout_set_attributes(dc.plo, NULL);
+		pango_layout_set_text(dc.plo, text, len);
+	}
 	pango_layout_get_extents(dc.plo, &r, 0);
 	return r.width / PANGO_SCALE;
 }