commit 4d2aca6f855d8e2a741943a77ceb83edb60bf800
parent 17325a67da94af574dee91ccf9112bd0ac51a1e0
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Fri, 10 Mar 2006 18:22:48 +0100
applied some portions of DenisG icon implementation for liblitz - in summary (no scaling, no loading, only creation) and the -lXpm dependency
Diffstat:
6 files changed, 91 insertions(+), 32 deletions(-)
diff --git a/cmd/wm/bar.c b/cmd/wm/bar.c
@@ -90,6 +90,7 @@ draw_bar()
if(!nlabel) { /* /default only */
d.color = def.sel;
blitz_drawlabel(dpy, &d);
+ blitz_drawborder(dpy, &d);
}
else {
for(i = 0; i < nlabel; i++) {
@@ -132,6 +133,7 @@ draw_bar()
blitz_drawmeter(dpy, &d);
else
blitz_drawlabel(dpy, &d);
+ blitz_drawborder(dpy, &d);
}
}
XCopyArea(dpy, pmapbar, winbar, gcbar, 0, 0, brect.width, brect.height, 0, 0);
diff --git a/cmd/wm/client.c b/cmd/wm/client.c
@@ -235,6 +235,7 @@ draw_client(Client *c)
d.rect.x = d.rect.y = 0;
d.notch = &c->rect;
blitz_drawlabel(dpy, &d);
+ blitz_drawborder(dpy, &d);
}
d.rect.x = 0;
d.rect.y = 0;
@@ -244,6 +245,7 @@ draw_client(Client *c)
snprintf(buf, sizeof(buf), "%s | %s", c->tags, c->name);
d.data = buf;
blitz_drawlabel(dpy, &d);
+ blitz_drawborder(dpy, &d);
XSync(dpy, False);
}
diff --git a/cmd/wmiimenu.c b/cmd/wmiimenu.c
@@ -128,7 +128,7 @@ draw_menu()
draw.rect.y = 0;
draw.color = normcolor;
draw.data = nil;
- blitz_drawlabelnoborder(dpy, &draw);
+ blitz_drawlabel(dpy, &draw);
/* print command */
draw.align = WEST;
@@ -136,7 +136,7 @@ draw_menu()
if(cmdw && nitem)
draw.rect.width = cmdw;
offx += draw.rect.width;
- blitz_drawlabelnoborder(dpy, &draw);
+ blitz_drawlabel(dpy, &draw);
draw.align = CENTER;
if(nitem) {
@@ -145,7 +145,7 @@ draw_menu()
draw.rect.x = offx;
draw.rect.width = seek;
offx += draw.rect.width;
- blitz_drawlabelnoborder(dpy, &draw);
+ blitz_drawlabel(dpy, &draw);
/* determine maximum items */
for(i = curroff; i < nextoff; i++) {
@@ -157,9 +157,10 @@ draw_menu()
if(sel == i) {
draw.color = selcolor;
blitz_drawlabel(dpy, &draw);
+ blitz_drawborder(dpy, &draw);
} else {
draw.color = normcolor;
- blitz_drawlabelnoborder(dpy, &draw);
+ blitz_drawlabel(dpy, &draw);
}
}
@@ -167,7 +168,7 @@ draw_menu()
draw.data = nitem > nextoff ? ">" : nil;
draw.rect.x = mrect.width - seek;
draw.rect.width = seek;
- blitz_drawlabelnoborder(dpy, &draw);
+ blitz_drawlabel(dpy, &draw);
}
XCopyArea(dpy, draw.drawable, win, draw.gc, 0, 0, mrect.width, mrect.height, 0, 0);
XSync(dpy, False);
diff --git a/config.mk b/config.mk
@@ -11,7 +11,7 @@ X11LIB = /usr/X11R6/lib
VERSION = 3-current
# includes and libs
-LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11
+LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11 -lXpm
# Linux/BSD
CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
diff --git a/liblitz/blitz.h b/liblitz/blitz.h
@@ -4,6 +4,7 @@
*/
#include <X11/Xlib.h>
+#include <X11/xpm.h>
#include <cext.h>
#define BLITZ_FONT "fixed"
@@ -32,16 +33,24 @@ typedef struct {
char *data;
} Draw;
+typedef struct {
+ XImage* image;
+ Pixmap mask;
+} Icon;
+
/* draw.c */
-XFontStruct *blitz_getfont(Display * dpy, char *fontstr);
+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_drawmeter(Display * dpy, Draw * r);
-void blitz_drawlabelnoborder(Display * dpy, Draw * r);
+void blitz_drawlabel(Display *dpy, Draw *r);
+void blitz_drawmeter(Display *dpy, Draw *r);
+int blitz_createicon(Display *dpy, Icon *ico, char *data[]);
+void blitz_freeicon(Display *dpy, Icon *ico);
+void blitz_drawicon(Display *dpy, Draw *d, Icon *ico);
+void blitz_drawborder(Display *dpy, Draw *r);
/* geometry.c */
int blitz_strtoalign(Align *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);
+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);
void blitz_getbasegeometry(unsigned int size, unsigned int *cols, unsigned int *rows);
diff --git a/liblitz/draw.c b/liblitz/draw.c
@@ -8,7 +8,7 @@
#include "blitz.h"
XFontStruct *
-blitz_getfont(Display * dpy, char *fontstr)
+blitz_getfont(Display *dpy, char *fontstr)
{
XFontStruct *font;
font = XLoadQueryFont(dpy, fontstr);
@@ -23,7 +23,7 @@ blitz_getfont(Display * dpy, char *fontstr)
}
static unsigned long
-xloadcolor(Display * dpy, int mon, char *colstr)
+xloadcolor(Display *dpy, int mon, char *colstr)
{
XColor color;
char col[8];
@@ -46,7 +46,7 @@ blitz_loadcolor(Display *dpy, int mon, char *colstr, Color *c)
}
static void
-draw_bg(Display * dpy, Draw * d)
+xdrawbg(Display *dpy, Draw *d)
{
XRectangle rect[4];
XSetForeground(dpy, d->gc, d->color.bg);
@@ -70,8 +70,8 @@ draw_bg(Display * dpy, Draw * d)
XFillRectangles(dpy, d->drawable, d->gc, rect, 4);
}
-static void
-xdraw_border(Display * dpy, Draw * d)
+void
+blitz_drawborder(Display *dpy, Draw *d)
{
XPoint points[5];
@@ -91,7 +91,7 @@ xdraw_border(Display * dpy, Draw * d)
}
static void
-draw_text(Display * dpy, Draw * d)
+xdrawtext(Display *dpy, Draw *d)
{
unsigned int x = 0, y = 0, w = 1, h = 1, shortened = 0;
unsigned int len = 0;
@@ -146,7 +146,6 @@ draw_text(Display * dpy, Draw * d)
XDrawString(dpy, d->drawable, d->gc, x, y, text, len);
}
-/* draws meter */
void
blitz_drawmeter(Display * dpy, Draw * d)
{
@@ -159,8 +158,8 @@ blitz_drawmeter(Display * dpy, Draw * d)
val = cext_strtonum(&d->data[3], 0, 100, &err);
if(err)
val = 100;
- draw_bg(dpy, d);
- xdraw_border(dpy, d);
+ xdrawbg(dpy, d);
+ blitz_drawborder(dpy, d);
/* draw bg gradient */
mh = ((d->rect.height - 4) * val) / 100;
@@ -169,24 +168,70 @@ blitz_drawmeter(Display * dpy, Draw * d)
XFillRectangle(dpy, d->drawable, d->gc, d->rect.x + 2, offy, w, mh);
}
-static void
-xdraw_label(Display * dpy, Draw * d)
+void
+blitz_drawlabel(Display *dpy, Draw * d)
{
- draw_bg(dpy, d);
+ xdrawbg(dpy, d);
if (d->data)
- draw_text(dpy, d);
+ xdrawtext(dpy, d);
+}
+
+int
+blitz_createicon(Display *dpy, Icon *ico, char *data[])
+{
+ printf("Entering blitz_createicon\n");
+ fflush(NULL);
+ XpmAttributes attr;
+ XImage* mask;
+ GC gc;
+
+ printf("%s …\n", data[0] );
+
+ attr.valuemask = XpmSize;
+ int retval;
+ retval = XpmCreateImageFromData(dpy, data, &ico->image, &mask, &attr);
+ if(retval)
+ return retval;
+ printf(" %dx%d\n", ico->image->width, ico->image->height);
+ ico->mask = XCreatePixmap(dpy, XDefaultRootWindow(dpy), mask->width, mask->height, mask->depth);
+ gc = XCreateGC (dpy, ico->mask, 0, NULL);
+ XPutImage(dpy, ico->mask, gc, mask, 0, 0, 0, 0, mask->width, mask->height);
+ printf("mask: %dx%d (%d)\n", mask->width, mask->height, sizeof(Pixmap));
+
+ XpmFreeAttributes(&attr);
+ return 0;
}
-/* draws label */
void
-blitz_drawlabel(Display * dpy, Draw * d)
+blitz_freeicon(Display *dpy, Icon *ico)
{
- xdraw_label(dpy, d);
- xdraw_border(dpy, d);
+ if(ico->image) {
+ XDestroyImage(ico->image);
+ ico->image = nil;
+ XFreePixmap(dpy, ico->mask);
+ }
}
void
-blitz_drawlabelnoborder(Display * dpy, Draw * d)
+blitz_drawicon(Display *dpy, Draw *d, Icon *ico)
{
- xdraw_label(dpy, d);
+ int y, w, h;
+ xdrawbg(dpy, d);
+ if (d->rect.width - 4 < ico->image->width)
+ w = d->rect.width - 4;
+ else
+ w = ico->image->width;
+ if (d->rect.height - 4 < ico->image->height)
+ h = d->rect.height - 4;
+ else
+ h = ico->image->height;
+ y = (h - ico->image->height) / 2;
+ XSetClipMask(dpy, d->gc, ico->mask);
+ XSetClipOrigin(dpy, d->gc, d->rect.x + 2, d->rect.y + 2 + y);
+ /* vertically centered */
+ if (y < 0)
+ XPutImage(dpy, d->drawable, d->gc, ico->image, 0, -y, d->rect.x + 2, d->rect.y + 2, w, h);
+ else
+ XPutImage(dpy, d->drawable, d->gc, ico->image, 0, y, d->rect.x + 2, d->rect.y + 2 + y, w, h);
+ XSetClipMask(dpy, d->gc, None);
}