Experimental demand-loading of Xft. Removed hard dependency.

This commit is contained in:
Kris Maglione 2010-05-22 18:58:37 -04:00
parent f4e31a199c
commit 14c09cbc53
43 changed files with 110 additions and 44 deletions

View File

@ -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=()

View File

@ -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>

View File

@ -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

View File

@ -3,7 +3,6 @@
*/
#include "dat.h"
#include <math.h>
#include <stdlib.h>
#include "fns.h"
#ifdef notdef

View File

@ -42,7 +42,6 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stuff/clientutil.h>

View File

@ -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>

View File

@ -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

View File

@ -2,6 +2,8 @@
#define _XOPEN_SOURCE 600
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#ifndef nil
#define nil ((void*)0)

View File

@ -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*);

View File

@ -86,6 +86,7 @@ OBJ=\
x11/sync \
x11/x11 \
x11/xatom \
x11/xft \
x11/colors/loadcolor \
x11/colors/namedcolor \
x11/colors/xftcolor \

View File

@ -1,6 +1,5 @@
/* Written by Kris Maglione */
/* Public domain */
#include <stdlib.h>
#include <string.h>
#include <stuff/util.h>

View File

@ -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"

View File

@ -6,7 +6,6 @@
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <bio.h>
#include <plan9.h>

View File

@ -2,7 +2,6 @@
* See LICENSE file for license details.
*/
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include "util.h"

View File

@ -1,6 +1,5 @@
/* Written by Kris Maglione <maglione.k at Gmail> */
/* Public domain */
#include <stdlib.h>
#include "util.h"
void *

View File

@ -1,6 +1,5 @@
/* Written by Kris Maglione <maglione.k at Gmail> */
/* Public domain */
#include <stdlib.h>
#include "util.h"
void *

View File

@ -1,6 +1,5 @@
/* Written by Kris Maglione <maglione.k at Gmail> */
/* Public domain */
#include <stdlib.h>
#include <fmt.h>
#include "util.h"

View File

@ -1,6 +1,5 @@
/* Written by Kris Maglione <maglione.k at Gmail> */
/* Public domain */
#include <stdlib.h>
#include "util.h"
void*

View File

@ -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>

View File

@ -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>

View File

@ -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"

View File

@ -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"

View File

@ -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>

View File

@ -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

View File

@ -2,7 +2,6 @@
* See LICENSE file for license details.
*/
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include "util.h"

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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**

View File

@ -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);

View File

@ -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;

View File

@ -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:

View File

@ -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

View File

@ -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);

39
libstuff/x11/xft.c Normal file
View File

@ -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

View File

@ -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>

View File

@ -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 '