wmii

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

commit 1b6bf46fe6d278cb81f3b52355743f1a8e117197
parent d7fea5865fafe49ac811dd4a8a265eead168f3b4
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Tue, 13 Jun 2006 17:27:01 +0200

added basic layout.c to liblitz


Diffstat:
liblitz/Makefile | 2+-
liblitz/blitz.c | 1-
liblitz/blitz.h | 28++++++++++++++++++++++++----
liblitz/layout.c | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 110 insertions(+), 6 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 window.c +SRC = blitz.c color.c font.c label.c layout.c window.c OBJ = ${SRC:.c=.o} all: liblitz.a diff --git a/liblitz/blitz.c b/liblitz/blitz.c @@ -7,7 +7,6 @@ #include "blitz.h" -/* blitz.c */ void blitz_x11_init(Display *dpy) { diff --git a/liblitz/blitz.h b/liblitz/blitz.h @@ -10,12 +10,15 @@ #define BLITZ_SELCOLORS "#ffffff #335577 #447799" #define BLITZ_NORMCOLORS "#222222 #eeeeee #666666" +enum {BLITZ_LAYOUT, BLITZ_LABEL, BLITZ_LAST}; typedef struct Blitz Blitz; typedef enum BlitzAlign BlitzAlign; typedef struct BlitzColor BlitzColor; typedef struct BlitzFont BlitzFont; typedef struct BlitzLabel BlitzLabel; +#define BLITZLABEL(p) ((BlitzLabel *)(p)) typedef struct BlitzLayout BlitzLayout; +#define BLITZLAYOUT(p) ((BlitzLayout *)(p)) typedef union BlitzWidget BlitzWidget; typedef struct BlitzWin BlitzWin; @@ -57,25 +60,36 @@ struct BlitzWin{ }; struct BlitzLayout { + int type; + XRectangle rect; + Bool expand; + BlitzWidget *next; + /* widget specific */ BlitzWin *win; - BlitzWidget *widgets; - void (*scale)(BlitzLayout *l); - void (*draw)(BlitzLayout *l); + BlitzWidget *rows; + BlitzWidget *cols; + void (*scale)(BlitzWidget *l); + void (*draw)(BlitzWidget *l); }; struct BlitzLabel { int type; XRectangle rect; + Bool expand; + BlitzWidget *next; /* widget specific */ BlitzColor color; BlitzAlign align; BlitzFont font; char *text; - void (*draw)(BlitzLayout *l); + void (*draw)(BlitzWidget *l); }; union BlitzWidget { int type; + XRectangle rect; + Bool expand; + BlitzWidget *next; BlitzLabel label; }; @@ -102,6 +116,12 @@ int blitz_loadcolor(BlitzColor *c, char *colstr); void blitz_drawlabel(BlitzDraw *d); void blitz_drawborder(BlitzDraw *d); +/* layout.c */ +BlitzLayout *blitz_create_layout(BlitzWin *win); +void blitz_add_widget(BlitzWidget **l, BlitzWidget *w); +void blitz_rm_widget(BlitzWidget **l, BlitzWidget *w); +int blitz_destroy_layout(BlitzLayout *l); + /* font.c */ unsigned int blitz_textwidth(BlitzFont *font, char *text); void blitz_loadfont(BlitzFont *font, char *fontstr); diff --git a/liblitz/layout.c b/liblitz/layout.c @@ -0,0 +1,85 @@ +/* + * (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" + +/* + * Each layout can be a widget. A layout may consist of + * columns or rows of widgets, or of columns and rows of widgets. + * Rows are scaled left to right, the first widget with + * expand == True takes the remaining space of the overall row. + * Columns are scaled top to bottom, the first widget with + * expand == True takes the remaining space of the overall column. + */ +static void +xscale(BlitzWidget *w) +{ + +} + +static void +xdraww(BlitzWidget *w) +{ + switch(w->type) { + case BLITZ_LABEL: + BLITZLABEL(w)->draw(w); + break; + case BLITZ_LAYOUT: + BLITZLAYOUT(w)->draw(w); + break; + } +} + +static void +xdraw(BlitzWidget *w) +{ + BlitzLayout *l = BLITZLAYOUT(w); + for(w = l->cols; w; w = w->next) + xdraww(w); + for(w = l->rows; w; w = w->next) + xdraww(w); +} + +BlitzLayout * +blitz_create_layout(BlitzWin *win) +{ + BlitzLayout *l; + l = cext_emallocz(sizeof(BlitzLayout)); + l->win = win; + l->cols = l->rows = nil; + l->scale = xscale; + l->draw = xdraw; + return l; +} + +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; +} + +int +blitz_destroy_layout(BlitzLayout *l) +{ + if(l->cols || l->rows) + return -1; + free(l); + return 0; +}