wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit f043abedc317648b43e402874c7df8a22618969c
parent f774e684705d87ece79ddc4736f45b1e6385a1b8
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Tue, 13 Jun 2006 18:24:08 +0200

added widget.c


Diffstat:
liblitz/Makefile | 2+-
liblitz/blitz.h | 11++++++++++-
liblitz/layout.c | 22++++++++++++++++------
liblitz/widget.c | 27+++++++++++++++++++++++++++
4 files changed, 54 insertions(+), 8 deletions(-)

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 = blitz.c color.c font.c label.c layout.c window.c +SRC = blitz.c color.c font.c label.c layout.c window.c widget.c OBJ = ${SRC:.c=.o} all: liblitz.a diff --git a/liblitz/blitz.h b/liblitz/blitz.h @@ -19,6 +19,7 @@ typedef struct BlitzLabel BlitzLabel; typedef struct BlitzLayout BlitzLayout; #define BLITZLAYOUT(p) ((BlitzLayout *)(p)) typedef union BlitzWidget BlitzWidget; +#define BLITZWIDGET(p) ((BlitzWidget *)(p)) typedef struct BlitzWin BlitzWin; struct Blitz { @@ -63,6 +64,7 @@ struct BlitzLayout { Bool expand; BlitzWidget *next; void (*draw)(BlitzWidget *); + void (*destroy)(BlitzWidget *); /* widget specific */ BlitzWin *win; BlitzWidget *rows; @@ -75,6 +77,7 @@ struct BlitzLabel { Bool expand; BlitzWidget *next; void (*draw)(BlitzWidget *); + void (*destroy)(BlitzWidget *); /* widget specific */ BlitzColor color; BlitzAlign align; @@ -87,7 +90,9 @@ union BlitzWidget { Bool expand; BlitzWidget *next; void (*draw)(BlitzWidget *); + void (*destroy)(BlitzWidget *); BlitzLabel label; + BlitzLayout layout; }; typedef struct { @@ -114,12 +119,16 @@ void blitz_drawlabel(BlitzDraw *d); void blitz_drawborder(BlitzDraw *d); /* layout.c */ -BlitzLayout *blitz_create_layout(BlitzWin *win); +BlitzLayout *blitz_create_layout(BlitzWin *win, BlitzWidget **w); /* font.c */ unsigned int blitz_textwidth(BlitzFont *font, char *text); void blitz_loadfont(BlitzFont *font, char *fontstr); +/* widget.c */ +void blitz_add_widget(BlitzWidget **l, BlitzWidget *w); +void blitz_rm_widget(BlitzWidget **l, BlitzWidget *w); + /* window.c */ BlitzWin *blitz_create_win(unsigned long mask, int x, int y, int w, int h); diff --git a/liblitz/layout.c b/liblitz/layout.c @@ -23,25 +23,35 @@ xscale(BlitzWidget *w) } static void +xdestroy(BlitzWidget *w) +{ + BlitzLayout *l = BLITZLAYOUT(w); + for(w = l->cols; w; w = w->next) + w->destroy(w); + for(w = l->rows; w; w = w->next) + w->destroy(w); +} + +static void xdraw(BlitzWidget *w) { BlitzLayout *l = BLITZLAYOUT(w); for(w = l->cols; w; w = w->next) - if(w->draw) - w->draw(w); + w->draw(w); for(w = l->rows; w; w = w->next) - if(w->draw) - w->draw(w); + w->draw(w); } BlitzLayout * -blitz_create_layout(BlitzWin *win) +blitz_create_layout(BlitzWin *win, BlitzWidget **w) { BlitzLayout *l; l = cext_emallocz(sizeof(BlitzLayout)); l->win = win; l->cols = l->rows = nil; - l->scale = xscale; + l->destroy = xdestroy; l->draw = xdraw; + l->scale = xscale; + blitz_add_widget(w, BLITZWIDGET(l)); return l; } diff --git a/liblitz/widget.c b/liblitz/widget.c @@ -0,0 +1,27 @@ +/* + * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> + * See LICENSE file for license details. + */ + +#include <cext.h> +#include <stdlib.h> + +#include "blitz.h" + +void +blitz_add_widget(BlitzWidget **l, BlitzWidget *w) +{ + BlitzWidget **wt; + for(wt = l; *wt; wt = &(*wt)->next); + w->next = nil; + *wt = w; +} + +void +blitz_rm_widget(BlitzWidget **l, BlitzWidget *w) +{ + BlitzWidget **wt; + for(wt = l; *wt && *wt != w; wt = &(*wt)->next); + cext_assert(*wt == w); + *wt = w->next; +}