Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

Commit

Permalink
Remove Pango
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjdskes committed Jul 12, 2014
1 parent 4806ce8 commit 81cc177
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 64 deletions.
2 changes: 1 addition & 1 deletion config.def.h
@@ -1,7 +1,7 @@
/* See LICENSE file for copyright and license details. */

/* appearance */
static const char font[] = "Sans 8";
static const char font[] = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
static const char normbordercolor[] = "#444444";
static const char normbgcolor[] = "#222222";
static const char normfgcolor[] = "#bbbbbb";
Expand Down
31 changes: 16 additions & 15 deletions config.h
Expand Up @@ -10,16 +10,17 @@
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }

/* appearance */
static const char font[] = "DejaVu Sans 8";
static const char normbordercolor[] = "#707070";
static const char normbgcolor[] = "#1D1F21";
static const char normfgcolor[] = "#F9F9F9";
static const char selbordercolor[] = "#DE935F";
static const char selbgcolor[] = "#1D1F21";
static const char selfgcolor[] = "#81A2BE";
static const char urgbgcolor[] = "#1D1F21";
static const char urgfgcolor[] = "#A54242";
static const unsigned int borderpx = 1;
//static const char font[] = "DejaVu Sans 8";
static const char font[] = "-*-dina-medium-r-*-*-10-*-*-*-*-*-*-*";
static const char normbordercolor[] = "#2a2a2a";
static const char normbgcolor[] = "#181b20";
static const char normfgcolor[] = "#605e5a";
static const char selbordercolor[] = "#765636";
static const char selbgcolor[] = "#181b20";
static const char selfgcolor[] = "#765636";
static const char urgbgcolor[] = "#181b20";
static const char urgfgcolor[] = "#744b40";
static const unsigned int borderpx = 2;
static const unsigned int snap = 2;
static const float mfact = 0.63;
static const int nmaster = 1;
Expand All @@ -42,7 +43,7 @@ static const Rule rules[] = {
{ "Firefox", NULL, NULL, 1 << 0, False, False, -1 },
{ "Dwb", NULL, NULL, 1 << 0, False, False, -1 },
{ "Skype", NULL, NULL, 1 << 1, False, True, -1 },
{ "Termite", NULL, NULL, 1 << 2, False, True, -1 },
{ "URxvt", NULL, NULL, 1 << 2, False, True, -1 },
{ "Eclipse", NULL, NULL, 1 << 3, False, False, -1 },
{ "Java", NULL, NULL, 1 << 3, True, False, -1 },
{ "MPlayer", NULL, NULL, 1 << 4, True, False, -1 },
Expand All @@ -51,17 +52,17 @@ static const Rule rules[] = {

/* commands */
static char dmenumon[2] = "0";
static const char *dmenu[] = { "dmenu_run", "-f", "-m", dmenumon, "-p", "Execute:", NULL };
static const char *dmenu[] = { "dmenu_run", "-f", "-m", dmenumon, "-p", "Uitvoeren:", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
static const char *find[] = { "dmenu_finder", NULL };
static const char *dmfm[] = { "dmenu_fm", NULL };
static const char *dmctl[] = { "dmenu_netctl", NULL };
static const char *term[] = { "termite", NULL };
static const char *term[] = { "urxvtc", NULL };
static const char *scrot[] = { "scrot", "/home/jente/afbeeldingen/screenshots/%d-%m-%Y-%R.png", NULL };
static const char *xkill[] = { "xkill", NULL };
static const char *lock[] = { "slock", NULL };
static const char *soff[] = { "xset", "dpms", "force", "off", NULL };
static const char *sup[] = { "xbacklight", "-inc", "10", NULL };
static const char *sdown[] = { "xbacklight", "-dec", "10", NULL };
static const char *sup[] = { "xbacklight", "-inc", "20%", NULL };
static const char *sdown[] = { "xbacklight", "-dec", "20%", NULL };
static const char *halt[] = { "dmenu_shutdown", NULL };
static const char *volup[] = { "amixer", "-q", "sset", "Master", "5%+", "unmute", NULL };
static const char *voldown[] = { "amixer", "-q", "sset", "Master", "5%-", "unmute", NULL };
Expand Down
4 changes: 2 additions & 2 deletions config.mk
Expand Up @@ -15,8 +15,8 @@ XINERAMALIBS = -lXinerama
XINERAMAFLAGS = -DXINERAMA

# includes and libs
INCS = -I${X11INC} `pkg-config --cflags xft pangoxft`
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} `pkg-config --libs xft pangoxft`
INCS = -I${X11INC}
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS}

# flags
CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
Expand Down
89 changes: 56 additions & 33 deletions drw.c
Expand Up @@ -3,8 +3,6 @@
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
#include <pango/pangoxft.h>

#include "drw.h"
#include "util.h"
Expand All @@ -20,7 +18,6 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
drw->w = w;
drw->h = h;
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
drw->xftdrawable = XftDrawCreate(dpy, drw->drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen));
drw->gc = XCreateGC(dpy, root, 0, NULL);
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
return drw;
Expand All @@ -40,59 +37,73 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h) {
void
drw_free(Drw *drw) {
XFreePixmap(drw->dpy, drw->drawable);
XftDrawDestroy(drw->xftdrawable);
XFreeGC(drw->dpy, drw->gc);
free(drw);
}

Fnt *
drw_font_create(Display *dpy, int screen, const char *fontname) {
drw_font_create(Display *dpy, const char *fontname) {
Fnt *font;
PangoContext *context;
PangoFontMap *fontmap;
PangoFontDescription *desc;
char *def, **missing;
int n;

font = (Fnt *)calloc(1, sizeof(Fnt));
if(!font)
return NULL;

fontmap = pango_xft_get_font_map(dpy, screen);
context = pango_font_map_create_context(fontmap);
font->layout = pango_layout_new(context);
g_object_unref(context);
desc = pango_font_description_from_string(fontname);
pango_layout_set_font_description(font->layout, desc);
pango_font_description_free(desc);

pango_layout_get_pixel_size(font->layout, NULL, &font->h);
font->set = XCreateFontSet(dpy, fontname, &missing, &n, &def);
if(missing) {
while(n--)
fprintf(stderr, "drw: missing fontset: %s\n", missing[n]);
XFreeStringList(missing);
}
if(font->set) {
XFontStruct **xfonts;
char **font_names;
XExtentsOfFontSet(font->set);
n = XFontsOfFontSet(font->set, &xfonts, &font_names);
while(n--) {
font->ascent = MAX(font->ascent, (*xfonts)->ascent);
font->descent = MAX(font->descent, (*xfonts)->descent);
xfonts++;
}
}
else {
if(!(font->xfont = XLoadQueryFont(dpy, fontname))
&& !(font->xfont = XLoadQueryFont(dpy, "fixed")))
die("error, cannot load font: '%s'\n", fontname);
font->ascent = font->xfont->ascent;
font->descent = font->xfont->descent;
}
font->h = font->ascent + font->descent;
return font;
}

void
drw_font_free(Display *dpy, Fnt *font) {
if(!font)
return;
g_object_unref(font->layout);
if(font->set)
XFreeFontSet(dpy, font->set);
else
XFreeFont(dpy, font->xfont);
free(font);
}

Clr *
drw_clr_create(Drw *drw, const char *clrname) {
Clr *clr;
Colormap cmap;
Visual *vis;
XftColor color;
XColor color;

if(!drw)
return NULL;
clr = (Clr *)calloc(1, sizeof(Clr));
if(!clr)
return NULL;
cmap = DefaultColormap(drw->dpy, drw->screen);
vis = DefaultVisual(drw->dpy, drw->screen);
if(!XftColorAllocName(drw->dpy, vis, cmap, clrname, &color))
if(!XAllocNamedColor(drw->dpy, cmap, clrname, &color, &color))
die("error, cannot allocate color '%s'\n", clrname);
clr->rgb = color;
clr->rgb = color.pixel;
return clr;
}

Expand Down Expand Up @@ -120,7 +131,7 @@ drw_rect(Drw *drw, int x, int y, int filled, int empty) {

if(!drw || !drw->font || !drw->scheme)
return;
XSetForeground(drw->dpy, drw->gc, drw->scheme->fg->rgb.pixel);
XSetForeground(drw->dpy, drw->gc, drw->scheme->fg->rgb);
dx = (drw->font->h + 2) / 4;
if(filled)
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx+1, dx+1);
Expand All @@ -131,18 +142,19 @@ drw_rect(Drw *drw, int x, int y, int filled, int empty) {
void
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text) {
char buf[256];
int i, tx, ty, len, olen;
int i, tx, ty, th, len, olen;
Extnts tex;

if(!drw || !drw->scheme)
return;
XSetForeground(drw->dpy, drw->gc, drw->scheme->bg->rgb.pixel);
XSetForeground(drw->dpy, drw->gc, drw->scheme->bg->rgb);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
if(!text || !drw->font)
return;
olen = strlen(text);
drw_font_getexts(drw->font, text, olen, &tex);
ty = y + (h / 2) - (drw->font->h / 2);
th = drw->font->ascent + drw->font->descent;
ty = y + (h / 2) - (th / 2) + drw->font->ascent;
tx = x + (h / 2);
/* shorten text if necessary */
for(len = MIN(olen, sizeof buf); len && (tex.w > w - tex.h || w < tex.h); len--)
Expand All @@ -152,9 +164,11 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex
memcpy(buf, text, len);
if(len < olen)
for(i = len; i && i > len - 3; buf[--i] = '.');
XSetForeground(drw->dpy, drw->gc, drw->scheme->fg->rgb.pixel);
pango_layout_set_text(drw->font->layout, buf, len);
pango_xft_render_layout(drw->xftdrawable, &drw->scheme->fg->rgb, drw->font->layout, tx * PANGO_SCALE, ty * PANGO_SCALE);
XSetForeground(drw->dpy, drw->gc, drw->scheme->fg->rgb);
if(drw->font->set)
XmbDrawString(drw->dpy, drw->drawable, drw->font->set, drw->gc, tx, ty, buf, len);
else
XDrawString(drw->dpy, drw->drawable, drw->gc, tx, ty, buf, len);
}

void
Expand All @@ -167,10 +181,19 @@ drw_map(Drw *drw, Window barwin, int x, int y, unsigned int w, unsigned int h) {

void
drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex) {
XRectangle r;

if(!font || !text)
return;
pango_layout_set_text(font->layout, text, len);
pango_layout_get_pixel_size(font->layout, &tex->w, &tex->h);
if(font->set) {
XmbTextExtents(font->set, text, len, NULL, &r);
tex->w = r.width;
tex->h = r.height;
}
else {
tex->h = font->ascent + font->descent;
tex->w = XTextWidth(font->xfont, text, len);
}
}

int
Expand Down
15 changes: 7 additions & 8 deletions drw.h
@@ -1,19 +1,19 @@
/* See LICENSE file for copyright and license details. */

#include <X11/Xft/Xft.h>
#include <pango/pango.h>

typedef struct {
XftColor rgb;
unsigned long rgb;
} Clr;

typedef struct {
Cursor cursor;
} Cur;

typedef struct {
int h;
PangoLayout *layout;
int ascent;
int descent;
unsigned int h;
XFontSet set;
XFontStruct *xfont;
} Fnt;

typedef struct {
Expand All @@ -28,7 +28,6 @@ typedef struct {
int screen;
Window root;
Drawable drawable;
XftDraw *xftdrawable;
GC gc;
ClrScheme *scheme;
Fnt *font;
Expand All @@ -45,7 +44,7 @@ void drw_resize(Drw *drw, unsigned int w, unsigned int h);
void drw_free(Drw *drw);

/* Fnt abstraction */
Fnt *drw_font_create(Display *dpy, int screen, const char *fontname);
Fnt *drw_font_create(Display *dpy, const char *fontname);
void drw_font_free(Display *dpy, Fnt *font);
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *extnts);
int drw_font_getexts_width(Fnt *font, const char *text, unsigned int len);
Expand Down
10 changes: 5 additions & 5 deletions dwm.c
Expand Up @@ -847,7 +847,7 @@ focus(Client *c) {
detachstack(c);
attachstack(c);
grabbuttons(c, True);
XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->rgb.pixel);
XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->rgb);
setfocus(c);
}
else {
Expand Down Expand Up @@ -1096,7 +1096,7 @@ manage(Window w, XWindowAttributes *wa) {

wc.border_width = c->bw;
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->rgb.pixel);
XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->rgb);
configure(c); /* propagates border_width, if size doesn't change */
updatewindowtype(c);
updatesizehints(c);
Expand Down Expand Up @@ -1614,7 +1614,7 @@ setup(void) {
/* init screen */
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
fnt = drw_font_create(dpy, screen, font);
fnt = drw_font_create(dpy, font);
sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen);
bh = fnt->h + 6;
Expand Down Expand Up @@ -1803,7 +1803,7 @@ unfocus(Client *c, Bool setfocus) {
if(!c)
return;
grabbuttons(c, False);
XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->rgb.pixel);
XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->rgb);
if(setfocus) {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
Expand Down Expand Up @@ -2077,7 +2077,7 @@ updatewmhints(Client *c) {
else {
c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
if(c->isurgent)
XSetWindowBorder(dpy, c->win, scheme[SchemeUrg].border->rgb.pixel);
XSetWindowBorder(dpy, c->win, scheme[SchemeUrg].border->rgb);
}
if(wmh->flags & InputHint)
c->neverfocus = !wmh->input;
Expand Down

0 comments on commit 81cc177

Please sign in to comment.