changed various parts to use new rocking data structure

This commit is contained in:
garbeam 2005-12-06 19:58:52 +02:00
parent 1d95f1fa99
commit fefbab01e2
30 changed files with 295 additions and 304 deletions

View File

@ -9,14 +9,12 @@
#include "wm.h" #include "wm.h"
#include <cext.h>
static Area zero_area = {0}; static Area zero_area = {0};
Area *alloc_area(Page *p, XRectangle * r, char *layout) Area *alloc_area(Page *p, XRectangle * r, char *layout)
{ {
char buf[MAX_BUF]; char buf[MAX_BUF];
Area *a = (Area *) emalloc(sizeof(Area)); Area *a = (Area *) cext_emalloc(sizeof(Area));
int id = count_items((void **) p->area) + 1; int id = count_items((void **) p->area) + 1;
*a = zero_area; *a = zero_area;
@ -108,3 +106,10 @@ void show_area(Area * a)
for (i = 0; a->frame && a->frame[i]; i++) for (i = 0; a->frame && a->frame[i]; i++)
XMapWindow(dpy, a->frame[i]->win); XMapWindow(dpy, a->frame[i]->win);
} }
Area *get_sel_area()
{
Page *p = cext_get_top_item(&page);
return p ? p->area[p->sel] : nil;
}

View File

@ -10,8 +10,6 @@
#include "wm.h" #include "wm.h"
#include <cext.h>
static Client zero_client = { 0 }; static Client zero_client = { 0 };
Client *alloc_client(Window w) Client *alloc_client(Window w)
@ -19,7 +17,7 @@ Client *alloc_client(Window w)
static int id = 0; static int id = 0;
char buf[MAX_BUF]; char buf[MAX_BUF];
char buf2[MAX_BUF]; char buf2[MAX_BUF];
Client *c = (Client *) emalloc(sizeof(Client)); Client *c = (Client *) cext_emalloc(sizeof(Client));
*c = zero_client; *c = zero_client;
c->win = w; c->win = w;
@ -29,7 +27,7 @@ Client *alloc_client(Window w)
snprintf(buf, MAX_BUF, "/detached/c/%d/name", id); snprintf(buf, MAX_BUF, "/detached/c/%d/name", id);
c->file[C_NAME] = wmii_create_ixpfile(ixps, buf, buf2); c->file[C_NAME] = wmii_create_ixpfile(ixps, buf, buf2);
id++; id++;
client = (Client **) attach_item_end((void **) client, c, sizeof(Client *)); cext_attach_item(&clients, c);
XSelectInput(dpy, c->win, CLIENT_MASK); XSelectInput(dpy, c->win, CLIENT_MASK);
return c; return c;
} }
@ -39,7 +37,7 @@ void sel_client(Client * c)
Frame *f = 0; Frame *f = 0;
/* sel client */ /* sel client */
f = c->frame; f = c->frame;
for (f->sel = 0; f->client && f->client[f->sel] != c; f->sel++); cext_top_item(&f->clients, c);
f->file[F_SEL_CLIENT]->content = c->file[C_PREFIX]->content; f->file[F_SEL_CLIENT]->content = c->file[C_PREFIX]->content;
XRaiseWindow(dpy, c->win); XRaiseWindow(dpy, c->win);
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
@ -182,7 +180,7 @@ void handle_client_property(Client * c, XPropertyEvent * e)
if (strlen(buf)) { if (strlen(buf)) {
if (c->file[C_NAME]->content) if (c->file[C_NAME]->content)
free(c->file[C_NAME]->content); free(c->file[C_NAME]->content);
c->file[C_NAME]->content = estrdup(buf); c->file[C_NAME]->content = cext_estrdup(buf);
c->file[C_NAME]->size = strlen(buf); c->file[C_NAME]->size = strlen(buf);
} }
if (c->frame) if (c->frame)
@ -203,7 +201,7 @@ void handle_client_property(Client * c, XPropertyEvent * e)
void destroy_client(Client * c) void destroy_client(Client * c)
{ {
client = (Client **) detach_item((void **) client, c, sizeof(Client *)); cext_detach_item(&clients, c);
ixp_remove_file(ixps, c->file[C_PREFIX]); ixp_remove_file(ixps, c->file[C_PREFIX]);
if (ixps->errstr) if (ixps->errstr)
fprintf(stderr, "wmiiwm: destroy_client(): %s\n", ixps->errstr); fprintf(stderr, "wmiiwm: destroy_client(): %s\n", ixps->errstr);
@ -211,53 +209,33 @@ void destroy_client(Client * c)
} }
/* speed reasoned function for client property change */ /* speed reasoned function for client property change */
void draw_client(Client * c) void draw_client(void *item)
{ {
Client *c = item;
Frame *f = c->frame; Frame *f = c->frame;
unsigned int tabh = tab_height(f); unsigned int tw, tabh = tab_height(f);
int i, size; size_t size;
int tw; int i;
if (!tabh) if (!tabh)
return; return;
size = count_items((void **) f->client); size = cext_sizeof(&f->clients);
tw = f->rect.width; tw = f->rect.width;
if (size) if (size)
tw /= size; tw /= size;
for (i = 0; f->client[i] && f->client[i] != c; i++); i = cext_get_item_index(&f->clients, c);
if (i < size - 1)
if (!f->client[i + 1]) draw_tab(f, c->file[C_NAME]->content, i * tw, 0, f->rect.width - (i * tw), tabh,
draw_tab(f, c->file[C_NAME]->content, i * tw, 0, (f == get_sel_frame()) && (c == get_sel_client()));
f->rect.width - (i * tw), tabh, ISSELFRAME(f)
&& f->client[f->sel] == c);
else else
draw_tab(f, c->file[C_NAME]->content, i * tw, 0, tw, tabh, draw_tab(f, c->file[C_NAME]->content, i * tw, 0, tw, tabh,
ISSELFRAME(f) && f->client[f->sel] == c); (f == get_sel_frame()) && (c == get_sel_client()));
XSync(dpy, False);
} }
void draw_clients(Frame * f) void draw_clients(Frame * f)
{ {
unsigned int tabh = tab_height(f); cext_iterate(&f->clients, draw_client);
int i, size = count_items((void **) f->client);
int tw = f->rect.width;
if (!tabh || !size)
return;
if (size)
tw /= size;
for (i = 0; f->client[i]; i++) {
if (!f->client[i + 1]) {
int xoff = i * tw;
draw_tab(f, f->client[i]->file[C_NAME]->content,
xoff, 0, f->rect.width - xoff, tabh, ISSELFRAME(f)
&& f->client[f->sel] == f->client[i]);
break;
} else
draw_tab(f, f->client[i]->file[C_NAME]->content,
i * tw, 0, tw, tabh, ISSELFRAME(f)
&& f->client[f->sel] == f->client[i]);
}
XSync(dpy, False);
} }
void gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert) void gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert)
@ -323,12 +301,11 @@ void gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert)
void attach_client(Client * c) void attach_client(Client * c)
{ {
Area *a = 0; Area *a = 0;
Frame *old; Frame *old = get_sel_frame();
if (!page) if (!cext_sizeof(&pages))
alloc_page(); alloc_page();
old = SELFRAME(page[sel]);
/* transient stuff */ /* transient stuff */
a = SELAREA; a = get_sel_area();
if (c && c->trans) { if (c && c->trans) {
Client *t = win_to_client(c->trans); Client *t = win_to_client(c->trans);
if (t && t->frame) if (t && t->frame)
@ -345,7 +322,11 @@ void detach_client(Client *c) {
c->frame->area->layout->detach(c->frame->area, c); c->frame->area->layout->detach(c->frame->area, c);
if (c->destroyed) if (c->destroyed)
destroy_client(c); destroy_client(c);
if (page) sel_page(get_sel_page());
sel_page(page[sel]);
} }
Client *get_sel_client()
{
Frame *f = get_sel_frame();
return f ? cext_get_top_item(&f->clients) : nil;
}

View File

@ -10,8 +10,6 @@
#include "wm.h" #include "wm.h"
#include <cext.h>
static Frame zero_frame = { 0 }; static Frame zero_frame = { 0 };
static void select_client(void *obj, char *cmd); static void select_client(void *obj, char *cmd);
@ -29,7 +27,7 @@ Frame *alloc_frame(XRectangle * r)
XSetWindowAttributes wa; XSetWindowAttributes wa;
static int id = 0; static int id = 0;
char buf[MAX_BUF]; char buf[MAX_BUF];
Frame *f = (Frame *) emalloc(sizeof(Frame)); Frame *f = (Frame *) cext_emalloc(sizeof(Frame));
int bw, th; int bw, th;
*f = zero_frame; *f = zero_frame;
@ -406,7 +404,7 @@ static void handle_before_read_frame(IXPServer * s, File * f)
frame[i]->rect.height); frame[i]->rect.height);
if (f->content) if (f->content)
free(f->content); free(f->content);
f->content = estrdup(buf); f->content = cext_estrdup(buf);
f->size = strlen(buf); f->size = strlen(buf);
return; return;
} }
@ -442,3 +440,16 @@ static void handle_after_write_frame(IXPServer * s, File * f)
} }
} }
} }
Frame *get_sel_frame_of_area(Area *a)
{
return cext_get_top_item(&a->frame);
}
Frame *get_sel_frame()
{
Page *p = get_sel_page();
if (!p)
return nil;
return get_sel_frame_of_area(get_sel_area(p));
}

View File

@ -10,8 +10,6 @@
#include "wm.h" #include "wm.h"
#include "layout.h" #include "layout.h"
#include <cext.h>
typedef struct Acme Acme; typedef struct Acme Acme;
typedef struct Column Column; typedef struct Column Column;
@ -75,7 +73,7 @@ static void arrange_col(Area * a)
static void init_col(Area * a) static void init_col(Area * a)
{ {
Acme *acme = emalloc(sizeof(Acme)); Acme *acme = cext_emalloc(sizeof(Acme));
int i, j, n, cols = 1; int i, j, n, cols = 1;
unsigned int width = 1; unsigned int width = 1;
Column *col; Column *col;
@ -97,9 +95,9 @@ static void init_col(Area * a)
*/ */
width = a->rect.width / cols; width = a->rect.width / cols;
acme->column = emalloc((cols + 1) * sizeof(Column *)); acme->column = cext_emalloc((cols + 1) * sizeof(Column *));
for (i = 0; i < cols; i++) { for (i = 0; i < cols; i++) {
acme->column[i] = emalloc(sizeof(Column)); acme->column[i] = cext_emalloc(sizeof(Column));
*acme->column[i] = zero_column; *acme->column[i] = zero_column;
acme->column[i]->rect = a->rect; acme->column[i]->rect = a->rect;
acme->column[i]->rect.x = i * width; acme->column[i]->rect.x = i * width;
@ -128,7 +126,7 @@ static void init_col(Area * a)
j++; j++;
} }
col = acme->column[cols - 1]; col = acme->column[cols - 1];
col->frame = emalloc((n - j + 1) * sizeof(Frame *)); col->frame = cext_emalloc((n - j + 1) * sizeof(Frame *));
for (i = 0; i + j < n; i++) { for (i = 0; i + j < n; i++) {
col->frame[i] = alloc_frame(&client[j + i]->rect); col->frame[i] = alloc_frame(&client[j + i]->rect);
col->frame[i]->aux = col; col->frame[i]->aux = col;

View File

@ -10,8 +10,6 @@
#include "wm.h" #include "wm.h"
#include "layout.h" #include "layout.h"
#include <cext.h>
static void init_float(Area * a); static void init_float(Area * a);
static void deinit_float(Area * a); static void deinit_float(Area * a);
static void arrange_float(Area * a); static void arrange_float(Area * a);

View File

@ -9,8 +9,6 @@
#include "wm.h" #include "wm.h"
#include <cext.h>
static Page zero_page = { 0 }; static Page zero_page = { 0 };
static void select_frame(void *obj, char *cmd); static void select_frame(void *obj, char *cmd);
@ -24,7 +22,7 @@ Action page_acttbl[] = {
Page *alloc_page() Page *alloc_page()
{ {
Page *p = emalloc(sizeof(Page)); Page *p = cext_emalloc(sizeof(Page));
char buf[MAX_BUF], buf2[16]; char buf[MAX_BUF], buf2[16];
int id = count_items((void **) page) + 1; int id = count_items((void **) page) + 1;
@ -111,7 +109,7 @@ XRectangle *rectangles(unsigned int *num)
XRectangle r; XRectangle r;
if (XQueryTree(dpy, root, &d1, &d2, &wins, num)) { if (XQueryTree(dpy, root, &d1, &d2, &wins, num)) {
result = emalloc(*num * sizeof(XRectangle)); result = cext_emalloc(*num * sizeof(XRectangle));
for (i = 0; i < *num; i++) { for (i = 0; i < *num; i++) {
if (!XGetWindowAttributes(dpy, wins[i], &wa)) if (!XGetWindowAttributes(dpy, wins[i], &wa))
continue; continue;
@ -342,3 +340,8 @@ detach_frame_from_page(Frame * f, int ignore_sel_and_destroy)
} }
} }
*/ */
Page *get_sel_page()
{
return cext_get_top_item(&page);
}

View File

@ -16,6 +16,8 @@
#include "wm.h" #include "wm.h"
static Draw d = { 0 };
static XRectangle initial_rect;
static int other_wm_running; static int other_wm_running;
static int (*x_error_handler) (Display *, XErrorEvent *); static int (*x_error_handler) (Display *, XErrorEvent *);
@ -110,42 +112,47 @@ scale_rect(XRectangle * from_dim, XRectangle * to_dim,
tgt->height = 1; tgt->height = 1;
} }
static void draw_pager_page(Page * p, Draw * d) static void draw_pager_frame(void *item)
{ {
unsigned int i, j; Frame *f = (Frame *)item;
XRectangle r = d->rect; if (f == cext_get_top_item(&f->area->frames)) {
char name[4]; d.bg = blitz_loadcolor(dpy, screen_num, def[WM_SEL_BG_COLOR]->content);
if (p == page[sel]) { d.fg = blitz_loadcolor(dpy, screen_num, def[WM_SEL_FG_COLOR]->content);
d->bg = blitz_loadcolor(dpy, screen_num, def[WM_SEL_BG_COLOR]->content); d.border = blitz_loadcolor(dpy, screen_num, def[WM_SEL_BORDER_COLOR]->content);
d->fg = blitz_loadcolor(dpy, screen_num, def[WM_SEL_FG_COLOR]->content);
d->border = blitz_loadcolor(dpy, screen_num, def[WM_SEL_BORDER_COLOR]->content);
} else { } else {
d->bg = blitz_loadcolor(dpy, screen_num, def[WM_NORM_BG_COLOR]->content); d.bg = blitz_loadcolor(dpy, screen_num, def[WM_NORM_BG_COLOR]->content);
d->fg = blitz_loadcolor(dpy, screen_num, def[WM_NORM_FG_COLOR]->content); d.fg = blitz_loadcolor(dpy, screen_num, def[WM_NORM_FG_COLOR]->content);
d->border = blitz_loadcolor(dpy, screen_num, def[WM_NORM_BORDER_COLOR]->content); d.border = blitz_loadcolor(dpy, screen_num, def[WM_NORM_BORDER_COLOR]->content);
} }
snprintf(name, sizeof(name), "%d", index_item((void **) page, p)); d.data = ((Client *)cext_get_top_item(&f->clients))->file[C_NAME]->content;
d->data = name; scale_rect(&rect, &initial_rect, &f->area->rect, &d.rect);
blitz_drawlabel(dpy, d); blitz_drawlabel(dpy, &d);
XSync(dpy, False);
for (i = 0; p->area[i]; i++) {
for (j = 0; p->area[i]->frame && p->area[i]->frame[j]; j++) {
if (i == p->sel && j == p->area[i]->sel) {
d->bg = blitz_loadcolor(dpy, screen_num, def[WM_SEL_BG_COLOR]->content);
d->fg = blitz_loadcolor(dpy, screen_num, def[WM_SEL_FG_COLOR]->content);
d->border = blitz_loadcolor(dpy, screen_num, def[WM_SEL_BORDER_COLOR]->content);
} else {
d->bg = blitz_loadcolor(dpy, screen_num, def[WM_NORM_BG_COLOR]->content);
d->fg = blitz_loadcolor(dpy, screen_num, def[WM_NORM_FG_COLOR]->content);
d->border = blitz_loadcolor(dpy, screen_num, def[WM_NORM_BORDER_COLOR]->content);
}
d->data = p->area[i]->frame[j]->client[p->area[i]->frame[j]->sel]->file[C_NAME]->content;
scale_rect(&rect, &r, &p->area[i]->rect, &d->rect);
blitz_drawlabel(dpy, d);
XSync(dpy, False); /* do not clear upwards */ XSync(dpy, False); /* do not clear upwards */
}
static void draw_pager_area(void *item)
{
cext_iterate(&((Area *)item)->frames, draw_pager_frame);
}
static void draw_pager_page(Page * p)
{
char name[4];
initial_rect = d.rect;
if (p == cext_get_top_item(&pages)) {
d.bg = blitz_loadcolor(dpy, screen_num, def[WM_SEL_BG_COLOR]->content);
d.fg = blitz_loadcolor(dpy, screen_num, def[WM_SEL_FG_COLOR]->content);
d.border = blitz_loadcolor(dpy, screen_num, def[WM_SEL_BORDER_COLOR]->content);
} else {
d.bg = blitz_loadcolor(dpy, screen_num, def[WM_NORM_BG_COLOR]->content);
d.fg = blitz_loadcolor(dpy, screen_num, def[WM_NORM_FG_COLOR]->content);
d.border = blitz_loadcolor(dpy, screen_num, def[WM_NORM_BORDER_COLOR]->content);
} }
} snprintf(name, sizeof(name), "%d", cext_get_item_index(&pages, p));
d.data = name;
blitz_drawlabel(dpy, &d);
XSync(dpy, False);
cext_iterate(&p->areas, draw_pager_area);
} }
static void draw_pager() static void draw_pager()
@ -153,9 +160,9 @@ static void draw_pager()
unsigned int ic, ir, tw, th, rows, cols, size; unsigned int ic, ir, tw, th, rows, cols, size;
int i = 0; int i = 0;
int dx; int dx;
Draw d = { 0 }; Page *p;
blitz_getbasegeometry((void **) page, &size, &cols, &rows); blitz_getbasegeometry(&pages, &size, &cols, &rows);
dx = (cols - 1) * GAP; /* GAPpx space */ dx = (cols - 1) * GAP; /* GAPpx space */
tw = (rect.width - dx) / cols; tw = (rect.width - dx) / cols;
th = ((double) tw / rect.width) * rect.height; th = ((double) tw / rect.width) * rect.height;
@ -171,9 +178,9 @@ static void draw_pager()
else else
d.rect.y = ir * (rect.height - th) / (rows - 1); d.rect.y = ir * (rect.height - th) / (rows - 1);
d.rect.height = th; d.rect.height = th;
if (!page[i]) if (!(p = cext_get_item(&pages, i)))
return; return;
draw_pager_page(page[i], &d); draw_pager_page(p);
i++; i++;
} }
} }
@ -185,10 +192,11 @@ static Page *xy_to_pager_page(int x, int y)
int i = 0; int i = 0;
int dx; int dx;
XRectangle r; XRectangle r;
Page *p;
if (!page) if (!cext_sizeof(&pages))
return 0; return nil;
blitz_getbasegeometry((void **) page, &size, &cols, &rows); blitz_getbasegeometry(&pages, &size, &cols, &rows);
dx = (cols - 1) * GAP; /* GAPpx space */ dx = (cols - 1) * GAP; /* GAPpx space */
tw = (rect.width - dx) / cols; tw = (rect.width - dx) / cols;
th = ((double) tw / rect.width) * rect.height; th = ((double) tw / rect.width) * rect.height;
@ -202,14 +210,14 @@ static Page *xy_to_pager_page(int x, int y)
else else
r.y = ir * (rect.height - th) / (rows - 1); r.y = ir * (rect.height - th) / (rows - 1);
r.height = th; r.height = th;
if (!page[i]) if (!(p = cext_get_item(&pages, i)))
return 0; return nil;
if (blitz_ispointinrect(x, y, &r)) if (blitz_ispointinrect(x, y, &r))
return page[i]; return p;
i++; i++;
} }
} }
return 0; return nil;
} }
static int handle_kpress(XKeyEvent * e) static int handle_kpress(XKeyEvent * e)
@ -231,7 +239,7 @@ static void pager(void *obj, char *cmd)
XEvent ev; XEvent ev;
int i; int i;
if (!page) if (!cext_sizeof(&pages))
return; return;
XClearWindow(dpy, transient); XClearWindow(dpy, transient);
@ -253,8 +261,8 @@ static void pager(void *obj, char *cmd)
case KeyPress: case KeyPress:
XUnmapWindow(dpy, transient); XUnmapWindow(dpy, transient);
if ((i = handle_kpress(&ev.xkey)) != -1) if ((i = handle_kpress(&ev.xkey)) != -1)
if (i < count_items((void **) page)) if (i < cext_sizeof(&pages))
sel_page(page[i]); sel_page(cext_get_item(&pages, i));
XUngrabKeyboard(dpy, CurrentTime); XUngrabKeyboard(dpy, CurrentTime);
return; return;
break; break;
@ -276,9 +284,9 @@ static void draw_icons()
unsigned int i, ic, ir, tw, th, rows, cols, size; unsigned int i, ic, ir, tw, th, rows, cols, size;
int dx, dy; int dx, dy;
if (!detached) if (!cext_sizeof(&detached))
return; return;
blitz_getbasegeometry((void **) detached, &size, &cols, &rows); blitz_getbasegeometry(&detached, &size, &cols, &rows);
dx = (cols - 1) * GAP; /* GAPpx space */ dx = (cols - 1) * GAP; /* GAPpx space */
dy = (rows - 1) * GAP; /* GAPpx space */ dy = (rows - 1) * GAP; /* GAPpx space */
tw = (rect.width - dx) / cols; tw = (rect.width - dx) / cols;
@ -289,7 +297,7 @@ static void draw_icons()
i = 0; i = 0;
for (ir = 0; ir < rows; ir++) { for (ir = 0; ir < rows; ir++) {
for (ic = 0; ic < cols; ic++) { for (ic = 0; ic < cols; ic++) {
Client *c = detached[i++]; Client *c = cext_get_item(&detached, i++);
XRectangle cr; XRectangle cr;
if (!c) if (!c)
return; return;
@ -313,9 +321,10 @@ static void icons(void *obj, char *cmd)
{ {
XEvent ev; XEvent ev;
int i, n; int i, n;
size_t size = cext_sizeof(&detached);
Client *c; Client *c;
if (!detached) if (!size)
return; return;
XClearWindow(dpy, transient); XClearWindow(dpy, transient);
@ -335,16 +344,16 @@ static void icons(void *obj, char *cmd)
case KeyPress: case KeyPress:
XUnmapWindow(dpy, transient); XUnmapWindow(dpy, transient);
if ((n = handle_kpress(&ev.xkey)) != -1) { if ((n = handle_kpress(&ev.xkey)) != -1) {
for (i = 0; detached && detached[i]; i++) for (i = 0; i < size; i++)
hide_client(detached[i]); hide_client(cext_get_item(&detached, i));
if (n - 1 < i) { if (n - 1 < i) {
c = detached[n]; c = cext_get_item(&detached, n);
detached = (Client **) detach_item((void **) detached, c, sizeof(Client *)); cext_detach_item(&detached, c);
attach_client(c); attach_client(c);
} }
} else { } else {
for (i = 0; detached && detached[i]; i++) for (i = 0; i < size; i++)
hide_client(detached[i]); hide_client(cext_get_item(&detached, i));
} }
XUngrabKeyboard(dpy, CurrentTime); XUngrabKeyboard(dpy, CurrentTime);
return; return;
@ -352,10 +361,10 @@ static void icons(void *obj, char *cmd)
case ButtonPress: case ButtonPress:
if (ev.xbutton.button == Button1) { if (ev.xbutton.button == Button1) {
XUnmapWindow(dpy, transient); XUnmapWindow(dpy, transient);
for (i = 0; detached && detached[i]; i++) for (i = 0; i < size; i++)
hide_client(detached[i]); hide_client(cext_get_item(&detached, i));
if ((c = win_to_client(ev.xbutton.window))) { if ((c = win_to_client(ev.xbutton.window))) {
detached = (Client **) detach_item((void **) detached, c, sizeof(Client *)); cext_detach_item(&detached, c);
attach_client(c); attach_client(c);
} }
XUngrabKeyboard(dpy, CurrentTime); XUngrabKeyboard(dpy, CurrentTime);
@ -368,66 +377,68 @@ static void icons(void *obj, char *cmd)
static void _close_client(void *obj, char *cmd) static void _close_client(void *obj, char *cmd)
{ {
Frame *f = page ? SELFRAME(page[sel]) : 0; Frame *f = get_sel_frame();
if (f->client[f->sel]) if (f)
close_client(f->client[f->sel]); close_client(cext_get_top_item(&f->clients));
} }
static void _attach_client(void *obj, char *cmd) static void _attach_client(void *obj, char *cmd)
{ {
if (detached) { if (cext_sizeof(&detached)) {
Client *c = detached[0]; Client *c = cext_get_top_item(&detached);
detached = (Client **) detach_item((void **) detached, c, sizeof(Client *)); cext_detach_item(&detached, c);
attach_client(c); attach_client(c);
} }
} }
static void _detach_client(void *obj, char *cmd) static void _detach_client(void *obj, char *cmd)
{ {
Frame *f; Frame *f = get_sel_frame();
if (!page)
return;
f = SELFRAME(page[sel]);
if (!f) if (!f)
return; return;
f->area->layout->detach(f->area, f->client[f->sel]); f->area->layout->detach(f->area, cext_get_top_item(&f->clients));
} }
static void _select_page(void *obj, char *cmd) static void _select_page(void *obj, char *cmd)
{ {
if (!page || !cmd) Page *p = get_sel_page();
if (!p || !cmd)
return; return;
if (!strncmp(cmd, "prev", 5)) if (!strncmp(cmd, "prev", 5))
sel = index_prev_item((void **) page, page[sel]); p = cext_get_up_item(&pages, p);
else if (!strncmp(cmd, "next", 5)) else if (!strncmp(cmd, "next", 5))
sel = index_next_item((void **) page, page[sel]); p = cext_get_down_item(&pages, p);
else else
sel = _strtonum(cmd, 0, count_items((void **) page) - 1); p = cext_get_item(&pages, _strtonum(cmd, 0, cext_sizeof(&pages) - 1));
sel_page(page[sel]); sel_page(p);
} }
static void _destroy_page(void *obj, char *cmd) static void _destroy_page(void *obj, char *cmd)
{ {
if (!page) Page *p = get_sel_page();
return; if (p)
destroy_page(page[sel]); destroy_page(p);
} }
static void new_page(void *obj, char *cmd) static void new_page(void *obj, char *cmd)
{ {
if (page) Page *p = get_sel_page();
hide_page(page[sel]); if (p)
alloc_page("0"); destroy_page(p);
alloc_page();
}
static int comp_win(void *pattern, void *client)
{
Window w = *(Window *)pattern;
Client *c = client;
return c->win == w;
} }
Client *win_to_client(Window w) Client *win_to_client(Window w)
{ {
int i; return cext_find_item(&clients, &w, comp_win);
for (i = 0; client && client[i]; i++)
if (client[i]->win == w)
return client[i];
return 0;
} }
void scan_wins() void scan_wins()
@ -531,18 +542,17 @@ void handle_after_write(IXPServer * s, File * f)
check_event(0); check_event(0);
} }
static int comp_layout_name(void *name, void *layout)
{
Layout *l = layout;
size_t len = strlen(l->name);
return !strncmp(name, l->name, len);
}
Layout *get_layout(char *name) Layout *get_layout(char *name)
{ {
int i = 0; return cext_find_item(&layouts, name, comp_layout_name);
size_t len;
if (!name)
return 0;
len = strlen(name);
for (i = 0; layouts[i]; i++) {
if (!strncmp(name, layouts[i]->name, len))
return layouts[i];
}
return 0;
} }
static void init_atoms() static void init_atoms()
@ -667,22 +677,23 @@ static int startup_error_handler(Display * dpy, XErrorEvent * error)
return -1; return -1;
} }
static void cleanup() static void clean_client_up(void *item)
{ {
int i; Client *c = item;
XWindowChanges wc;
for (i = 0; client && client[i]; i++) {
Client *c = client[i];
Frame *f = c->frame; Frame *f = c->frame;
if (f) { if (f) {
XWindowChanges wc;
gravitate(c, tab_height(f), border_width(f), 1); gravitate(c, tab_height(f), border_width(f), 1);
XReparentWindow(dpy, c->win, root, f->rect.x + c->rect.x, XReparentWindow(dpy, c->win, root, f->rect.x + c->rect.x,
f->rect.y + c->rect.y); f->rect.y + c->rect.y);
wc.border_width = c->border; wc.border_width = c->border;
XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); XConfigureWindow(dpy, c->win, CWBorderWidth, &wc);
} }
} }
static void cleanup()
{
cext_iterate(&clients, clean_client_up);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
} }
@ -697,12 +708,7 @@ static void run()
} }
def[WM_CTL]->after_write = handle_after_write; def[WM_CTL]->after_write = handle_after_write;
client = 0; clients = frames = detached = pages = layouts = zero_container;
frame = 0;
detached = 0;
page = 0;
layouts = 0;
sel = 0;
init_atoms(); init_atoms();
init_cursors(); init_cursors();

View File

@ -6,7 +6,6 @@
#include <stdio.h> #include <stdio.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "cext.h"
#include "wmii.h" #include "wmii.h"
/* array indexes of page file pointers */ /* array indexes of page file pointers */
@ -112,8 +111,7 @@ typedef struct Client Client;
*/ */
struct Page { struct Page {
Area **area; Container areas;
unsigned int sel;
File *file[P_LAST]; File *file[P_LAST];
}; };
@ -130,8 +128,7 @@ struct Layout {
struct Area { struct Area {
Layout *layout; Layout *layout;
Page *page; Page *page;
Frame **frame; Container frames;
unsigned int sel;
XRectangle rect; XRectangle rect;
void *aux; /* free pointer */ void *aux; /* free pointer */
File *file[A_LAST]; File *file[A_LAST];
@ -139,12 +136,11 @@ struct Area {
struct Frame { struct Frame {
Area *area; Area *area;
Container clients;
Window win; Window win;
GC gc; GC gc;
XRectangle rect; XRectangle rect;
Cursor cursor; Cursor cursor;
Client **client;
int sel;
void *aux; /* free pointer */ void *aux; /* free pointer */
File *file[F_LAST]; File *file[F_LAST];
}; };
@ -161,9 +157,6 @@ struct Client {
File *file[C_LAST]; File *file[C_LAST];
}; };
#define SELAREA (page ? page[sel]->area[page[sel]->sel] : 0)
#define SELFRAME(x) (x && x->area[x->sel]->frame ? x->area[x->sel]->frame[x->area[x->sel]->sel] : 0)
#define ISSELFRAME(x) (page && SELFRAME(page[sel]) == x)
/* global variables */ /* global variables */
Display *dpy; Display *dpy;
@ -172,16 +165,16 @@ int screen_num;
Window root; Window root;
Window transient; Window transient;
XRectangle rect; XRectangle rect;
Client **detached; Container detached;
Page **page; Container pages;
unsigned int sel; Container frames;
Frame **frame; Container clients;
Client **client; Container layouts;
static Container zero_container = { 0 };
XFontStruct *font; XFontStruct *font;
XColor xorcolor; XColor xorcolor;
GC xorgc; GC xorgc;
GC transient_gc; GC transient_gc;
Layout **layouts;
Atom wm_state; Atom wm_state;
Atom wm_change_state; Atom wm_change_state;
@ -217,6 +210,7 @@ void detach_frame_from_area(Frame * f, int ignore_sel_and_destroy);
void draw_area(Area * a); void draw_area(Area * a);
void hide_area(Area * a); void hide_area(Area * a);
void show_area(Area * a); void show_area(Area * a);
Area *get_sel_area();
/* client.c */ /* client.c */
Client *alloc_client(Window w); Client *alloc_client(Window w);
@ -225,7 +219,7 @@ void destroy_client(Client * c);
void configure_client(Client * c); void configure_client(Client * c);
void handle_client_property(Client * c, XPropertyEvent * e); void handle_client_property(Client * c, XPropertyEvent * e);
void close_client(Client * c); void close_client(Client * c);
void draw_client(Client * c); void draw_client(void *item);
void draw_clients(Frame * f); void draw_clients(Frame * f);
void gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert); void gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert);
void grab_client(Client * c, unsigned long mod, unsigned int button); void grab_client(Client * c, unsigned long mod, unsigned int button);
@ -236,6 +230,7 @@ void reparent_client(Client * c, Window w, int x, int y);
void sel_client(Client *c); void sel_client(Client *c);
void attach_client(Client *c); void attach_client(Client *c);
void detach_client(Client *c); void detach_client(Client *c);
Client *get_sel_client();
/* frame.c */ /* frame.c */
void sel_frame(Frame * f, int raise); void sel_frame(Frame * f, int raise);
@ -250,6 +245,8 @@ void detach_client_from_frame(Client *c);
void draw_tab(Frame * f, char *text, int x, int y, int w, int h, int sel); void draw_tab(Frame * f, char *text, int x, int y, int w, int h, int sel);
unsigned int tab_height(Frame * f); unsigned int tab_height(Frame * f);
unsigned int border_width(Frame * f); unsigned int border_width(Frame * f);
Frame *get_sel_frame();
Frame *get_sel_frame_of_area(Area *a);
/* event.c */ /* event.c */
void init_event_hander(); void init_event_hander();
@ -264,6 +261,7 @@ Align xy_to_align(XRectangle * rect, int x, int y);
void drop_move(Frame * f, XRectangle * new, XPoint * pt); void drop_move(Frame * f, XRectangle * new, XPoint * pt);
/* page.c */ /* page.c */
Page *get_sel_page();
Page *alloc_page(); Page *alloc_page();
void free_page(Page * p); void free_page(Page * p);
void destroy_page(Page * p); void destroy_page(Page * p);

View File

@ -16,8 +16,6 @@
#include "wmii.h" #include "wmii.h"
#include <cext.h>
/* array indexes for file pointers */ /* array indexes for file pointers */
typedef enum { typedef enum {
B_CTL, B_CTL,
@ -290,17 +288,15 @@ static void draw_bar(void *obj, char *arg)
n = 0; n = 0;
for (f = label; f; f = f->next) for (f = label; f; f = f->next)
n++; n++;
paths = emalloc(sizeof(char *) * n); paths = cext_emalloc(sizeof(char *) * n);
i = 0; i = 0;
for (f = label; f; f = f->next) for (f = label; f; f = f->next)
paths[i++] = f->name; paths[i++] = f->name;
qsort(paths, n, sizeof(char *), comp_str); qsort(paths, n, sizeof(char *), comp_str);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
snprintf(buf, sizeof(buf), "/%s", paths[i]); snprintf(buf, sizeof(buf), "/%s", paths[i]);
item = emalloc(sizeof(Item)); item = cext_emalloc(sizeof(Item));
items = items = (Item **) attach_item_end((void **) items, item, sizeof(Item *));
(Item **) attach_item_end((void **) items, item,
sizeof(Item *));
init_item(buf, item); init_item(buf, item);
} }
draw(); draw();
@ -533,7 +529,7 @@ int main(int argc, char *argv[])
geom[0] = '\0'; geom[0] = '\0';
if (argc > i) if (argc > i)
_strlcpy(geom, argv[i], sizeof(geom)); cext_strlcpy(geom, argv[i], sizeof(geom));
ixps = wmii_setup_server(sockfile); ixps = wmii_setup_server(sockfile);
run(geom); run(geom);

View File

@ -19,7 +19,6 @@
#include "../libixp2/ixp.h" #include "../libixp2/ixp.h"
#include "blitz.h" #include "blitz.h"
#include "cext.h"
/* /*
* filesystem specification * filesystem specification
@ -193,7 +192,7 @@ static int make_qid(Qid * dir, char *wname, Qid * new)
return TRUE; return TRUE;
} }
/* check if wname is a number, otherwise file not found */ /* check if wname is a number, otherwise file not found */
idx = (u16) __strtonum(wname, 1, 0xffff, &errstr); idx = (u16) cext_strtonum(wname, 1, 0xffff, &errstr);
if (errstr || count_items((void **) items) < idx) if (errstr || count_items((void **) items) < idx)
return FALSE; return FALSE;
/* found */ /* found */
@ -208,7 +207,7 @@ static int make_qid(Qid * dir, char *wname, Qid * new)
static int attach(IXPServer * s, IXPConn * c) static int attach(IXPServer * s, IXPConn * c)
{ {
Map *map = emalloc(sizeof(Map)); Map *map = cext_emalloc(sizeof(Map));
fprintf(stderr, "attaching %d %s %s\n", s->fcall.afid, s->fcall.uname, fprintf(stderr, "attaching %d %s %s\n", s->fcall.afid, s->fcall.uname,
s->fcall.aname); s->fcall.aname);
map->qid = root_qid; map->qid = root_qid;
@ -257,7 +256,7 @@ static int walk(IXPServer * s, IXPConn * c)
(Map **) detach_item((void **) c->aux, map, sizeof(Map *)); (Map **) detach_item((void **) c->aux, map, sizeof(Map *));
free(map); free(map);
} }
map = emalloc(sizeof(Map)); map = cext_emalloc(sizeof(Map));
map->qid = qid; map->qid = qid;
map->fid = s->fcall.newfid; map->fid = s->fcall.newfid;
c->aux = c->aux =
@ -302,28 +301,28 @@ static int _read(IXPServer * s, IXPConn * c)
} }
stat.mode = 0xff; stat.mode = 0xff;
stat.atime = stat.mtime = time(0); stat.atime = stat.mtime = time(0);
_strlcpy(stat.uid, getenv("USER"), sizeof(stat.uid)); cext_strlcpy(stat.uid, getenv("USER"), sizeof(stat.uid));
_strlcpy(stat.gid, getenv("USER"), sizeof(stat.gid)); cext_strlcpy(stat.gid, getenv("USER"), sizeof(stat.gid));
_strlcpy(stat.muid, getenv("USER"), sizeof(stat.muid)); cext_strlcpy(stat.muid, getenv("USER"), sizeof(stat.muid));
fprintf(stderr, "%d\n", qpath_item(map->qid.path)); fprintf(stderr, "%d\n", qpath_item(map->qid.path));
switch (qpath_type(map->qid.path)) { switch (qpath_type(map->qid.path)) {
default: default:
case Droot: case Droot:
p = s->fcall.data; p = s->fcall.data;
_strlcpy(stat.name, "display", sizeof(stat.name)); cext_strlcpy(stat.name, "display", sizeof(stat.name));
stat.length = strlen(align); stat.length = strlen(align);
make_qid(&root_qid, "display", &stat.qid); make_qid(&root_qid, "display", &stat.qid);
stat.size = ixp_sizeof_stat(&stat); stat.size = ixp_sizeof_stat(&stat);
s->fcall.count = stat.size; s->fcall.count = stat.size;
p = ixp_enc_stat(p, &stat); p = ixp_enc_stat(p, &stat);
_strlcpy(stat.name, "font", sizeof(stat.name)); cext_strlcpy(stat.name, "font", sizeof(stat.name));
stat.length = strlen(font); stat.length = strlen(font);
make_qid(&root_qid, "font", &stat.qid); make_qid(&root_qid, "font", &stat.qid);
stat.size = ixp_sizeof_stat(&stat);; stat.size = ixp_sizeof_stat(&stat);;
s->fcall.count += stat.size; s->fcall.count += stat.size;
p = ixp_enc_stat(p, &stat); p = ixp_enc_stat(p, &stat);
_strlcpy(stat.name, "new", sizeof(stat.name)); cext_strlcpy(stat.name, "new", sizeof(stat.name));
stat.length = 0; stat.length = 0;
make_qid(&root_qid, "new", &stat.qid); make_qid(&root_qid, "new", &stat.qid);
stat.size = ixp_sizeof_stat(&stat);; stat.size = ixp_sizeof_stat(&stat);;
@ -438,7 +437,7 @@ int main(int argc, char *argv[])
atexit(exit_cleanup); atexit(exit_cleanup);
/* default item settings */ /* default item settings */
item = emalloc(sizeof(Item)); item = cext_emalloc(sizeof(Item));
item->id = 0; item->id = 0;
item->text[0] = '\0'; item->text[0] = '\0';
item->value = 0; item->value = 0;

View File

@ -9,8 +9,6 @@
#include "wmii.h" #include "wmii.h"
#include <cext.h>
/* array indexes for file pointers */ /* array indexes for file pointers */
typedef enum { typedef enum {
F_CTL, F_CTL,
@ -121,7 +119,7 @@ static void bind(void *obj, char *arg)
if (!arg) if (!arg)
return; return;
_strlcpy(cmd, arg, sizeof(cmd)); cext_strlcpy(cmd, arg, sizeof(cmd));
sfile = strchr(cmd, ' '); sfile = strchr(cmd, ' ');
if (!sfile) { if (!sfile) {
fprintf(stderr, fprintf(stderr,
@ -137,7 +135,7 @@ static void bind(void *obj, char *arg)
arg); arg);
return; /* shortcut with empty argument */ return; /* shortcut with empty argument */
} }
b = emalloc(sizeof(Bind)); b = cext_emalloc(sizeof(Bind));
*b = zero_bind; *b = zero_bind;
b->client = init_ixp_client(sfile); b->client = init_ixp_client(sfile);

View File

@ -16,8 +16,6 @@
#include "wmii.h" #include "wmii.h"
#include <cext.h>
/* array indexes for file pointers */ /* array indexes for file pointers */
typedef enum { typedef enum {
K_CTL, K_CTL,
@ -123,18 +121,18 @@ static void create_shortcut(File * f)
size_t i, toks; size_t i, toks;
Shortcut *s = 0, *r = 0; Shortcut *s = 0, *r = 0;
_strlcpy(buf, f->name, sizeof(buf)); cext_strlcpy(buf, f->name, sizeof(buf));
toks = tokenize(chain, 8, buf, ','); toks = cext_tokenize(chain, 8, buf, ',');
for (i = 0; i < toks; i++) { for (i = 0; i < toks; i++) {
if (!s) if (!s)
r = s = emalloc(sizeof(Shortcut)); r = s = cext_emalloc(sizeof(Shortcut));
else { else {
s->next = emalloc(sizeof(Shortcut)); s->next = cext_emalloc(sizeof(Shortcut));
s = s->next; s = s->next;
} }
*s = zero_shortcut; *s = zero_shortcut;
_strlcpy(s->name, chain[i], MAX_BUF); cext_strlcpy(s->name, chain[i], MAX_BUF);
k = strrchr(chain[i], '-'); k = strrchr(chain[i], '-');
if (k) if (k)
k++; k++;
@ -492,7 +490,7 @@ int main(int argc, char *argv[])
screen_num = DefaultScreen(dpy); screen_num = DefaultScreen(dpy);
size[0] = '\0'; size[0] = '\0';
if (argc > i) if (argc > i)
_strlcpy(size, argv[i], sizeof(size)); cext_strlcpy(size, argv[i], sizeof(size));
ixps = wmii_setup_server(sockfile); ixps = wmii_setup_server(sockfile);

View File

@ -18,8 +18,6 @@
#include "wmii.h" #include "wmii.h"
#include <cext.h>
/* array indexes for file pointers */ /* array indexes for file pointers */
typedef enum { typedef enum {
M_CTL, M_CTL,
@ -113,7 +111,7 @@ static void _exec(char *cmd)
add_history(cmd); add_history(cmd);
if (files[M_PRE_COMMAND]->content) { if (files[M_PRE_COMMAND]->content) {
size_t len = strlen(cmd) + files[M_PRE_COMMAND]->size + 2; size_t len = strlen(cmd) + files[M_PRE_COMMAND]->size + 2;
rc = emalloc(len); rc = cext_emalloc(len);
snprintf(rc, len, "%s %s", (char *) files[M_PRE_COMMAND]->content, snprintf(rc, len, "%s %s", (char *) files[M_PRE_COMMAND]->content,
cmd); cmd);
} }
@ -242,7 +240,7 @@ static int update_items(char *pattern)
items = 0; items = 0;
item_size = size; item_size = size;
if (item_size) if (item_size)
items = (File **) emalloc((item_size + 1) * sizeof(File *)); items = (File **) cext_emalloc((item_size + 1) * sizeof(File *));
} }
size = 0; size = 0;
@ -354,7 +352,7 @@ static void handle_kpress(XKeyEvent * e)
text[0] = '\0'; text[0] = '\0';
if (files[M_COMMAND]->content) { if (files[M_COMMAND]->content) {
_strlcpy(text, files[M_COMMAND]->content, sizeof(text)); cext_strlcpy(text, files[M_COMMAND]->content, sizeof(text));
len = strlen(text); len = strlen(text);
} }
buf[0] = '\0'; buf[0] = '\0';
@ -462,9 +460,9 @@ static void handle_kpress(XKeyEvent * e)
if ((num == 1) && !iscntrl((int) buf[0])) { if ((num == 1) && !iscntrl((int) buf[0])) {
buf[num] = '\0'; buf[num] = '\0';
if (len > 0) if (len > 0)
_strlcat(text, buf, sizeof(text)); cext_strlcat(text, buf, sizeof(text));
else else
_strlcpy(text, buf, sizeof(text)); cext_strlcpy(text, buf, sizeof(text));
set_text(text); set_text(text);
update_items(files[M_COMMAND]->content); update_items(files[M_COMMAND]->content);
} }
@ -653,7 +651,7 @@ int main(int argc, char *argv[])
size[0] = '\0'; size[0] = '\0';
if (argc > i) if (argc > i)
_strlcpy(size, argv[i], sizeof(size)); cext_strlcpy(size, argv[i], sizeof(size));
ixps = wmii_setup_server(sockfile); ixps = wmii_setup_server(sockfile);
items = 0; items = 0;

View File

@ -229,7 +229,7 @@ int main(int argc, char *argv[])
char *_argv[3]; char *_argv[3];
int _argc; int _argc;
while (fgets(line, 4096, stdin)) while (fgets(line, 4096, stdin))
if ((_argc = tokenize(_argv, 3, line, ' '))) { if ((_argc = cext_tokenize(_argv, 3, line, ' '))) {
if ((ret = perform_cmd(_argc, _argv))) if ((ret = perform_cmd(_argc, _argv)))
break; break;
} }

View File

@ -35,10 +35,12 @@ void cext_attach_item(Container *c, void *item);
void cext_detach_item(Container *c, void *item); void cext_detach_item(Container *c, void *item);
void *cext_find_item(Container *c, void *pattern, int (*comp)(void *pattern, void *item)); void *cext_find_item(Container *c, void *pattern, int (*comp)(void *pattern, void *item));
void cext_top_item(Container *c, void *item); void cext_top_item(Container *c, void *item);
void cext_iterate(Container *c, void (*doit)(void *));
void *cext_get_top_item(Container *c); void *cext_get_top_item(Container *c);
void *cext_get_down_item(Container *c, void *item); void *cext_get_down_item(Container *c, void *item);
void *cext_get_up_item(Container *c, void *item); void *cext_get_up_item(Container *c, void *item);
void *cext_get_item(Container *c, size_t index); void *cext_get_item(Container *c, size_t index);
int cext_get_item_index(Container *c, void *item);
size_t cext_sizeof(Container *c); size_t cext_sizeof(Container *c);
void **attach_item_begin(void **old, void *item, size_t size_item); void **attach_item_begin(void **old, void *item, size_t size_item);

View File

@ -76,6 +76,12 @@ void *cext_find_item(Container *c, void *pattern, int (*comp)(void *pattern, voi
return i ? i->item : nil; return i ? i->item : nil;
} }
void cext_iterate(Container *c, void (*doit)(void *))
{
CItem *i;
for (i = c->list; i; i = i->next)
doit(i->item);
}
void cext_top_item(Container *c, void *item) void cext_top_item(Container *c, void *item)
{ {
@ -121,6 +127,17 @@ void *cext_get_item(Container *c, size_t index)
return i ? i->item : nil; return i ? i->item : nil;
} }
int cext_get_item_index(Container *c, void *item)
{
int idx = 0;
CItem *i;
for (i = c->list; i && i->item != item; i = i->next)
idx++;
return i ? idx : -1;
}
size_t cext_sizeof(Container *c) size_t cext_sizeof(Container *c)
{ {
size_t idx = 0; size_t idx = 0;

View File

@ -117,7 +117,7 @@ static void *poll_server(IXPClient * c, void *request, size_t req_len,
handle_dead_server(c); handle_dead_server(c);
return 0; return 0;
} }
result = emalloc(*out_len); result = cext_emalloc(*out_len);
header = 1; header = 1;
} }
r = read(c->fd, ((char *) result) + num, *out_len - num); r = read(c->fd, ((char *) result) + num, *out_len - num);
@ -256,7 +256,7 @@ IXPClient *init_ixp_client(char *sockfile)
socklen_t su_len; socklen_t su_len;
/* init */ /* init */
IXPClient *c = (IXPClient *) emalloc(sizeof(IXPClient)); IXPClient *c = (IXPClient *) cext_emalloc(sizeof(IXPClient));
*c = zero_client; *c = zero_client;
c->create = cixp_create; c->create = cixp_create;
c->open = cixp_open; c->open = cixp_open;

View File

@ -17,7 +17,7 @@ void *tcreate_message(char *path, size_t * msg_len)
char *msg; char *msg;
ReqHeader h; ReqHeader h;
*msg_len = sizeof(ReqHeader) + strlen(path) + 1; *msg_len = sizeof(ReqHeader) + strlen(path) + 1;
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.req = TCREATE; h.req = TCREATE;
memcpy(msg, &h, sizeof(ReqHeader)); memcpy(msg, &h, sizeof(ReqHeader));
memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1); memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1);
@ -29,7 +29,7 @@ void *topen_message(char *path, size_t * msg_len)
char *msg; char *msg;
ReqHeader h; ReqHeader h;
*msg_len = sizeof(ReqHeader) + strlen(path) + 1; *msg_len = sizeof(ReqHeader) + strlen(path) + 1;
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.req = TOPEN; h.req = TOPEN;
memcpy(msg, &h, sizeof(ReqHeader)); memcpy(msg, &h, sizeof(ReqHeader));
memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1); memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1);
@ -42,7 +42,7 @@ void *tread_message(int fd, size_t offset, size_t buf_len,
char *msg; char *msg;
ReqHeader h; ReqHeader h;
*msg_len = sizeof(ReqHeader); *msg_len = sizeof(ReqHeader);
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.req = TREAD; h.req = TREAD;
h.fd = fd; h.fd = fd;
h.offset = offset; h.offset = offset;
@ -57,7 +57,7 @@ void *twrite_message(int fd, size_t offset, void *content,
char *msg; char *msg;
ReqHeader h; ReqHeader h;
*msg_len = sizeof(ReqHeader) + content_len; *msg_len = sizeof(ReqHeader) + content_len;
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.req = TWRITE; h.req = TWRITE;
h.fd = fd; h.fd = fd;
h.offset = offset; h.offset = offset;
@ -72,7 +72,7 @@ void *tclose_message(int fd, size_t * msg_len)
char *msg; char *msg;
ReqHeader h; ReqHeader h;
*msg_len = sizeof(ReqHeader); *msg_len = sizeof(ReqHeader);
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.req = TCLUNK; h.req = TCLUNK;
h.fd = fd; h.fd = fd;
memcpy(msg, &h, sizeof(ReqHeader)); memcpy(msg, &h, sizeof(ReqHeader));
@ -84,7 +84,7 @@ void *tremove_message(char *path, size_t * msg_len)
char *msg; char *msg;
ReqHeader h; ReqHeader h;
*msg_len = sizeof(ReqHeader) + strlen(path) + 1; *msg_len = sizeof(ReqHeader) + strlen(path) + 1;
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.req = TREMOVE; h.req = TREMOVE;
memcpy(msg, &h, sizeof(ReqHeader)); memcpy(msg, &h, sizeof(ReqHeader));
memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1); memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1);
@ -98,7 +98,7 @@ void *rcreate_message(size_t * msg_len)
char *msg; char *msg;
ResHeader h; ResHeader h;
*msg_len = sizeof(ResHeader); *msg_len = sizeof(ResHeader);
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.res = RCREATE; h.res = RCREATE;
memcpy(msg, &h, sizeof(ResHeader)); memcpy(msg, &h, sizeof(ResHeader));
return msg; return msg;
@ -109,7 +109,7 @@ void *ropen_message(int fd, size_t * msg_len)
char *msg; char *msg;
ResHeader h; ResHeader h;
*msg_len = sizeof(ResHeader); *msg_len = sizeof(ResHeader);
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.res = ROPEN; h.res = ROPEN;
h.fd = fd; h.fd = fd;
memcpy(msg, &h, sizeof(ResHeader)); memcpy(msg, &h, sizeof(ResHeader));
@ -121,7 +121,7 @@ void *rread_message(void *content, size_t content_len, size_t * msg_len)
char *msg; char *msg;
ResHeader h; ResHeader h;
*msg_len = sizeof(ResHeader) + content_len; *msg_len = sizeof(ResHeader) + content_len;
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.res = RREAD; h.res = RREAD;
h.buf_len = content_len; h.buf_len = content_len;
memcpy(msg, &h, sizeof(ResHeader)); memcpy(msg, &h, sizeof(ResHeader));
@ -134,7 +134,7 @@ void *rwrite_message(size_t * msg_len)
char *msg; char *msg;
ResHeader h; ResHeader h;
*msg_len = sizeof(ResHeader); *msg_len = sizeof(ResHeader);
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.res = RWRITE; h.res = RWRITE;
memcpy(msg, &h, sizeof(ResHeader)); memcpy(msg, &h, sizeof(ResHeader));
return msg; return msg;
@ -145,7 +145,7 @@ void *rclose_message(size_t * msg_len)
char *msg; char *msg;
ResHeader h; ResHeader h;
*msg_len = sizeof(ResHeader); *msg_len = sizeof(ResHeader);
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.res = RCLUNK; h.res = RCLUNK;
memcpy(msg, &h, sizeof(ResHeader)); memcpy(msg, &h, sizeof(ResHeader));
return msg; return msg;
@ -156,7 +156,7 @@ void *rremove_message(size_t * msg_len)
char *msg; char *msg;
ResHeader h; ResHeader h;
*msg_len = sizeof(ResHeader); *msg_len = sizeof(ResHeader);
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.res = RREMOVE; h.res = RREMOVE;
memcpy(msg, &h, sizeof(ResHeader)); memcpy(msg, &h, sizeof(ResHeader));
return msg; return msg;
@ -168,7 +168,7 @@ void *rerror_message(char *errstr, size_t * msg_len)
size_t len = strlen(errstr) + 1; size_t len = strlen(errstr) + 1;
ResHeader h; ResHeader h;
*msg_len = sizeof(ResHeader) + len; *msg_len = sizeof(ResHeader) + len;
msg = emalloc(*msg_len); msg = cext_emalloc(*msg_len);
h.res = RERROR; h.res = RERROR;
memcpy(msg, &h, sizeof(ResHeader)); memcpy(msg, &h, sizeof(ResHeader));
memmove(msg + sizeof(ResHeader), errstr, len); memmove(msg + sizeof(ResHeader), errstr, len);

View File

@ -53,7 +53,7 @@ File *ixp_create(IXPServer * s, char *path)
} }
/* only create missing parts, if file is directory */ /* only create missing parts, if file is directory */
while (tok) { while (tok) {
f = (File *) emalloc(sizeof(File)); f = (File *) cext_emalloc(sizeof(File));
*f = zero_file; *f = zero_file;
f->name = strdup(tok); f->name = strdup(tok);
f->parent = p; f->parent = p;
@ -90,7 +90,7 @@ static char *_ls(File * f)
for (p = f; p; p = p->next) for (p = f; p; p = p->next)
num++; num++;
tmp = emalloc(sizeof(File *) * num); tmp = cext_emalloc(sizeof(File *) * num);
i = 0; i = 0;
for (p = f; p; p = p->next) { for (p = f; p; p = p->next) {
size += strlen(p->name) + 1; size += strlen(p->name) + 1;
@ -99,7 +99,7 @@ static char *_ls(File * f)
tmp[i++] = p; tmp[i++] = p;
} }
qsort(tmp, num, sizeof(char *), comp_file_name); qsort(tmp, num, sizeof(char *), comp_file_name);
result = emalloc(size); result = cext_emalloc(size);
result[0] = '\0'; result[0] = '\0';
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
strncat(result, tmp[i]->name, size); strncat(result, tmp[i]->name, size);

View File

@ -81,7 +81,7 @@ static void handle_ixp_read(Connection * c, ReqHeader * h)
void *data = 0; void *data = 0;
size_t out_len; size_t out_len;
data = emalloc(h->buf_len); data = cext_emalloc(h->buf_len);
out_len = c->s->read(c->s, h->fd, h->offset, data, h->buf_len); out_len = c->s->read(c->s, h->fd, h->offset, data, h->buf_len);
free(c->data); free(c->data);
if (c->s->errstr) { if (c->s->errstr) {
@ -219,7 +219,7 @@ static void read_conn(Connection * c)
return; return;
} }
c->remain = c->len; c->remain = c->len;
c->data = emalloc(c->len); c->data = cext_emalloc(c->len);
c->header = 1; c->header = 1;
} }
r = read(c->fd, ((char *) c->data) + c->len - c->remain, c->remain); r = read(c->fd, ((char *) c->data) + c->len - c->remain, c->remain);
@ -347,10 +347,10 @@ IXPServer *init_server(char *sockfile, void (*cleanup) (void))
IXPServer *s; IXPServer *s;
/* init */ /* init */
s = (IXPServer *) emalloc(sizeof(IXPServer)); s = (IXPServer *) cext_emalloc(sizeof(IXPServer));
*s = zero_server; *s = zero_server;
s->sockfile = sockfile; s->sockfile = sockfile;
s->root = (File *) emalloc(sizeof(File)); s->root = (File *) cext_emalloc(sizeof(File));
s->runlevel = HALT; /* initially server is not running */ s->runlevel = HALT; /* initially server is not running */
s->create = ixp_create; s->create = ixp_create;
s->remove = ixp_remove; s->remove = ixp_remove;

View File

@ -44,7 +44,7 @@ int ixp_client_init(IXPClient * c, char *sockfile)
c->fcall.id = TVERSION; c->fcall.id = TVERSION;
c->fcall.tag = IXP_NOTAG; c->fcall.tag = IXP_NOTAG;
c->fcall.maxmsg = IXP_MAX_MSG; c->fcall.maxmsg = IXP_MAX_MSG;
_strlcpy(c->fcall.version, IXP_VERSION, sizeof(c->fcall.version)); cext_strlcpy(c->fcall.version, IXP_VERSION, sizeof(c->fcall.version));
if (!do_fcall(c)) { if (!do_fcall(c)) {
ixp_client_deinit(c); ixp_client_deinit(c);
return FALSE; return FALSE;
@ -61,7 +61,7 @@ int ixp_client_init(IXPClient * c, char *sockfile)
c->fcall.tag = IXP_NOTAG; c->fcall.tag = IXP_NOTAG;
c->fcall.fid = c->root_fid; c->fcall.fid = c->root_fid;
c->fcall.afid = IXP_NOFID; c->fcall.afid = IXP_NOFID;
_strlcpy(c->fcall.uname, getenv("USER"), sizeof(c->fcall.uname)); cext_strlcpy(c->fcall.uname, getenv("USER"), sizeof(c->fcall.uname));
c->fcall.aname[0] = '\0'; c->fcall.aname[0] = '\0';
if (!do_fcall(c)) { if (!do_fcall(c)) {
ixp_client_deinit(c); ixp_client_deinit(c);
@ -89,7 +89,7 @@ ixp_client_create(IXPClient * c, u32 dirfid, char *name, u32 perm, u8 mode)
c->fcall.id = TCREATE; c->fcall.id = TCREATE;
c->fcall.tag = IXP_NOTAG; c->fcall.tag = IXP_NOTAG;
c->fcall.fid = dirfid; c->fcall.fid = dirfid;
_strlcpy(c->fcall.name, name, sizeof(c->fcall.name)); cext_strlcpy(c->fcall.name, name, sizeof(c->fcall.name));
c->fcall.perm = perm; c->fcall.perm = perm;
c->fcall.mode = mode; c->fcall.mode = mode;
return do_fcall(c); return do_fcall(c);
@ -102,10 +102,8 @@ int ixp_client_walk(IXPClient * c, u32 newfid, char *filepath)
c->fcall.fid = c->root_fid; c->fcall.fid = c->root_fid;
c->fcall.newfid = newfid; c->fcall.newfid = newfid;
if (filepath) { if (filepath) {
_strlcpy(c->fcall.name, filepath, sizeof(c->fcall.name)); cext_strlcpy(c->fcall.name, filepath, sizeof(c->fcall.name));
c->fcall.nwname = c->fcall.nwname = cext_tokenize((char **) c->fcall.wname, IXP_MAX_WELEM, c->fcall.name, '/');
tokenize((char **) c->fcall.wname, IXP_MAX_WELEM,
c->fcall.name, '/');
} }
return do_fcall(c); return do_fcall(c);
} }

View File

@ -111,7 +111,7 @@ static void server_client_read(IXPServer * s, IXPConn * c)
if (!s->errstr) if (!s->errstr)
s->errstr = "function not supported"; s->errstr = "function not supported";
s->fcall.id = RERROR; s->fcall.id = RERROR;
_strlcpy(s->fcall.errstr, s->errstr, sizeof(s->fcall.errstr)); cext_strlcpy(s->fcall.errstr, s->errstr, sizeof(s->fcall.errstr));
msize = ixp_fcall_to_msg(&s->fcall, msg, IXP_MAX_MSG); msize = ixp_fcall_to_msg(&s->fcall, msg, IXP_MAX_MSG);
if (ixp_send_message(c->fd, msg, msize, &s->errstr) != msize) if (ixp_send_message(c->fd, msg, msize, &s->errstr) != msize)
ixp_server_rm_conn(s, c); ixp_server_rm_conn(s, c);

View File

@ -4,6 +4,7 @@
*/ */
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <cext.h>
#define BLITZ_FONT "fixed" #define BLITZ_FONT "fixed"
#define BLITZ_SEL_FG_COLOR "#eeeeee" #define BLITZ_SEL_FG_COLOR "#eeeeee"
@ -44,9 +45,7 @@ void blitz_drawlabelnoborder(Display * dpy, Draw * r);
int blitz_strtorect(XRectangle * root, XRectangle * r, char *val); int blitz_strtorect(XRectangle * root, XRectangle * r, char *val);
int blitz_ispointinrect(int x, int y, XRectangle * r); int blitz_ispointinrect(int x, int y, XRectangle * r);
int blitz_distance(XRectangle * origin, XRectangle * target); int blitz_distance(XRectangle * origin, XRectangle * target);
void void blitz_getbasegeometry(Container *c, unsigned int *size, unsigned int *cols, unsigned int *rows);
blitz_getbasegeometry(void **items, unsigned int *size,
unsigned int *cols, unsigned int *rows);
/* mouse.c */ /* mouse.c */
char *blitz_buttontostr(unsigned int button); char *blitz_buttontostr(unsigned int button);

View File

@ -7,8 +7,6 @@
#include <string.h> #include <string.h>
#include "blitz.h" #include "blitz.h"
#include <cext.h>
XFontStruct *blitz_getfont(Display * dpy, char *fontstr) XFontStruct *blitz_getfont(Display * dpy, char *fontstr)
{ {
XFontStruct *font; XFontStruct *font;
@ -28,7 +26,7 @@ unsigned long blitz_loadcolor(Display * dpy, int mon, char *colstr)
XColor color; XColor color;
char col[8]; char col[8];
_strlcpy(col, colstr, sizeof(col)); cext_strlcpy(col, colstr, sizeof(col));
col[7] = '\0'; col[7] = '\0';
XAllocNamedColor(dpy, DefaultColormap(dpy, mon), col, &color, &color); XAllocNamedColor(dpy, DefaultColormap(dpy, mon), col, &color, &color);
return color.pixel; return color.pixel;
@ -87,7 +85,7 @@ static void draw_text(Display * dpy, Draw * d)
return; return;
len = strlen(d->data); len = strlen(d->data);
_strlcpy(text, d->data, sizeof(text)); cext_strlcpy(text, d->data, sizeof(text));
XSetFont(dpy, d->gc, d->font->fid); XSetFont(dpy, d->gc, d->font->fid);
h = d->font->ascent + d->font->descent; h = d->font->ascent + d->font->descent;
y = d->rect.y + d->rect.height / 2 - h / 2 + d->font->ascent; y = d->rect.y + d->rect.height / 2 - h / 2 + d->font->ascent;

View File

@ -8,7 +8,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "blitz.h" #include "blitz.h"
#include <cext.h>
static int strtoalign(Align * result, char *val) static int strtoalign(Align * result, char *val)
{ {
@ -57,7 +56,7 @@ int blitz_strtorect(XRectangle * root, XRectangle * r, char *val)
return FALSE; return FALSE;
sx = sy = sw = sh = 0; sx = sy = sw = sh = 0;
x = y = w = h = 0; x = y = w = h = 0;
_strlcpy(buf, val, sizeof(buf)); cext_strlcpy(buf, val, sizeof(buf));
x = strtok_r(buf, ",", &p); x = strtok_r(buf, ",", &p);
if (x) { if (x) {
@ -201,13 +200,11 @@ int blitz_distance(XRectangle * origin, XRectangle * target)
((oy - ty) * (oy - ty)))); ((oy - ty) * (oy - ty))));
} }
void void blitz_getbasegeometry(Container *c, unsigned int *size, unsigned int *cols, unsigned int *rows)
blitz_getbasegeometry(void **items, unsigned int *size,
unsigned int *cols, unsigned int *rows)
{ {
float sq, dummy; float sq, dummy;
*size = count_items((void **) items); *size = cext_sizeof(c);
sq = sqrt(*size); sq = sqrt(*size);
if (modff(sq, &dummy) < 0.5) if (modff(sq, &dummy) < 0.5)
*rows = floor(sq); *rows = floor(sq);

View File

@ -7,8 +7,6 @@
#include "blitz.h" #include "blitz.h"
#include <cext.h>
/* free the result manually! */ /* free the result manually! */
char *blitz_modtostr(unsigned long mod) char *blitz_modtostr(unsigned long mod)
{ {
@ -16,20 +14,20 @@ char *blitz_modtostr(unsigned long mod)
result[0] = '\0'; result[0] = '\0';
if (mod & ShiftMask) if (mod & ShiftMask)
_strlcat(result, "S-", sizeof(result)); cext_strlcat(result, "S-", sizeof(result));
if (mod & ControlMask) if (mod & ControlMask)
_strlcat(result, "C-", sizeof(result)); cext_strlcat(result, "C-", sizeof(result));
if (mod & Mod1Mask) if (mod & Mod1Mask)
_strlcat(result, "M-", sizeof(result)); cext_strlcat(result, "M-", sizeof(result));
if (mod & Mod2Mask) if (mod & Mod2Mask)
_strlcat(result, "M2-", sizeof(result)); cext_strlcat(result, "M2-", sizeof(result));
if (mod & Mod3Mask) if (mod & Mod3Mask)
_strlcat(result, "M3-", sizeof(result)); cext_strlcat(result, "M3-", sizeof(result));
if (mod & Mod4Mask) if (mod & Mod4Mask)
_strlcat(result, "WIN-", sizeof(result)); cext_strlcat(result, "WIN-", sizeof(result));
if (mod & Mod5Mask) if (mod & Mod5Mask)
_strlcat(result, "M5-", sizeof(result)); cext_strlcat(result, "M5-", sizeof(result));
return estrdup(result); return cext_estrdup(result);
} }
unsigned long blitz_strtomod(char *val) unsigned long blitz_strtomod(char *val)

View File

@ -9,15 +9,13 @@
#include "blitz.h" #include "blitz.h"
#include <cext.h>
/* free the result manually! */ /* free the result manually! */
char *blitz_buttontostr(unsigned int button) char *blitz_buttontostr(unsigned int button)
{ {
char result[8]; char result[8];
result[0] = '\0'; result[0] = '\0';
snprintf(result, 8, "Button%ud", button - Button1); snprintf(result, 8, "Button%ud", button - Button1);
return estrdup(result); return cext_estrdup(result);
} }
unsigned int blitz_strtobutton(char *val) unsigned int blitz_strtobutton(char *val)

View File

@ -5,16 +5,13 @@
#include <stdio.h> #include <stdio.h>
#include "cext.h"
#include "blitz.h" #include "blitz.h"
long long _strtonum(const char *numstr, long long minval, long long maxval) long long _strtonum(const char *numstr, long long minval, long long maxval)
{ {
const char *errstr; const char *errstr;
long long ret = __strtonum(numstr, minval, maxval, &errstr); long long ret = cext_strtonum(numstr, minval, maxval, &errstr);
if (errstr) if (errstr)
fprintf(stderr, fprintf(stderr, "liblitz: cannot convert '%s' into integer: %s\n", numstr, errstr);
"liblitz: cannot convert '%s' into integer: %s\n",
numstr, errstr);
return ret; return ret;
} }

View File

@ -17,8 +17,6 @@
static pid_t mypid; static pid_t mypid;
static char *mysockfile; static char *mysockfile;
/* convenience stuff ----------------------------------------------- */
File *wmii_create_ixpfile(IXPServer * s, char *key, char *val) File *wmii_create_ixpfile(IXPServer * s, char *key, char *val)
{ {
File *f = ixp_create(s, key); File *f = ixp_create(s, key);
@ -38,10 +36,10 @@ void wmii_get_ixppath(File * f, char *path, size_t size)
buf[0] = '\0'; buf[0] = '\0';
if (path) if (path)
_strlcpy(buf, path, sizeof(buf)); cext_strlcpy(buf, path, sizeof(buf));
snprintf(path, size, "%s/", f->name); snprintf(path, size, "%s/", f->name);
if (buf[0] != '\0') if (buf[0] != '\0')
_strlcat(path, buf, size); cext_strlcat(path, buf, size);
if (f->parent) if (f->parent)
wmii_get_ixppath(f->parent, path, size); wmii_get_ixppath(f->parent, path, size);
} }

View File

@ -41,7 +41,7 @@ void win_prop(Display * dpy, Window w, Atom a, char *res, int len)
unsigned char *prop; unsigned char *prop;
if (property(dpy, w, a, XA_STRING, 100L, &prop)) { if (property(dpy, w, a, XA_STRING, 100L, &prop)) {
_strlcpy(res, (char *) prop, len); cext_strlcpy(res, (char *) prop, len);
XFree(prop); XFree(prop);
} }
res[len - 1] = '\0'; res[len - 1] = '\0';