commit 14c09cbc53cadfae19880565e9f9590f3553b572 parent f4e31a199c3723a012169526580e713eb525305d Author: Kris Maglione <kris@suckless.org> Date: Sat, 22 May 2010 18:58:37 -0400 Experimental demand-loading of Xft. Removed hard dependency. Diffstat:
43 files changed, 110 insertions(+), 44 deletions(-)
diff --git a/PKGBUILD b/PKGBUILD @@ -6,11 +6,12 @@ pkgdesc="The latest hg pull of wmii, a lightweight, dynamic window manager for X url="http://wmii.suckless.org" license=("MIT") arch=("i686" "x86_64") -depends=("libx11" "libxinerama" "libxrandr" "libxft") +depends=("libx11" "libxinerama" "libxrandr") makedepends=("mercurial") optdepends=("plan9port: for use of the alternative plan9port wmiirc" \ "python: for use of the alternative Python wmiirc" \ - "ruby-rumai: for use of the alternative Ruby wmiirc") + "ruby-rumai: for use of the alternative Ruby wmiirc" \ + "libxft: for anti-aliased font support") provides=("wmii") conflicts=("wmii") source=() diff --git a/cmd/menu/main.c b/cmd/menu/main.c @@ -7,6 +7,7 @@ #include "dat.h" #include <X11/Xproto.h> #include <locale.h> +#include <stdio.h> #include <strings.h> #include <unistd.h> #include <bio.h> diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h @@ -2,6 +2,8 @@ * See LICENSE file for license details. */ +#include <setjmp.h> + #ifdef VARARGCK # pragma varargck argpos debug 2 # pragma varargck argpos dprint 1 diff --git a/cmd/wmii/screen.c b/cmd/wmii/screen.c @@ -3,7 +3,6 @@ */ #include "dat.h" #include <math.h> -#include <stdlib.h> #include "fns.h" #ifdef notdef diff --git a/cmd/wmii9menu.c b/cmd/wmii9menu.c @@ -42,7 +42,6 @@ #include <stdarg.h> #include <stdbool.h> #include <stdio.h> -#include <stdlib.h> #include <string.h> #include <stuff/clientutil.h> diff --git a/cmd/wmiir.c b/cmd/wmiir.c @@ -4,7 +4,6 @@ #define IXP_NO_P9_ #define IXP_P9_STRUCTS #include <stdio.h> -#include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> diff --git a/config.mk b/config.mk @@ -20,21 +20,24 @@ include $(ROOT)/mk/gcc.mk CFLAGS += $(DEBUGCFLAGS) -O0 LDFLAGS += -g -SOLDFLAGS += $(LDFLAGS) -SHARED = -shared -Wl,-soname=$(SONAME) -STATIC = -static - # Compiler, Linker. Linker should usually *not* be ld. CC = cc -c LD = cc # Archiver AR = ar crs -X11PACKAGES = xft +X11PACKAGES = x11 xinerama xrender INCX11 = $$(pkg-config --cflags $(X11PACKAGES)) -LIBICONV = # Leave blank if your libc includes iconv (glibc does) LIBIXP = $(LIBDIR)/libixp.a +# Enable RTLD. Only necessary for Xft support. +CFLAGS += -DHAVE_RTLD +LDFLAGS += -ldl # Comment this out on BSD systems. + +SOLDFLAGS += $(LDFLAGS) +SHARED = -shared -Wl,-soname=$(SONAME) +STATIC = -static + # Your make shell. By default, the first found of /bin/dash, /bin/ksh, # /bin/sh. Except with bsdmake, which assumes /bin/sh is sane. bash and zsh # are painfully slow, and should be avoided. @@ -50,9 +53,7 @@ LIBIXP = $(LIBDIR)/libixp.a #CC=pcc -c #LD=pcc -# *BSD -#LIBICONV = -L/usr/local/lib -liconv -# +Darwin +# Darwin #STATIC = # Darwin doesn't like static linking #SHARED = -dynamiclib #SOEXT = dylib diff --git a/include/stuff/base.h b/include/stuff/base.h @@ -2,6 +2,8 @@ #define _XOPEN_SOURCE 600 #include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> #ifndef nil #define nil ((void*)0) diff --git a/include/stuff/x11.h b/include/stuff/x11.h @@ -7,7 +7,6 @@ #include <stuff/geom.h> #include <X11/Xlib.h> #include <X11/Xutil.h> -#include <X11/Xft/Xft.h> #include <X11/extensions/Xrender.h> #ifdef _X11_VISIBLE # include <X11/Xatom.h> @@ -44,6 +43,10 @@ typedef struct Screen Screen; typedef struct WinHints WinHints; typedef struct Window Image; typedef struct Window Window; +typedef struct Xft Xft; +typedef struct XftColor XftColor; +typedef void XftDraw; +typedef struct XftFont XftFont; struct Color { ulong pixel; @@ -138,6 +141,30 @@ struct Window { int depth; }; +struct Xft { + XftDraw* (*drawcreate)(Display*, Drawable, Visual*, Colormap); + void (*drawdestroy)(XftDraw*); + XftFont* (*fontopen)(Display*, int, const char*); + XftFont* (*fontopenname)(Display*, int, const char*); + XftFont* (*fontclose)(Display*, XftFont*); + void (*textextents)(Display*, XftFont*, char*, int len, XGlyphInfo*); + void (*drawstring)(Display*, XftColor*, XftFont*, int x, int y, char*, int len); +}; + +struct XftColor { + ulong pixel; + XRenderColor color; +}; + +struct XftFont { + int ascent; + int descent; + int height; + int max_advance_width; + void* charset; + void* pattern; +}; + struct Screen { int screen; Window root; @@ -165,6 +192,7 @@ Screen scr; extern const Point ZP; extern const Rectangle ZR; extern Window* pointerwin; +extern Xft* xft; XRectangle XRect(Rectangle r); @@ -205,6 +233,7 @@ ulong getprop_ulong(Window*, char*, char*, ulong, ulong**, ulong); ulong getproperty(Window*, char *prop, char *type, Atom *actual, ulong offset, uchar **ret, ulong length); int grabkeyboard(Window*); int grabpointer(Window*, Window *confine, Cursor, int mask); +bool havexft(void); void initdisplay(void); KeyCode keycode(char*); uint labelh(Font*); diff --git a/libstuff/Makefile b/libstuff/Makefile @@ -86,6 +86,7 @@ OBJ=\ x11/sync \ x11/x11 \ x11/xatom \ + x11/xft \ x11/colors/loadcolor \ x11/colors/namedcolor \ x11/colors/xftcolor \ diff --git a/libstuff/map.c b/libstuff/map.c @@ -1,6 +1,5 @@ /* Written by Kris Maglione */ /* Public domain */ -#include <stdlib.h> #include <string.h> #include <stuff/util.h> diff --git a/libstuff/util/_die.c b/libstuff/util/_die.c @@ -2,7 +2,6 @@ /* Public domain */ #include <sys/types.h> #include <signal.h> -#include <stdlib.h> #include <unistd.h> #include <fmt.h> #include "util.h" diff --git a/libstuff/util/backtrace.c b/libstuff/util/backtrace.c @@ -6,7 +6,6 @@ #include <sys/wait.h> #include <fcntl.h> #include <signal.h> -#include <stdlib.h> #include <bio.h> #include <plan9.h> diff --git a/libstuff/util/doublefork.c b/libstuff/util/doublefork.c @@ -2,7 +2,6 @@ * See LICENSE file for license details. */ #include <sys/wait.h> -#include <stdlib.h> #include <unistd.h> #include "util.h" diff --git a/libstuff/util/emalloc.c b/libstuff/util/emalloc.c @@ -1,6 +1,5 @@ /* Written by Kris Maglione <maglione.k at Gmail> */ /* Public domain */ -#include <stdlib.h> #include "util.h" void * diff --git a/libstuff/util/erealloc.c b/libstuff/util/erealloc.c @@ -1,6 +1,5 @@ /* Written by Kris Maglione <maglione.k at Gmail> */ /* Public domain */ -#include <stdlib.h> #include "util.h" void * diff --git a/libstuff/util/fatal.c b/libstuff/util/fatal.c @@ -1,6 +1,5 @@ /* Written by Kris Maglione <maglione.k at Gmail> */ /* Public domain */ -#include <stdlib.h> #include <fmt.h> #include "util.h" diff --git a/libstuff/util/freelater.c b/libstuff/util/freelater.c @@ -1,6 +1,5 @@ /* Written by Kris Maglione <maglione.k at Gmail> */ /* Public domain */ -#include <stdlib.h> #include "util.h" void* diff --git a/libstuff/util/getlong.c b/libstuff/util/getlong.c @@ -1,7 +1,6 @@ /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ -#include <stdlib.h> #include <string.h> #include <stuff/util.h> diff --git a/libstuff/util/getulong.c b/libstuff/util/getulong.c @@ -1,7 +1,6 @@ /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ -#include <stdlib.h> #include <string.h> #include <stuff/util.h> diff --git a/libstuff/util/join.c b/libstuff/util/join.c @@ -1,7 +1,6 @@ /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ -#include <stdlib.h> #include <fmt.h> #include "util.h" diff --git a/libstuff/util/mfatal.c b/libstuff/util/mfatal.c @@ -1,6 +1,5 @@ /* Written by Kris Maglione <maglione.k at Gmail> */ /* Public domain */ -#include <stdlib.h> #include <string.h> #include <unistd.h> #include "util.h" diff --git a/libstuff/util/pathsearch.c b/libstuff/util/pathsearch.c @@ -1,7 +1,6 @@ /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ -#include <stdlib.h> #include <string.h> #include <unistd.h> #include <fmt.h> diff --git a/libstuff/util/refree.c b/libstuff/util/refree.c @@ -1,7 +1,6 @@ /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ -#include <stdlib.h> #include "util.h" void diff --git a/libstuff/util/spawn3.c b/libstuff/util/spawn3.c @@ -2,7 +2,6 @@ * See LICENSE file for license details. */ #include <errno.h> -#include <stdlib.h> #include <unistd.h> #include "util.h" diff --git a/libstuff/util/spawn3l.c b/libstuff/util/spawn3l.c @@ -1,7 +1,6 @@ /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ -#include <stdlib.h> #include <fmt.h> #include "util.h" diff --git a/libstuff/util/vector.c b/libstuff/util/vector.c @@ -1,7 +1,6 @@ /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ -#include <stdlib.h> #include <string.h> #include "util.h" diff --git a/libstuff/x11/colors/loadcolor.c b/libstuff/x11/colors/loadcolor.c @@ -1,6 +1,7 @@ /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ +#include <string.h> #include "../x11.h" bool diff --git a/libstuff/x11/drawing/drawstring.c b/libstuff/x11/drawing/drawstring.c @@ -1,6 +1,7 @@ /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ +#include <string.h> #include "../x11.h" uint @@ -69,9 +70,9 @@ drawstring(Image *dst, Font *font, buf, len); break; case FXft: - XftDrawStringUtf8(xftdrawable(dst), xftcolor(col), - font->font.xft, - x, y, (uchar*)buf, len); + xft->drawstring(xftdrawable(dst), xftcolor(col), + font->font.xft, + x, y, buf, len); break; case FX11: XSetFont(display, dst->gc, font->font.x11->fid); diff --git a/libstuff/x11/images/freeimage.c b/libstuff/x11/images/freeimage.c @@ -11,7 +11,7 @@ freeimage(Image *img) { assert(img->type == WImage); if(img->xft) - XftDrawDestroy(img->xft); + xft->drawdestroy(img->xft); XFreePixmap(display, img->xid); XFreeGC(display, img->gc); free(img); diff --git a/libstuff/x11/images/xftdrawable.c b/libstuff/x11/images/xftdrawable.c @@ -6,6 +6,6 @@ XftDraw* xftdrawable(Image *img) { if(img->xft == nil) - img->xft = XftDrawCreate(display, img->xid, img->visual, img->colormap); + img->xft = xft->drawcreate(display, img->xid, img->visual, img->colormap); return img->xft; } diff --git a/libstuff/x11/insanity/sethints.c b/libstuff/x11/insanity/sethints.c @@ -1,6 +1,7 @@ /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ +#include <string.h> #include "../x11.h" void diff --git a/libstuff/x11/properties/changeprop_string.c b/libstuff/x11/properties/changeprop_string.c @@ -1,6 +1,7 @@ /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ +#include <string.h> #include "../x11.h" void diff --git a/libstuff/x11/properties/changeprop_textlist.c b/libstuff/x11/properties/changeprop_textlist.c @@ -1,6 +1,7 @@ /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ +#include <string.h> #include "../x11.h" void diff --git a/libstuff/x11/properties/strlistdup.c b/libstuff/x11/properties/strlistdup.c @@ -1,6 +1,7 @@ /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ +#include <string.h> #include "../x11.h" char** diff --git a/libstuff/x11/text/freefont.c b/libstuff/x11/text/freefont.c @@ -10,7 +10,7 @@ freefont(Font *f) { XFreeFontSet(display, f->font.set); break; case FXft: - XftFontClose(display, f->font.xft); + xft->fontclose(display, f->font.xft); break; case FX11: XFreeFont(display, f->font.x11); diff --git a/libstuff/x11/text/loadfont.c b/libstuff/x11/text/loadfont.c @@ -1,6 +1,7 @@ /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ +#include <string.h> #include "../x11.h" Font* @@ -17,9 +18,12 @@ loadfont(char *name) { if(!strncmp(f->name, "xft:", 4)) { f->type = FXft; - f->font.xft = XftFontOpenXlfd(display, scr.screen, f->name + 4); + if(!havexft()) + goto error; + + f->font.xft = xft->fontopen(display, scr.screen, f->name + 4); if(!f->font.xft) - f->font.xft = XftFontOpenName(display, scr.screen, f->name + 4); + f->font.xft = xft->fontopenname(display, scr.screen, f->name + 4); if(!f->font.xft) goto error; diff --git a/libstuff/x11/text/textextents_l.c b/libstuff/x11/text/textextents_l.c @@ -18,7 +18,7 @@ textextents_l(Font *font, char *text, uint len, int *offset) { *offset = Xutf8TextExtents(font->font.set, text, len, &r, nil); return Rect(r.x, -r.y - r.height, r.x + r.width, -r.y); case FXft: - XftTextExtentsUtf8(display, font->font.xft, (uchar*)text, len, &i); + xft->textextents(display, font->font.xft, text, len, &i); *offset = i.xOff; return Rect(-i.x, i.y - i.height, -i.x + i.width, i.y); case FX11: diff --git a/libstuff/x11/text/textwidth.c b/libstuff/x11/text/textwidth.c @@ -1,6 +1,7 @@ /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> * See LICENSE file for license details. */ +#include <string.h> #include "../x11.h" uint diff --git a/libstuff/x11/windows/destroywindow.c b/libstuff/x11/windows/destroywindow.c @@ -8,7 +8,7 @@ destroywindow(Window *w) { assert(w->type == WWindow); sethandler(w, nil); if(w->xft) - XftDrawDestroy(w->xft); + xft->drawdestroy(w->xft); if(w->gc) XFreeGC(display, w->gc); XDestroyWindow(display, w->xid); diff --git a/libstuff/x11/xft.c b/libstuff/x11/xft.c @@ -0,0 +1,39 @@ +/* Copyright ©2010 Kris Maglione <maglione.k at Gmail> + * See LICENSE file for license details. + */ +#include <stuff/x.h> +#include <stuff/util.h> + +Xft *xft; + +#ifdef HAVE_RTLD +#include <dlfcn.h> + +bool +havexft(void) { + void *libxft; + + if(xft == nil) { + libxft = dlopen("libXft.so", RTLD_LAZY); + if(libxft == nil) + return false; + xft = emalloc(sizeof *xft); + *(void**)(uintptr_t)&xft->drawcreate = dlsym(libxft, "XftDrawCreate"); + *(void**)(uintptr_t)&xft->drawdestroy = dlsym(libxft, "XftDrawDestroy"); + *(void**)(uintptr_t)&xft->fontopen = dlsym(libxft, "XftFontOpenXlfd"); + *(void**)(uintptr_t)&xft->fontopenname = dlsym(libxft, "XftFontOpenName"); + *(void**)(uintptr_t)&xft->fontclose = dlsym(libxft, "XftFontClose"); + *(void**)(uintptr_t)&xft->textextents = dlsym(libxft, "XftTextExtentsUtf8"); + *(void**)(uintptr_t)&xft->drawstring = dlsym(libxft, "XftDrawStringUtf8"); + } + return xft && xft->drawcreate && xft->drawdestroy && xft->fontopen + && xft->fontopenname && xft->fontclose && xft->textextents && xft->drawstring; +} + +#else +bool +havexft(void) { + return false; +} +#endif + diff --git a/libwmii_hack/hack.c b/libwmii_hack/hack.c @@ -4,7 +4,6 @@ #include "hack.h" #include <dlfcn.h> #include <stdbool.h> -#include <stdlib.h> #include <stdio.h> #include <sys/time.h> #include <sys/types.h> diff --git a/util/compile b/util/compile @@ -17,7 +17,7 @@ status=$? [ $? -eq 0 ] || echo $CC -o $outfile $CFLAGS $@ >&2 base=$(echo $BASE | sed 's/,/\\,/g') -re='\([^[:space:]/]*\..:[0-9]\)' +re='\([^[:space:]/][^[:space:]]*\..:[0-9]\)' undup() { # GCC is crap. awk '