You are not logged in.

#1 2013-06-18 13:13:15

b1tH1de0
Member
Registered: 2013-06-05
Posts: 17

[SOLVED] can't change dwm bar size after applying xft patch

I'm currently experimenting with dwm and recently decided to change the default font from terminus to inconsolata. Installed the font, applied both patches found on suckless.org site, and changed the font line in config.h.

After X restart my dwm status bar has become about 2x/3x times as large as it was before (do the font is smaller then terminus, when comparing terminal output) and I can't seem to change it back. To be hones I don't know if it's the font itself, or has something been broken during patching.

Please find bellow my dot files.

config.h

/* See LICENSE file for copyright and license details. */

/* appearance */
//static const char font[]            = "-*-terminus-medium-r-*-*-12-*-*-*-*-*-*-*";
static const char font[]            = "Inconsolata 8";
static const char normbordercolor[] = "#1D1F21";
static const char normbgcolor[]     = "#1D1F21";
static const char normfgcolor[]     = "#C5C8C6";
static const char selbordercolor[]  = "#1D1F21";
static const char selbgcolor[]      = "#1D1F21";
static const char selfgcolor[]      = "#C5C8C6";
static const unsigned int borderpx  = 1;        /* border pixel of windows */
static const unsigned int snap      = 8;       /* snap pixel */
static const Bool showbar           = True;     /* False means no bar */
static const Bool topbar            = True;     /* False means bottom bar */

/* tagging */
static const char *tags[] = { "main", "web", "chat", "code", "test", "admin", "media", "misc" };

static const Rule rules[] = {
	/* class      instance    title       tags mask     isfloating   monitor */
	{ "Chromium", NULL,       NULL,       1 << 1,       False,       -1 },
};

/* layout(s) */
static const float mfact      = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster      = 1;    /* number of clients in master area */
static const Bool resizehints = True; /* True means respect size hints in tiled resizals */

static const Layout layouts[] = {
	/* symbol     arrange function */
	{ "[]=",      tile },    /* first entry is default */
	{ "><>",      NULL },    /* no layout function means floating behavior */
	{ "[M]",      monocle },
};

/* key definitions */
#define MODKEY Mod1Mask
#define TAGKEYS(KEY,TAG) \
	{ MODKEY,                       KEY,      view,           {.ui = 1 << TAG} }, \
	{ MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
	{ MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
	{ MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },

/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#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 *termcmd[]  = { "uxterm", NULL };

static Key keys[] = {
	/* modifier                     key        function        argument */
	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
	{ MODKEY,                       XK_b,      togglebar,      {0} },
	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
	{ MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
	{ MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
	{ MODKEY,                       XK_Return, zoom,           {0} },
	{ MODKEY,                       XK_Tab,    view,           {0} },
	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
	{ MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
	{ MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
	{ MODKEY,                       XK_space,  setlayout,      {0} },
	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
	{ MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
	{ MODKEY,                       XK_period, focusmon,       {.i = +1 } },
	{ MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
	{ MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
	TAGKEYS(                        XK_1,                      0)
	TAGKEYS(                        XK_2,                      1)
	TAGKEYS(                        XK_3,                      2)
	TAGKEYS(                        XK_4,                      3)
	TAGKEYS(                        XK_5,                      4)
	TAGKEYS(                        XK_6,                      5)
	TAGKEYS(                        XK_7,                      6)
	TAGKEYS(                        XK_8,                      7)
	TAGKEYS(                        XK_9,                      8)
	{ MODKEY|ShiftMask,             XK_q,      quit,           {0} },
};

/* button definitions */
/* click can be ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
	/* click                event mask      button          function        argument */
	{ ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
	{ ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
	{ ClkWinTitle,          0,              Button2,        zoom,           {0} },
	{ ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
	{ ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
	{ ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
	{ ClkTagBar,            0,              Button1,        view,           {0} },
	{ ClkTagBar,            0,              Button3,        toggleview,     {0} },
	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
};

.xinitrc

#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)

if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi

VBoxClient-all &

# load Xresources
[[ -f ~/.Xresources ]] && xrdb -merge ~/.Xresources

# add font paths
#[[ -d /usr/share/fonts/local ]] && xset +fp /usr/share/fonts/local
[[ -d /usr/share/fonts/TTF ]] && xset +fp /usr/share/fonts/TTF
#[[ -d ~/.fonts/ ]] && xset +fp ~/fonts/		# for future reference
xset fp rehash

# set background
sh ~/.fehbg &			# background image

# load statusbar
conky |while read -r; do xsetroot -name "$REPLY"; done &

# start WM
exec dwm

.Xresources

xft.dpi:	96
!xcursor.theme:	Neutral

!- colors ------------------------------
! BASE
*foreground: 	 #C5C8C6
*background: 	 #1D1F21
!*cursorColor:    #1C1C23
!*colorUL:        #1E828C

!! PALETE
! 0-7 - 'normal' colors
! 8-15 - 'bright' counterparts
!black
*color0: #282A2E
*color8: #373B41
!red
*color1: #A54242
*color9: #CC6666
!green
*color2: #8C9440
*color10: #B5BD68
!yellow
*color3: #DE935F
*color11: #F0C674
!blue
*color4: #5F819D
*color12: #81A2BE
!magenta
*color5: #85678F
*color13: #B294BB
!cyan
*color6: #5E8D87
*color14: #8ABEB7
!white
*color7: #707880
*color15: #c5c8c6

!- xterm -------------------------------
!xterm*scaleHeight:	0.9
xterm*VT100.geometry:	80x25	
xterm*faceName:		xft:Inconsolata:style=Medium:size=8:antialias=true:hinting=true
xterm*font:		xft:Inconsolata:size=8
xterm*boldFont:		xft:Inconsolata:size=8
xterm*italicFont:		xft:Inconsolata:size=8
xterm*boldItalicFont:		xft:Inconsolata:size=8

Any ideas?

Last edited by b1tH1de0 (2013-06-20 09:21:42)

Offline

#2 2013-06-18 14:21:11

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

Re: [SOLVED] can't change dwm bar size after applying xft patch

First of all, you configured your font wrongly, it should be Inconsolata:size=8. Secondly, can I see those two patches? We can't help you with anything if you don't supply the code..


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

#3 2013-06-18 20:34:54

b1tH1de0
Member
Registered: 2013-06-05
Posts: 17

Re: [SOLVED] can't change dwm bar size after applying xft patch

All I assumed was that config.h was the source of the problem.

Please find bellow patch files You asked for..

dwm-xft

--- ../dwm-o/dwm-6.0/dwm.c	2011-12-19 10:02:46.000000000 -0500
+++ dwm.c	2012-05-16 22:33:00.043394484 -0400
@@ -39,6 +39,7 @@
 #ifdef XINERAMA
 #include <X11/extensions/Xinerama.h>
 #endif /* XINERAMA */
+#include <X11/Xft/Xft.h>
 
 /* macros */
 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
@@ -99,16 +100,15 @@
 
 typedef struct {
 	int x, y, w, h;
-	unsigned long norm[ColLast];
-	unsigned long sel[ColLast];
+	XftColor norm[ColLast];
+	XftColor sel[ColLast];
 	Drawable drawable;
 	GC gc;
 	struct {
 		int ascent;
 		int descent;
 		int height;
-		XFontSet set;
-		XFontStruct *xfont;
+		XftFont *xfont;
 	} font;
 } DC; /* draw context */
 
@@ -178,15 +178,15 @@
 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 drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]);
+static void drawtext(const char *text, XftColor col[ColLast], Bool invert);
 static void enternotify(XEvent *e);
 static void expose(XEvent *e);
 static void focus(Client *c);
 static void focusin(XEvent *e);
 static void focusmon(const Arg *arg);
 static void focusstack(const Arg *arg);
-static unsigned long getcolor(const char *colstr);
+static XftColor getcolor(const char *colstr);
 static Bool getrootptr(int *x, int *y);
 static long getstate(Window w);
 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
@@ -485,10 +485,6 @@
 	for(m = mons; m; m = m->next)
 		while(m->stack)
 			unmanage(m->stack, False);
-	if(dc.font.set)
-		XFreeFontSet(dpy, dc.font.set);
-	else
-		XFreeFont(dpy, dc.font.xfont);
 	XUngrabKey(dpy, AnyKey, AnyModifier, root);
 	XFreePixmap(dpy, dc.drawable);
 	XFreeGC(dpy, dc.gc);
@@ -719,7 +715,7 @@
 drawbar(Monitor *m) {
 	int x;
 	unsigned int i, occ = 0, urg = 0;
-	unsigned long *col;
+	XftColor *col;
 	Client *c;
 
 	for(c = m->clients; c; c = c->next) {
@@ -774,10 +770,10 @@
 }
 
 void
-drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
+drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]) {
 	int x;
 
-	XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
+	XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG].pixel);
 	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);
@@ -786,11 +782,12 @@
 }
 
 void
-drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
+drawtext(const char *text, XftColor col[ColLast], Bool invert) {
 	char buf[256];
 	int i, x, y, h, len, olen;
+	XftDraw *d;
 
-	XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
+	XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG].pixel);
 	XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h);
 	if(!text)
 		return;
@@ -805,11 +802,11 @@
 	memcpy(buf, text, len);
 	if(len < olen)
 		for(i = len; i && i > len - 3; buf[--i] = '.');
-	XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
-	if(dc.font.set)
-		XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
-	else
-		XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
+
+	d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy,screen));
+
+	XftDrawStringUtf8(d, &col[invert ? ColBG : ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len);
+	XftDrawDestroy(d);
 }
 
 void
@@ -855,7 +852,7 @@
 		detachstack(c);
 		attachstack(c);
 		grabbuttons(c, True);
-		XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
+		XSetWindowBorder(dpy, c->win, dc.sel[ColBorder].pixel);
 		setfocus(c);
 	}
 	else
@@ -926,14 +923,14 @@
 	return atom;
 }
 
-unsigned long
+XftColor 
 getcolor(const char *colstr) {
-	Colormap cmap = DefaultColormap(dpy, screen);
-	XColor color;
+	XftColor color;
 
-	if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
+	if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color))
 		die("error, cannot allocate color '%s'\n", colstr);
-	return color.pixel;
+
+	return color;
 }
 
 Bool
@@ -1034,35 +1031,13 @@
 
 void
 initfont(const char *fontstr) {
-	char *def, **missing;
-	int n;
 
-	dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
-	if(missing) {
-		while(n--)
-			fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
-		XFreeStringList(missing);
-	}
-	if(dc.font.set) {
-		XFontStruct **xfonts;
-		char **font_names;
-
-		dc.font.ascent = dc.font.descent = 0;
-		XExtentsOfFontSet(dc.font.set);
-		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
-		while(n--) {
-			dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
-			dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
-			xfonts++;
-		}
-	}
-	else {
-		if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
-		&& !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
-			die("error, cannot load font: '%s'\n", fontstr);
-		dc.font.ascent = dc.font.xfont->ascent;
-		dc.font.descent = dc.font.xfont->descent;
-	}
+	if(!(dc.font.xfont = XftFontOpenName(dpy,screen,fontstr))
+	&& !(dc.font.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;
 }
 
@@ -1144,7 +1119,7 @@
 
 	wc.border_width = c->bw;
 	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
-	XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
+	XSetWindowBorder(dpy, w, dc.norm[ColBorder].pixel);
 	configure(c); /* propagates border_width, if size doesn't change */
 	updatewindowtype(c);
 	updatesizehints(c);
@@ -1621,8 +1596,6 @@
 	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);
-	if(!dc.font.set)
-		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
 	/* init bars */
 	updatebars();
 	updatestatus();
@@ -1692,13 +1665,9 @@
 
 int
 textnw(const char *text, unsigned int len) {
-	XRectangle r;
-
-	if(dc.font.set) {
-		XmbTextExtents(dc.font.set, text, len, NULL, &r);
-		return r.width;
-	}
-	return XTextWidth(dc.font.xfont, text, len);
+	XGlyphInfo ext;
+	XftTextExtentsUtf8(dpy, dc.font.xfont, (XftChar8 *) text, len, &ext);
+	return ext.xOff;
 }
 
 void
@@ -1776,7 +1745,7 @@
 	if(!c)
 		return;
 	grabbuttons(c, False);
-	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
+	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder].pixel);
 	if(setfocus)
 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
 }

dwm-config.mk

--- config.mk.orig  2011-12-19 16:02:46.000000000 +0100
+++ b/dwm-6.0/config.mk 2012-05-26 15:46:24.429574270 +0200
@@ -14,12 +14,17 @@
 XINERAMALIBS = -L${X11LIB} -lXinerama
 XINERAMAFLAGS = -DXINERAMA
 
+# Xft
+XFTINC = -I/usr/include/freetype2
+XFTLIBS = -L${X11LIB} -lXft
+XFTFLAGS = -DXFT
+
 # includes and libs
-INCS = -I. -I/usr/include -I${X11INC}
-LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS}
+INCS = -I. -I/usr/include -I${X11INC} ${XFTINC}
+LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS} ${XFTLIBS}
 
 # flags
-CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
+CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} ${XFTFLAGS}
 #CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
 CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
 #LDFLAGS = -g ${LIBS}

dmenu

diff -upr a/config.mk b/config.mk
--- a/config.mk	2012-01-10 19:03:22.000000000 +0200
+++ b/config.mk	2012-01-10 19:03:38.000000000 +0200
@@ -12,9 +12,13 @@ X11LIB = /usr/X11R6/lib
 XINERAMALIBS  = -lXinerama
 XINERAMAFLAGS = -DXINERAMA
 
+# Xft, comment if you don't want it
+XFTINC = -I/usr/local/include/freetype2
+XFTLIBS  = -lXft -lXrender -lfreetype -lz -lfontconfig
+
 # includes and libs
-INCS = -I${X11INC}
-LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS}
+INCS = -I${X11INC} ${XFTINC}
+LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${XFTLIBS}
 
 # flags
 CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
diff -upr a/dmenu.1 b/dmenu.1
--- a/dmenu.1	2012-01-10 19:14:19.000000000 +0200
+++ b/dmenu.1	2012-01-10 19:14:23.000000000 +0200
@@ -53,7 +53,7 @@ dmenu lists items vertically, with the g
 defines the prompt to be displayed to the left of the input field.
 .TP
 .BI \-fn " font"
-defines the font or font set used.
+defines the font or font set used. eg. "fixed" or "Monospace-12:normal" (an xft font)
 .TP
 .BI \-nb " color"
 defines the normal background color.
diff -upr a/dmenu.c b/dmenu.c
--- a/dmenu.c	2012-01-10 19:14:19.000000000 +0200
+++ b/dmenu.c	2012-01-10 19:24:39.000000000 +0200
@@ -17,6 +17,7 @@
                              * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
 #define MIN(a,b)              ((a) < (b) ? (a) : (b))
 #define MAX(a,b)              ((a) > (b) ? (a) : (b))
+#define DEFFONT "fixed" /* xft example: "Monospace-11" */
 
 typedef struct Item Item;
 struct Item {
@@ -26,6 +27,7 @@ struct Item {
 
 static void appenditem(Item *item, Item **list, Item **last);
 static void calcoffsets(void);
+static void cleanup(void);
 static char *cistrstr(const char *s, const char *sub);
 static void drawmenu(void);
 static void grabkeyboard(void);
@@ -50,10 +52,12 @@ static const char *normfgcolor = "#bbbbb
 static const char *selbgcolor  = "#005577";
 static const char *selfgcolor  = "#eeeeee";
 static unsigned int lines = 0;
-static unsigned long normcol[ColLast];
-static unsigned long selcol[ColLast];
+static ColorSet *normcol;
+static ColorSet *selcol;
 static Atom clip, utf8;
 static Bool topbar = True;
+static Bool running = True;
+static int ret = 0;
 static DC *dc;
 static Item *items = NULL;
 static Item *matches, *matchend;
@@ -104,7 +108,9 @@ main(int argc, char *argv[]) {
 			usage();
 
 	dc = initdc();
-	initfont(dc, font);
+	initfont(dc, font ? font : DEFFONT);
+	normcol = initcolor(dc, normfgcolor, normbgcolor);
+	selcol = initcolor(dc, selfgcolor, selbgcolor);
 
 	if(fast) {
 		grabkeyboard();
@@ -117,7 +123,8 @@ main(int argc, char *argv[]) {
 	setup();
 	run();
 
-	return 1; /* unreachable */
+	cleanup();
+	return ret;
 }
 
 void
@@ -160,6 +167,15 @@ cistrstr(const char *s, const char *sub)
 }
 
 void
+cleanup(void) {
+    freecol(dc, normcol);
+    freecol(dc, selcol);
+    XDestroyWindow(dc->dpy, win);
+    XUngrabKeyboard(dc->dpy, CurrentTime);
+    freedc(dc);
+}
+
+void
 drawmenu(void) {
 	int curpos;
 	Item *item;
@@ -167,7 +183,7 @@ drawmenu(void) {
 	dc->x = 0;
 	dc->y = 0;
 	dc->h = bh;
-	drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol));
+	drawrect(dc, 0, 0, mw, mh, True, normcol->BG);
 
 	if(prompt) {
 		dc->w = promptw;
@@ -178,7 +194,7 @@ drawmenu(void) {
 	dc->w = (lines > 0 || !matches) ? mw - dc->x : inputw;
 	drawtext(dc, text, normcol);
 	if((curpos = textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w)
-		drawrect(dc, curpos, 2, 1, dc->h - 4, True, FG(dc, normcol));
+		drawrect(dc, curpos, 2, 1, dc->h - 4, True, normcol->FG);
 
 	if(lines > 0) {
 		/* draw vertical list */
@@ -321,7 +337,8 @@ keypress(XKeyEvent *ev) {
 		sel = matchend;
 		break;
 	case XK_Escape:
-		exit(EXIT_FAILURE);
+        ret = EXIT_FAILURE;
+        running = False;
 	case XK_Home:
 		if(sel == matches) {
 			cursor = 0;
@@ -359,7 +376,8 @@ keypress(XKeyEvent *ev) {
 	case XK_Return:
 	case XK_KP_Enter:
 		puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
-		exit(EXIT_SUCCESS);
+		ret = EXIT_SUCCESS;
+		running = False;
 	case XK_Right:
 		if(text[cursor] != '\0') {
 			cursor = nextrune(+1);
@@ -490,7 +508,7 @@ void
 run(void) {
 	XEvent ev;
 
-	while(!XNextEvent(dc->dpy, &ev)) {
+	while(running && !XNextEvent(dc->dpy, &ev)) {
 		if(XFilterEvent(&ev, win))
 			continue;
 		switch(ev.type) {
@@ -524,11 +542,6 @@ setup(void) {
 	XineramaScreenInfo *info;
 #endif
 
-	normcol[ColBG] = getcolor(dc, normbgcolor);
-	normcol[ColFG] = getcolor(dc, normfgcolor);
-	selcol[ColBG]  = getcolor(dc, selbgcolor);
-	selcol[ColFG]  = getcolor(dc, selfgcolor);
-
 	clip = XInternAtom(dc->dpy, "CLIPBOARD",   False);
 	utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
 
@@ -582,7 +595,7 @@ setup(void) {
 
 	/* create menu window */
 	swa.override_redirect = True;
-	swa.background_pixel = normcol[ColBG];
+	swa.background_pixel = normcol->BG;
 	swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
 	win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
 	                    DefaultDepth(dc->dpy, screen), CopyFromParent,
diff -upr a/draw.c b/draw.c
--- a/draw.c	2012-01-10 19:14:19.000000000 +0200
+++ b/draw.c	2012-01-10 19:14:23.000000000 +0200
@@ -9,9 +9,6 @@
 
 #define MAX(a, b)  ((a) > (b) ? (a) : (b))
 #define MIN(a, b)  ((a) < (b) ? (a) : (b))
-#define DEFAULTFN  "fixed"
-
-static Bool loadfont(DC *dc, const char *fontstr);
 
 void
 drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color) {
@@ -23,7 +20,7 @@ drawrect(DC *dc, int x, int y, unsigned 
 }
 
 void
-drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
+drawtext(DC *dc, const char *text, ColorSet *col) {
 	char buf[BUFSIZ];
 	size_t mn, n = strlen(text);
 
@@ -35,19 +32,24 @@ drawtext(DC *dc, const char *text, unsig
 	if(mn < n)
 		for(n = MAX(mn-3, 0); n < mn; buf[n++] = '.');
 
-	drawrect(dc, 0, 0, dc->w, dc->h, True, BG(dc, col));
+	drawrect(dc, 0, 0, dc->w, dc->h, True, col->BG);
 	drawtextn(dc, buf, mn, col);
 }
 
 void
-drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]) {
+drawtextn(DC *dc, const char *text, size_t n, ColorSet *col) {
 	int x = dc->x + dc->font.height/2;
 	int y = dc->y + dc->font.ascent+1;
 
-	XSetForeground(dc->dpy, dc->gc, FG(dc, col));
-	if(dc->font.set)
+	XSetForeground(dc->dpy, dc->gc, col->FG);
+	if(dc->font.xft_font) {
+		if (!dc->xftdraw)
+			eprintf("error, xft drawable does not exist");
+		XftDrawStringUtf8(dc->xftdraw, &col->FG_xft,
+			dc->font.xft_font, x, y, (unsigned char*)text, n);
+	} else if(dc->font.set) {
 		XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y, text, n);
-	else {
+	} else {
 		XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid);
 		XDrawString(dc->dpy, dc->canvas, dc->gc, x, y, text, n);
 	}
@@ -69,16 +71,33 @@ eprintf(const char *fmt, ...) {
 }
 
 void
+freecol(DC *dc, ColorSet *col) {
+    if(col) {
+        if(&col->FG_xft)
+            XftColorFree(dc->dpy, DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
+                DefaultColormap(dc->dpy, DefaultScreen(dc->dpy)), &col->FG_xft);
+        free(col); 
+    }
+}
+
+void
 freedc(DC *dc) {
+    if(dc->font.xft_font) {
+        XftFontClose(dc->dpy, dc->font.xft_font);
+        XftDrawDestroy(dc->xftdraw);
+    }
 	if(dc->font.set)
 		XFreeFontSet(dc->dpy, dc->font.set);
-	if(dc->font.xfont)
+    if(dc->font.xfont)
 		XFreeFont(dc->dpy, dc->font.xfont);
-	if(dc->canvas)
+    if(dc->canvas)
 		XFreePixmap(dc->dpy, dc->canvas);
-	XFreeGC(dc->dpy, dc->gc);
-	XCloseDisplay(dc->dpy);
-	free(dc);
+	if(dc->gc)
+        XFreeGC(dc->dpy, dc->gc);
+	if(dc->dpy)
+        XCloseDisplay(dc->dpy);
+	if(dc)
+        free(dc);
 }
 
 unsigned long
@@ -91,6 +110,20 @@ getcolor(DC *dc, const char *colstr) {
 	return color.pixel;
 }
 
+ColorSet *
+initcolor(DC *dc, const char * foreground, const char * background) {
+	ColorSet * col = (ColorSet *)malloc(sizeof(ColorSet));
+	if(!col)
+		eprintf("error, cannot allocate memory for color set");
+	col->BG = getcolor(dc, background);
+	col->FG = getcolor(dc, foreground);
+	if(dc->font.xft_font)
+		if(!XftColorAllocName(dc->dpy, DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
+			DefaultColormap(dc->dpy, DefaultScreen(dc->dpy)), foreground, &col->FG_xft))
+			eprintf("error, cannot allocate xft font color '%s'\n", foreground);
+	return col;
+}
+
 DC *
 initdc(void) {
 	DC *dc;
@@ -109,39 +142,33 @@ initdc(void) {
 
 void
 initfont(DC *dc, const char *fontstr) {
-	if(!loadfont(dc, fontstr ? fontstr : DEFAULTFN)) {
-		if(fontstr != NULL)
-			fprintf(stderr, "cannot load font '%s'\n", fontstr);
-		if(fontstr == NULL || !loadfont(dc, DEFAULTFN))
-			eprintf("cannot load font '%s'\n", DEFAULTFN);
-	}
-	dc->font.height = dc->font.ascent + dc->font.descent;
-}
-
-Bool
-loadfont(DC *dc, const char *fontstr) {
 	char *def, **missing, **names;
 	int i, n;
 	XFontStruct **xfonts;
 
-	if(!*fontstr)
-		return False;
-	if((dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def))) {
+	missing = NULL;
+	if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) {
+		dc->font.ascent = dc->font.xfont->ascent;
+		dc->font.descent = dc->font.xfont->descent;
+		dc->font.width   = dc->font.xfont->max_bounds.width;
+	} else if((dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def))) {
 		n = XFontsOfFontSet(dc->font.set, &xfonts, &names);
 		for(i = 0; i < n; i++) {
 			dc->font.ascent  = MAX(dc->font.ascent,  xfonts[i]->ascent);
 			dc->font.descent = MAX(dc->font.descent, xfonts[i]->descent);
 			dc->font.width   = MAX(dc->font.width,   xfonts[i]->max_bounds.width);
 		}
-	}
-	else if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) {
-		dc->font.ascent  = dc->font.xfont->ascent;
-		dc->font.descent = dc->font.xfont->descent;
-		dc->font.width   = dc->font.xfont->max_bounds.width;
+	} else if((dc->font.xft_font = XftFontOpenName(dc->dpy, DefaultScreen(dc->dpy), fontstr))) {
+		dc->font.ascent = dc->font.xft_font->ascent;
+		dc->font.descent = dc->font.xft_font->descent;
+		dc->font.width = dc->font.xft_font->max_advance_width;
+	} else {
+		eprintf("cannot load font '%s'\n", fontstr);
 	}
 	if(missing)
 		XFreeStringList(missing);
-	return dc->font.set || dc->font.xfont;
+	dc->font.height = dc->font.ascent + dc->font.descent;
+	return;
 }
 
 void
@@ -151,20 +178,29 @@ mapdc(DC *dc, Window win, unsigned int w
 
 void
 resizedc(DC *dc, unsigned int w, unsigned int h) {
+	int screen = DefaultScreen(dc->dpy);
 	if(dc->canvas)
 		XFreePixmap(dc->dpy, dc->canvas);
 
 	dc->w = w;
 	dc->h = h;
 	dc->canvas = XCreatePixmap(dc->dpy, DefaultRootWindow(dc->dpy), w, h,
-	                           DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)));
+	                           DefaultDepth(dc->dpy, screen));
+	if(dc->font.xft_font && !(dc->xftdraw)) {
+		dc->xftdraw = XftDrawCreate(dc->dpy, dc->canvas, DefaultVisual(dc->dpy,screen), DefaultColormap(dc->dpy,screen));
+		if(!(dc->xftdraw))
+			eprintf("error, cannot create xft drawable\n");
+	}
 }
 
 int
 textnw(DC *dc, const char *text, size_t len) {
-	if(dc->font.set) {
+	if(dc->font.xft_font) {
+		XGlyphInfo gi;
+		XftTextExtentsUtf8(dc->dpy, dc->font.xft_font, (const FcChar8*)text, len, &gi);
+		return gi.width;
+	} else if(dc->font.set) {
 		XRectangle r;
-
 		XmbTextExtents(dc->font.set, text, len, NULL, &r);
 		return r.width;
 	}
diff -upr a/draw.h b/draw.h
--- a/draw.h	2012-01-10 19:14:19.000000000 +0200
+++ b/draw.h	2012-01-10 19:14:23.000000000 +0200
@@ -1,9 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 
-#define FG(dc, col)  ((col)[(dc)->invert ? ColBG : ColFG])
-#define BG(dc, col)  ((col)[(dc)->invert ? ColFG : ColBG])
-
-enum { ColBG, ColFG, ColBorder, ColLast };
+#include <X11/Xft/Xft.h>
 
 typedef struct {
 	int x, y, w, h;
@@ -11,6 +8,7 @@ typedef struct {
 	Display *dpy;
 	GC gc;
 	Pixmap canvas;
+	XftDraw *xftdraw;
 	struct {
 		int ascent;
 		int descent;
@@ -18,15 +16,24 @@ typedef struct {
 		int width;
 		XFontSet set;
 		XFontStruct *xfont;
+		XftFont *xft_font;
 	} font;
 } DC;  /* draw context */
 
+typedef struct {
+	unsigned long FG;
+	XftColor FG_xft;
+	unsigned long BG;
+} ColorSet;
+
 void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color);
-void drawtext(DC *dc, const char *text, unsigned long col[ColLast]);
-void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]);
+void drawtext(DC *dc, const char *text, ColorSet *col);
+void drawtextn(DC *dc, const char *text, size_t n, ColorSet *col);
+void freecol(DC *dc, ColorSet *col);
 void eprintf(const char *fmt, ...);
 void freedc(DC *dc);
 unsigned long getcolor(DC *dc, const char *colstr);
+ColorSet *initcolor(DC *dc, const char *foreground, const char *background);
 DC *initdc(void);
 void initfont(DC *dc, const char *fontstr);
 void mapdc(DC *dc, Window win, unsigned int w, unsigned int h);

Offline

#4 2013-06-18 20:42:19

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

Re: [SOLVED] can't change dwm bar size after applying xft patch

Patches look fine, did you change your font string as I said? If you have, try another font.


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

#5 2013-06-18 22:38:04

b1tH1de0
Member
Registered: 2013-06-05
Posts: 17

Re: [SOLVED] can't change dwm bar size after applying xft patch

Tried with "Inconsolata:size=8" defined in config.h and, unfortunately, no change. Also tried with Inconsolata-g with the same result. Then I switched back to terminus (the default) and noticed, that the bar did not return to it's expected size. My next best guess would be that one of the patches broke something.

Offline

#6 2013-06-18 22:43:56

b1tH1de0
Member
Registered: 2013-06-05
Posts: 17

Re: [SOLVED] can't change dwm bar size after applying xft patch

Heh.. it worked.

After some further experiments, I've changed "Inconsolata:size=8" to "inconsolata:size=8" and the bar is now at it's expected height.

Thanks for all the help Unia.

Offline

#7 2013-06-19 15:40:53

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

Re: [SOLVED] can't change dwm bar size after applying xft patch

Glad you got it working. Please do not forget to mark your topic as solved.


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

#8 2013-06-20 09:18:56

b1tH1de0
Member
Registered: 2013-06-05
Posts: 17

Re: [SOLVED] can't change dwm bar size after applying xft patch

After some more testing, this is not as simple, as it looks..

Just to be sure after changing font line in config.h I've changed it back bit did not get the previous result (chunky bar). The bar was the same. To be honest I don't have an idea, why dwm suddenly started to display the bar properly.

During the search for the problem root cause I've performed many minor tweaks to my setup simultaneously (changing font name in config.h being one of them). Any of them could have had impact.. I probably won't be able to reproduce the scenario. Shame that this post won't be of much help if anybody else finds him/herself in a similar situation.

Marking as solved.

Offline

#9 2013-06-20 11:20:26

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

Re: [SOLVED] can't change dwm bar size after applying xft patch

Did you just install the font when you tried it first? Maybe your font cache wasn't refreshed at first. The patch you linked to is fine, so it can't be that. Otherwise, you can try the patch found on my GitHub: https://github.com/Unia/DWM/blob/master … 0-xft.diff

Lastly, just to be sure, you do recompile DWM between changes? tongue


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

#10 2013-06-20 11:58:21

b1tH1de0
Member
Registered: 2013-06-05
Posts: 17

Re: [SOLVED] can't change dwm bar size after applying xft patch

I did recompile dwm and dmenu after every change made either to config.h or any of the source files.

I have to admit I don't remember if I did refresh font cache after each change. Will put it in my .xinitrc though so that next time my memory won't be a factor :-)

Last edited by b1tH1de0 (2013-06-20 11:59:54)

Offline

Board footer

Powered by FluxBB