commit 445976869eafe12183d8279f4e5023c299533e09
parent 09b8c2961af5c4ad5d881e612a8c8290c4ccb256
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Sun, 23 Apr 2006 20:00:47 +0200
polished liblitz, now going to support XFontSets
Diffstat:
14 files changed, 130 insertions(+), 103 deletions(-)
diff --git a/cmd/wm/bar.c b/cmd/wm/bar.c
@@ -64,7 +64,7 @@ unsigned int
height_of_bar()
{
enum { BAR_PADDING = 4 };
- return xfont->ascent + xfont->descent + BAR_PADDING;
+ return blitzfont.font->ascent + blitzfont.font->descent + BAR_PADDING;
}
void
@@ -99,14 +99,14 @@ draw_bar()
{
unsigned int i = 0, w = 0;
int exp = -1;
- Draw d = { 0 };
+ BlitzDraw d = { 0 };
Bar *l = nil;
d.gc = bargc;
d.drawable = barpmap;
d.rect = brect;
d.rect.x = d.rect.y = 0;
- d.font = xfont;
+ d.font = blitzfont;
d.color = def.norm;
blitz_drawlabel(dpy, &d);
@@ -127,7 +127,7 @@ draw_bar()
l->rect.y = 0;
l->rect.width = brect.height;
if(strlen(l->data))
- l->rect.width += XTextWidth(xfont, l->data, strlen(l->data));
+ l->rect.width += XTextWidth(blitzfont.font, l->data, strlen(l->data));
l->rect.height = brect.height;
w += l->rect.width;
}
diff --git a/cmd/wm/client.c b/cmd/wm/client.c
@@ -213,13 +213,13 @@ prop_client(Client *c, XPropertyEvent *e)
void
draw_client(Client *c)
{
- Draw d = { 0 };
+ BlitzDraw d = { 0 };
if(!c->frame.size)
return; /* might not have been attached atm */
d.drawable = c->framewin;
- d.font = xfont;
+ d.font = blitzfont;
d.gc = c->gc;
if(c == sel_client())
@@ -250,7 +250,7 @@ draw_client(Client *c)
idx_of_frame(c->frame.data[c->sel]) + 1,
c->frame.data[c->sel]->area->frame.size);
d.align = CENTER;
- d.rect.width = d.rect.height + XTextWidth(xfont, buf, strlen(buf));
+ d.rect.width = d.rect.height + XTextWidth(blitzfont.font, buf, strlen(buf));
d.data = buf;
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
@@ -260,7 +260,7 @@ draw_client(Client *c)
}
/* tag bar */
- d.rect.width = d.rect.height + XTextWidth(xfont, c->tags, strlen(c->tags));
+ d.rect.width = d.rect.height + XTextWidth(blitzfont.font, c->tags, strlen(c->tags));
d.data = c->tags;
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
diff --git a/cmd/wm/event.c b/cmd/wm/event.c
@@ -77,7 +77,7 @@ handle_buttonpress(XEvent *e)
if(ev->button == Button1)
do_mouse_move(c);
else if (ev->button == Button3) {
- Align align = blitz_align_of_rect(&c->rect, ev->x, ev->y);
+ BlitzAlign align = blitz_align_of_rect(&c->rect, ev->x, ev->y);
if(align != CENTER)
do_mouse_resize(c, align);
else
diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c
@@ -1334,7 +1334,7 @@ xwrite(IXPConn *c, Fcall *fcall)
return Ebadvalue;
memcpy(bar.data[i1]->colstr, fcall->data, fcall->count);
bar.data[i1]->colstr[fcall->count] = 0;
- blitz_loadcolor(dpy, screen, bar.data[i1]->colstr, &bar.data[i1]->color);
+ blitz_loadcolor(dpy, &bar.data[i1]->color, screen, bar.data[i1]->colstr);
draw_bar();
break;
case FsFselcolors:
@@ -1343,7 +1343,7 @@ xwrite(IXPConn *c, Fcall *fcall)
return Ebadvalue;
memcpy(def.selcolor, fcall->data, fcall->count);
def.selcolor[fcall->count] = 0;
- blitz_loadcolor(dpy, screen, def.selcolor, &def.sel);
+ blitz_loadcolor(dpy, &def.sel, screen, def.selcolor);
draw_clients();
break;
case FsFnormcolors:
@@ -1352,7 +1352,7 @@ xwrite(IXPConn *c, Fcall *fcall)
return Ebadvalue;
memcpy(def.normcolor, fcall->data, fcall->count);
def.normcolor[fcall->count] = 0;
- blitz_loadcolor(dpy, screen, def.normcolor, &def.norm);
+ blitz_loadcolor(dpy, &def.norm, screen, def.normcolor);
draw_clients();
break;
case FsFkeys:
@@ -1415,8 +1415,7 @@ xwrite(IXPConn *c, Fcall *fcall)
free(def.font);
def.font = cext_emallocz(fcall->count + 1);
memcpy(def.font, fcall->data, fcall->count);
- XFreeFont(dpy, xfont);
- xfont = blitz_getfont(dpy, def.font);
+ blitz_loadfont(dpy, &blitzfont, def.font);
resize_bar();
break;
case FsFmode:
diff --git a/cmd/wm/mouse.c b/cmd/wm/mouse.c
@@ -265,7 +265,7 @@ do_mouse_move(Client *c)
}
static void
-snap_resize(XRectangle * r, XRectangle * o, Align align,
+snap_resize(XRectangle * r, XRectangle * o, BlitzAlign align,
XRectangle * rects, unsigned int num, int px, int ox, int py,
int oy, int snapw, int snaph)
{
@@ -441,7 +441,7 @@ snap_resize(XRectangle * r, XRectangle * o, Align align,
}
void
-do_mouse_resize(Client *c, Align align)
+do_mouse_resize(Client *c, BlitzAlign align)
{
int px = 0, py = 0, i, ox, oy, first = 1;
Window dummy;
diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c
@@ -295,15 +295,15 @@ main(int argc, char *argv[])
def.colmode = Coldefault;
def.colw = 0;
cext_strlcpy(def.selcolor, BLITZ_SELCOLORS, sizeof(def.selcolor));
- blitz_loadcolor(dpy, screen, def.selcolor, &def.sel);
+ blitz_loadcolor(dpy, &def.sel, screen, def.selcolor);
cext_strlcpy(def.normcolor, BLITZ_NORMCOLORS, sizeof(def.normcolor));
- blitz_loadcolor(dpy, screen, def.normcolor, &def.norm);
+ blitz_loadcolor(dpy, &def.norm, screen, def.normcolor);
cext_strlcpy(def.grabmod, "Mod1", sizeof(def.grabmod));
def.mod = Mod1Mask;
init_atoms();
init_cursors();
- xfont = blitz_getfont(dpy, def.font);
+ blitz_loadfont(dpy, &blitzfont, def.font);
init_lock_keys();
init_screen();
@@ -317,7 +317,7 @@ main(int argc, char *argv[])
| SubstructureRedirectMask | SubstructureNotifyMask;
brect = rect;
- brect.height = xfont->ascent + xfont->descent + 4;
+ brect.height = height_of_bar();
brect.y = rect.height - brect.height;
barwin = XCreateWindow(dpy, RootWindow(dpy, screen), brect.x, brect.y,
brect.width, brect.height, 0, DefaultDepth(dpy, screen),
diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h
@@ -133,7 +133,7 @@ typedef struct {
unsigned short id;
char data[256];
char colstr[24];
- Color color;
+ BlitzColor color;
XRectangle rect;
Bool intern;
} Bar;
@@ -143,8 +143,8 @@ typedef struct {
char selcolor[24];
char normcolor[24];
char *font;
- Color sel;
- Color norm;
+ BlitzColor sel;
+ BlitzColor norm;
unsigned int border;
unsigned int snap;
char *keys;
@@ -172,7 +172,7 @@ Display *dpy;
int screen;
Window root;
XRectangle rect;
-XFontStruct *xfont;
+BlitzFont blitzfont;
GC xorgc;
IXPServer srv;
Pixmap barpmap;
@@ -264,7 +264,7 @@ void init_lock_keys();
unsigned long mod_key_of_str(char *val);
/* mouse.c */
-void do_mouse_resize(Client *c, Align align);
+void do_mouse_resize(Client *c, BlitzAlign align);
void do_mouse_move(Client *c);
void grab_mouse(Window w, unsigned long mod, unsigned int button);
void ungrab_mouse(Window w, unsigned long mod, unsigned int button);
diff --git a/cmd/wmiimenu.c b/cmd/wmiimenu.c
@@ -24,8 +24,8 @@ VECTOR(ItemVector, char *);
static Bool done = False;
static int ret = 0;
static char text[4096];
-static Color selcolor;
-static Color normcolor;
+static BlitzColor selcolor;
+static BlitzColor normcolor;
static Display *dpy;
static Window win;
static XRectangle mrect;
@@ -37,7 +37,7 @@ static unsigned int nextoff = 0;
static unsigned int prevoff = 0;
static unsigned int curroff = 0;
static unsigned int cmdw = 0;
-static Draw draw = { 0 };
+static BlitzDraw draw = { 0 };
static const int seek = 30; /* 30px */
static void draw_menu(void);
@@ -68,7 +68,7 @@ update_offsets()
return;
for(i = curroff; i < item.size; i++) {
- w += XTextWidth(draw.font, item.data[i], strlen(item.data[i])) + mrect.height;
+ w += XTextWidth(draw.font.font, item.data[i], strlen(item.data[i])) + mrect.height;
if(w > mrect.width)
break;
}
@@ -76,7 +76,7 @@ update_offsets()
w = cmdw + 2 * seek;
for(i = curroff; i > 0; i--) {
- w += XTextWidth(draw.font, item.data[i], strlen(item.data[i])) + mrect.height;
+ w += XTextWidth(draw.font.font, item.data[i], strlen(item.data[i])) + mrect.height;
if(w > mrect.width)
break;
}
@@ -143,7 +143,7 @@ draw_menu()
for(i = curroff; i < nextoff; i++) {
draw.data = item.data[i];
draw.rect.x = offx;
- draw.rect.width = XTextWidth(draw.font, draw.data,
+ draw.rect.width = XTextWidth(draw.font.font, draw.data,
strlen(draw.data)) + mrect.height;
offx += draw.rect.width;
if(sel == i) {
@@ -308,7 +308,7 @@ read_allitems()
}
if(maxname)
- cmdw = XTextWidth(draw.font, maxname, max) + mrect.height;
+ cmdw = XTextWidth(draw.font.font, maxname, max) + mrect.height;
}
int
@@ -343,15 +343,15 @@ main(int argc, char *argv[])
fontstr = getenv("WMII_FONT");
if (!fontstr)
fontstr = strdup(BLITZ_FONT);
- draw.font = blitz_getfont(dpy, fontstr);
+ blitz_loadfont(dpy, &draw.font, fontstr);
normcolstr = getenv("WMII_NORMCOLORS");
if (!normcolstr || strlen(normcolstr) != 23)
normcolstr = strdup(BLITZ_NORMCOLORS);
- blitz_loadcolor(dpy, screen, normcolstr, &normcolor);
+ blitz_loadcolor(dpy, &normcolor, screen, normcolstr);
selcolstr = getenv("WMII_SELCOLORS");
if (!selcolstr || strlen(selcolstr) != 23)
selcolstr = strdup(BLITZ_SELCOLORS);
- blitz_loadcolor(dpy, screen, selcolstr, &selcolor);
+ blitz_loadcolor(dpy, &selcolor, screen, selcolstr);
wa.override_redirect = 1;
wa.background_pixmap = ParentRelative;
@@ -359,7 +359,7 @@ main(int argc, char *argv[])
| SubstructureRedirectMask | SubstructureNotifyMask;
mrect.width = DisplayWidth(dpy, screen);
- mrect.height = draw.font->ascent + draw.font->descent + 4;
+ mrect.height = draw.font.font->ascent + draw.font.font->descent + 4;
mrect.y = DisplayHeight(dpy, screen) - mrect.height;
mrect.x = 0;
diff --git a/liblitz/Makefile b/liblitz/Makefile
@@ -6,7 +6,7 @@ include ../config.mk
CFLAGS += -I../libixp -I../libcext
LDFLAGS += -L../libixp -lixp -L../libcext -lcext
-SRC = draw.c geometry.c
+SRC = color.c font.c draw.c geometry.c
OBJ = ${SRC:.c=.o}
all: liblitz.a
diff --git a/liblitz/blitz.h b/liblitz/blitz.h
@@ -12,34 +12,43 @@
typedef enum {
CENTER, WEST, NWEST, NORTH, NEAST, EAST,
SEAST, SOUTH, SWEST
-} Align;
+} BlitzAlign;
typedef struct {
unsigned long bg;
unsigned long fg;
unsigned long border;
-} Color;
+} BlitzColor;
typedef struct {
- Align align;
+ XFontStruct *font;
+ XFontSet set;
+} BlitzFont;
+
+typedef struct {
+ BlitzAlign align;
Drawable drawable;
GC gc;
- Color color;
- XFontStruct *font;
+ BlitzColor color;
+ BlitzFont font;
XRectangle rect; /* relative rect */
XRectangle *notch; /* relative notch rect */
char *data;
-} Draw;
+} BlitzDraw;
+
+/* font.c */
+void blitz_loadfont(Display *dpy, BlitzFont *font, char *fontstr);
+
+/* color.c */
+int blitz_loadcolor(Display *dpy, BlitzColor *c, int mon, char *colstr);
/* draw.c */
-XFontStruct *blitz_getfont(Display *dpy, char *fontstr);
-int blitz_loadcolor(Display *dpy, int mon, char *colstr, Color *c);
-void blitz_drawlabel(Display *dpy, Draw *r);
-void blitz_drawborder(Display *dpy, Draw *r);
+void blitz_drawlabel(Display *dpy, BlitzDraw *d);
+void blitz_drawborder(Display *dpy, BlitzDraw *d);
/* geometry.c */
-Align blitz_align_of_rect(XRectangle *rect, int x, int y);
-int blitz_strtoalign(Align *result, char *val);
+BlitzAlign blitz_align_of_rect(XRectangle *rect, int x, int y);
+int blitz_strtoalign(BlitzAlign *result, char *val);
int blitz_strtorect(XRectangle *root, XRectangle *r, char *val);
Bool blitz_ispointinrect(int x, int y, XRectangle *r);
int blitz_distance(XRectangle *origin, XRectangle *target);
diff --git a/liblitz/color.c b/liblitz/color.c
@@ -0,0 +1,33 @@
+/*
+ * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
+ * See LICENSE file for license details.
+ */
+
+#include <string.h>
+#include <cext.h>
+
+#include "blitz.h"
+
+static unsigned long
+xloadcolor(Display *dpy, int mon, char *colstr)
+{
+ XColor color;
+ char col[8];
+
+ cext_strlcpy(col, colstr, sizeof(col));
+ col[7] = 0;
+ XAllocNamedColor(dpy, DefaultColormap(dpy, mon), col, &color, &color);
+ return color.pixel;
+}
+
+int
+blitz_loadcolor(Display *dpy, BlitzColor *c, int mon, char *colstr)
+{
+ if(!colstr || strlen(colstr) != 23)
+ return -1;
+ c->fg = xloadcolor(dpy, mon, &colstr[0]);
+ c->bg = xloadcolor(dpy, mon, &colstr[8]);
+ c->border = xloadcolor(dpy, mon, &colstr[16]);
+ return 0;
+}
+
diff --git a/liblitz/draw.c b/liblitz/draw.c
@@ -9,46 +9,8 @@
#include "blitz.h"
-XFontStruct *
-blitz_getfont(Display *dpy, char *fontstr)
-{
- XFontStruct *font;
- font = XLoadQueryFont(dpy, fontstr);
- if (!font) {
- font = XLoadQueryFont(dpy, "fixed");
- if (!font) {
- fprintf(stderr, "%s", "wmii: error, cannot load fixed font\n");
- return 0;
- }
- }
- return font;
-}
-
-static unsigned long
-xloadcolor(Display *dpy, int mon, char *colstr)
-{
- XColor color;
- char col[8];
-
- cext_strlcpy(col, colstr, sizeof(col));
- col[7] = 0;
- XAllocNamedColor(dpy, DefaultColormap(dpy, mon), col, &color, &color);
- return color.pixel;
-}
-
-int
-blitz_loadcolor(Display *dpy, int mon, char *colstr, Color *c)
-{
- if(!colstr || strlen(colstr) != 23)
- return -1;
- c->fg = xloadcolor(dpy, mon, &colstr[0]);
- c->bg = xloadcolor(dpy, mon, &colstr[8]);
- c->border = xloadcolor(dpy, mon, &colstr[16]);
- return 0;
-}
-
static void
-xdrawbg(Display *dpy, Draw *d)
+xdrawbg(Display *dpy, BlitzDraw *d)
{
XRectangle rect[4];
XSetForeground(dpy, d->gc, d->color.bg);
@@ -73,7 +35,7 @@ xdrawbg(Display *dpy, Draw *d)
}
void
-blitz_drawborder(Display *dpy, Draw *d)
+blitz_drawborder(Display *dpy, BlitzDraw *d)
{
XPoint points[5];
@@ -93,7 +55,7 @@ blitz_drawborder(Display *dpy, Draw *d)
}
static void
-xdrawtext(Display *dpy, Draw *d)
+xdrawtext(Display *dpy, BlitzDraw *d)
{
unsigned int x = 0, y = 0, w = 1, h = 1, shortened = 0;
unsigned int len = 0;
@@ -104,12 +66,12 @@ xdrawtext(Display *dpy, Draw *d)
len = strlen(d->data);
cext_strlcpy(text, d->data, sizeof(text));
- XSetFont(dpy, d->gc, d->font->fid);
- h = d->font->ascent + d->font->descent;
- y = d->rect.y + d->rect.height / 2 - h / 2 + d->font->ascent;
+ XSetFont(dpy, d->gc, d->font.font->fid);
+ h = d->font.font->ascent + d->font.font->descent;
+ y = d->rect.y + d->rect.height / 2 - h / 2 + d->font.font->ascent;
/* shorten text if necessary */
- while (len && (w = XTextWidth(d->font, text, len)) > d->rect.width) {
+ while (len && (w = XTextWidth(d->font.font, text, len)) > d->rect.width) {
text[len - 1] = 0;
len--;
shortened = 1;
@@ -144,7 +106,7 @@ xdrawtext(Display *dpy, Draw *d)
}
void
-blitz_drawlabel(Display *dpy, Draw * d)
+blitz_drawlabel(Display *dpy, BlitzDraw * d)
{
xdrawbg(dpy, d);
if (d->data)
diff --git a/liblitz/font.c b/liblitz/font.c
@@ -0,0 +1,24 @@
+/*
+ * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
+ * See LICENSE file for license details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "blitz.h"
+
+void
+blitz_loadfont(Display *dpy, BlitzFont *font, char *fontstr)
+{
+ if(font->font)
+ XFreeFont(dpy, font->font);
+ font->font = XLoadQueryFont(dpy, fontstr);
+ if (!font->font) {
+ font->font = XLoadQueryFont(dpy, "fixed");
+ if (!font->font) {
+ fprintf(stderr, "%s", "liblitz: error, cannot load fixed font\n");
+ exit(1);
+ }
+ }
+}
diff --git a/liblitz/geometry.c b/liblitz/geometry.c
@@ -10,7 +10,7 @@
#include "blitz.h"
-Align
+BlitzAlign
blitz_align_of_rect(XRectangle *rect, int x, int y)
{
int w = x <= rect->x + rect->width / 2;
@@ -34,7 +34,7 @@ blitz_align_of_rect(XRectangle *rect, int x, int y)
return CENTER;
}
-int blitz_strtoalign(Align *result, char *val)
+int blitz_strtoalign(BlitzAlign *result, char *val)
{
/*
* note, resize allows syntax like "east-20", this we cannot do
@@ -109,7 +109,7 @@ int blitz_strtorect(XRectangle *root, XRectangle *r, char *val)
if (!sx && !sw && x && w
&& x[0] != '-' && x[0] != '+' && w[0] != '-' && w[0] != '+') {
- Align ax, aw;
+ BlitzAlign ax, aw;
blitz_strtoalign(&ax, x);
blitz_strtoalign(&aw, w);
if ((ax == CENTER) && (aw == EAST)) {
@@ -124,7 +124,7 @@ int blitz_strtorect(XRectangle *root, XRectangle *r, char *val)
}
}
} else if (!sx && x && x[0] != '-' && x[0] != '+') {
- Align ax;
+ BlitzAlign ax;
blitz_strtoalign(&ax, x);
if (ax == CENTER) {
rx = root->x + (root->width / 2) - (rw / 2);
@@ -134,7 +134,7 @@ int blitz_strtorect(XRectangle *root, XRectangle *r, char *val)
rx = root->x;
}
} else if (!sw && w && w[0] != '-' && w[0] != '+') {
- Align aw;
+ BlitzAlign aw;
blitz_strtoalign(&aw, w);
if (aw == CENTER) {
rw = (root->width / 2) - rx;
@@ -144,7 +144,7 @@ int blitz_strtorect(XRectangle *root, XRectangle *r, char *val)
}
if (!sy && !sh && y && h
&& y[0] != '-' && y[0] != '+' && h[0] != '-' && h[0] != '+') {
- Align ay, ah;
+ BlitzAlign ay, ah;
blitz_strtoalign(&ay, y);
blitz_strtoalign(&ah, h);
if ((ay == CENTER) && (ah == SOUTH)) {
@@ -159,7 +159,7 @@ int blitz_strtorect(XRectangle *root, XRectangle *r, char *val)
}
}
} else if (!sy && y && y[0] != '-' && y[0] != '+') {
- Align ay;
+ BlitzAlign ay;
blitz_strtoalign(&ay, y);
if (ay == CENTER) {
ry = root->y + (root->height / 2) - (rh / 2);
@@ -169,7 +169,7 @@ int blitz_strtorect(XRectangle *root, XRectangle *r, char *val)
ry = root->y;
}
} else if (!sh && h && h[0] != '-' && h[0] != '+') {
- Align ah;
+ BlitzAlign ah;
blitz_strtoalign(&ah, h);
if (ah == CENTER) {
rh = (root->height / 2) - ry;