commit - b64495df1ad4f88c344bc178795477f484a1129c
commit + 77968eb56bf7e10e9bdf758e44e280877079b655
blob - 117bed2c90dfa84804086314af1175f9300faebd
blob + f203501e7576702db83a2b8d22d631cb435e2a42
--- config.mk
+++ config.mk
PREFIX ?= /usr/local
MANPREFIX ?= /usr/local/man
+X11INC = /usr/X11R6/include
+X11LIB = /usr/X11R6/lib
+
+FREETYPELIBS = -lfontconfig -lXft
+FREETYPEINC = $(X11INC)/freetype2
+
CFLAGS = -std=c99 -Wall -pedantic
-CPPFLAGS = -I/usr/X11R6/include
-LDFLAGS = -L/usr/X11R6/lib -lX11
+CPPFLAGS = -I$(X11INC) -I$(FREETYPEINC)
+LDFLAGS = -L$(X11LIB) -lX11 $(FREETYPELIBS)
# debug
#CFLAGS = -std=c99 -Wall -pedantic -Wextra -O0 -g3
blob - 1adf25493a4ab230b04053aabecdaed091f4ad81
blob + 6143ffec18a9a15c0465453d75b1030332e58e0d
--- xitems.1
+++ xitems.1
The font to be used for displaying text.
Corresponds to the resource font.
Default is
-.Dq fixed .
+.Dq DejaVu Sans Mono-10 .
.It Fl bg Ar colour
Specifies the normal background colour.
Corresponds to the resource background.
blob - 321bbbd73581080259e93ea4eb82bfc057b3fe66
blob + 0ab84c5260cdd2c0f8d3785d464c1b4bdf6ed50c
--- xitems.c
+++ xitems.c
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
+#include <X11/Xft/Xft.h>
#define PROGNAME "xitems"
#define MAXKS 32
static Display *dpy = NULL;
static int screen;
static Window win;
-static GC gc;
-static XColor c_fg, c_sbg, c_sfg;
-static XFontStruct *font;
static int height, width; /* height and width of one item */
+static XftFont *font;
+static XftColor c_fg, c_sfg, c_sbg;
/* selpos -- mark the item at position y (from top) as selected. */
static void
struct item *it = first;
int y = 0;
+ static XftDraw *d = NULL;
+
+ if (!d && !(d = XftDrawCreate(dpy, win, DefaultVisual(dpy, screen),
+ DefaultColormap(dpy, screen))))
+ die(1, "couldn't create XftDraw");
+
do {
if (it->dirty) {
+ XftColor *xftc;
+
XClearArea(dpy, win, 0, y, width, height, False);
if (it == selected) {
- XSetForeground(dpy, gc, c_sbg.pixel);
- XFillRectangle(dpy, win, gc, 0, y,
- width, height);
- XSetForeground(dpy, gc, c_sfg.pixel);
+ xftc = &c_sfg;
+ XftDrawRect(d, &c_sbg, 0, y, width, height);
} else
- XSetForeground(dpy, gc, c_fg.pixel);
+ xftc = &c_fg;
- XDrawString(dpy, win, gc, o_hp, y + o_vp+font->ascent,
- it->s, it->len);
+ XftDrawStringUtf8(d, xftc, font,
+ o_hp, y + o_vp+font->ascent,
+ (FcChar8 *)it->s, it->len);
it->dirty = false;
}
die(1, "couldn't grab keyboard");
}
+/* alloccol_xft -- safely allocate new Xft colour c from string s. */
static void
+alloccol_xft(char *s, XftColor *c)
+{
+ if (!(XftColorAllocName(dpy, DefaultVisual(dpy, screen),
+ DefaultColormap(dpy, screen), s, c)))
+ die(1, "couldn't allocate Xft colour %s\n", s);
+}
+
+/* alloccol -- safely allocate new colour c from string s. */
+static void
alloccol(char *s, XColor *c)
{
XColor dummy;
setupx(int n)
{
struct item *it;
- XGCValues gcv;
XColor col;
XClassHint ch = {PROGNAME, PROGNAME};
XSetWindowAttributes swa = {
PointerMotionMask | LeaveWindowMask | EnterWindowMask,
};
- if (!(font = XLoadQueryFont(dpy, o_font)))
+ if (!(font = XftFontOpenName(dpy, screen, o_font)))
die(1, "couldn't load font");
- height = font->ascent + font->descent + o_vp;
+ height = font->height + o_vp;
it = first;
do {
- int w;
- if ((w = XTextWidth(font, it->s, it->len) + o_hp*2) > width)
- width = w;
+ XGlyphInfo gi;
+ XftTextExtentsUtf8(dpy, font, (FcChar8 *)it->s, it->len, &gi);
+ if (gi.xOff + o_hp*2 > width)
+ width = gi.xOff + o_hp*2;
it = it->next;
} while (it != first);
CWEventMask | CWSaveUnder, &swa);
XSetClassHint(dpy, win, &ch);
- alloccol(o_sbg, &c_sbg);
- alloccol(o_sfg, &c_sfg);
- alloccol(o_fg, &c_fg);
-
- gc = XCreateGC(dpy, win, 0, &gcv);
+ alloccol_xft(o_fg, &c_fg);
+ alloccol_xft(o_sfg, &c_sfg);
+ alloccol_xft(o_sbg, &c_sbg);
grabkb();
grabptr();
if (!o_fg)
o_fg = sdefault("foreground", "black");
if (!o_font)
- o_font = sdefault("font", "fixed");
+ o_font = sdefault("font", "DejaVu Sans Mono-10");
if (!o_sbg)
o_sbg = sdefault("selectedBackground", "black");
if (!o_sfg)