mirror of
https://github.com/0intro/wmii
synced 2024-11-22 05:42:05 +03:00
changed various parts to use new rocking data structure
This commit is contained in:
parent
1d95f1fa99
commit
fefbab01e2
@ -9,14 +9,12 @@
|
||||
|
||||
#include "wm.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
static Area zero_area = {0};
|
||||
|
||||
Area *alloc_area(Page *p, XRectangle * r, char *layout)
|
||||
{
|
||||
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;
|
||||
|
||||
*a = zero_area;
|
||||
@ -108,3 +106,10 @@ void show_area(Area * a)
|
||||
for (i = 0; a->frame && a->frame[i]; i++)
|
||||
XMapWindow(dpy, a->frame[i]->win);
|
||||
}
|
||||
|
||||
Area *get_sel_area()
|
||||
{
|
||||
Page *p = cext_get_top_item(&page);
|
||||
|
||||
return p ? p->area[p->sel] : nil;
|
||||
}
|
||||
|
@ -10,8 +10,6 @@
|
||||
|
||||
#include "wm.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
static Client zero_client = { 0 };
|
||||
|
||||
Client *alloc_client(Window w)
|
||||
@ -19,7 +17,7 @@ Client *alloc_client(Window w)
|
||||
static int id = 0;
|
||||
char buf[MAX_BUF];
|
||||
char buf2[MAX_BUF];
|
||||
Client *c = (Client *) emalloc(sizeof(Client));
|
||||
Client *c = (Client *) cext_emalloc(sizeof(Client));
|
||||
|
||||
*c = zero_client;
|
||||
c->win = w;
|
||||
@ -29,7 +27,7 @@ Client *alloc_client(Window w)
|
||||
snprintf(buf, MAX_BUF, "/detached/c/%d/name", id);
|
||||
c->file[C_NAME] = wmii_create_ixpfile(ixps, buf, buf2);
|
||||
id++;
|
||||
client = (Client **) attach_item_end((void **) client, c, sizeof(Client *));
|
||||
cext_attach_item(&clients, c);
|
||||
XSelectInput(dpy, c->win, CLIENT_MASK);
|
||||
return c;
|
||||
}
|
||||
@ -39,7 +37,7 @@ void sel_client(Client * c)
|
||||
Frame *f = 0;
|
||||
/* sel client */
|
||||
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;
|
||||
XRaiseWindow(dpy, c->win);
|
||||
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
||||
@ -182,7 +180,7 @@ void handle_client_property(Client * c, XPropertyEvent * e)
|
||||
if (strlen(buf)) {
|
||||
if (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);
|
||||
}
|
||||
if (c->frame)
|
||||
@ -203,7 +201,7 @@ void handle_client_property(Client * c, XPropertyEvent * e)
|
||||
|
||||
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]);
|
||||
if (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 */
|
||||
void draw_client(Client * c)
|
||||
void draw_client(void *item)
|
||||
{
|
||||
Client *c = item;
|
||||
Frame *f = c->frame;
|
||||
unsigned int tabh = tab_height(f);
|
||||
int i, size;
|
||||
int tw;
|
||||
unsigned int tw, tabh = tab_height(f);
|
||||
size_t size;
|
||||
int i;
|
||||
|
||||
if (!tabh)
|
||||
return;
|
||||
size = count_items((void **) f->client);
|
||||
size = cext_sizeof(&f->clients);
|
||||
tw = f->rect.width;
|
||||
if (size)
|
||||
tw /= size;
|
||||
for (i = 0; f->client[i] && f->client[i] != c; i++);
|
||||
|
||||
if (!f->client[i + 1])
|
||||
draw_tab(f, c->file[C_NAME]->content, i * tw, 0,
|
||||
f->rect.width - (i * tw), tabh, ISSELFRAME(f)
|
||||
&& f->client[f->sel] == c);
|
||||
i = cext_get_item_index(&f->clients, c);
|
||||
if (i < size - 1)
|
||||
draw_tab(f, c->file[C_NAME]->content, i * tw, 0, f->rect.width - (i * tw), tabh,
|
||||
(f == get_sel_frame()) && (c == get_sel_client()));
|
||||
else
|
||||
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)
|
||||
{
|
||||
unsigned int tabh = tab_height(f);
|
||||
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);
|
||||
cext_iterate(&f->clients, draw_client);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Area *a = 0;
|
||||
Frame *old;
|
||||
if (!page)
|
||||
Frame *old = get_sel_frame();
|
||||
if (!cext_sizeof(&pages))
|
||||
alloc_page();
|
||||
old = SELFRAME(page[sel]);
|
||||
/* transient stuff */
|
||||
a = SELAREA;
|
||||
a = get_sel_area();
|
||||
if (c && c->trans) {
|
||||
Client *t = win_to_client(c->trans);
|
||||
if (t && t->frame)
|
||||
@ -345,7 +322,11 @@ void detach_client(Client *c) {
|
||||
c->frame->area->layout->detach(c->frame->area, c);
|
||||
if (c->destroyed)
|
||||
destroy_client(c);
|
||||
if (page)
|
||||
sel_page(page[sel]);
|
||||
sel_page(get_sel_page());
|
||||
}
|
||||
|
||||
Client *get_sel_client()
|
||||
{
|
||||
Frame *f = get_sel_frame();
|
||||
return f ? cext_get_top_item(&f->clients) : nil;
|
||||
}
|
||||
|
@ -10,8 +10,6 @@
|
||||
|
||||
#include "wm.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
static Frame zero_frame = { 0 };
|
||||
|
||||
static void select_client(void *obj, char *cmd);
|
||||
@ -29,7 +27,7 @@ Frame *alloc_frame(XRectangle * r)
|
||||
XSetWindowAttributes wa;
|
||||
static int id = 0;
|
||||
char buf[MAX_BUF];
|
||||
Frame *f = (Frame *) emalloc(sizeof(Frame));
|
||||
Frame *f = (Frame *) cext_emalloc(sizeof(Frame));
|
||||
int bw, th;
|
||||
|
||||
*f = zero_frame;
|
||||
@ -406,7 +404,7 @@ static void handle_before_read_frame(IXPServer * s, File * f)
|
||||
frame[i]->rect.height);
|
||||
if (f->content)
|
||||
free(f->content);
|
||||
f->content = estrdup(buf);
|
||||
f->content = cext_estrdup(buf);
|
||||
f->size = strlen(buf);
|
||||
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));
|
||||
}
|
||||
|
@ -10,8 +10,6 @@
|
||||
#include "wm.h"
|
||||
#include "layout.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
typedef struct Acme Acme;
|
||||
typedef struct Column Column;
|
||||
|
||||
@ -75,7 +73,7 @@ static void arrange_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;
|
||||
unsigned int width = 1;
|
||||
Column *col;
|
||||
@ -97,9 +95,9 @@ static void init_col(Area * a)
|
||||
*/
|
||||
|
||||
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++) {
|
||||
acme->column[i] = emalloc(sizeof(Column));
|
||||
acme->column[i] = cext_emalloc(sizeof(Column));
|
||||
*acme->column[i] = zero_column;
|
||||
acme->column[i]->rect = a->rect;
|
||||
acme->column[i]->rect.x = i * width;
|
||||
@ -128,7 +126,7 @@ static void init_col(Area * a)
|
||||
j++;
|
||||
}
|
||||
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++) {
|
||||
col->frame[i] = alloc_frame(&client[j + i]->rect);
|
||||
col->frame[i]->aux = col;
|
||||
|
@ -10,8 +10,6 @@
|
||||
#include "wm.h"
|
||||
#include "layout.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
static void init_float(Area * a);
|
||||
static void deinit_float(Area * a);
|
||||
static void arrange_float(Area * a);
|
||||
|
@ -9,8 +9,6 @@
|
||||
|
||||
#include "wm.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
static Page zero_page = { 0 };
|
||||
|
||||
static void select_frame(void *obj, char *cmd);
|
||||
@ -24,7 +22,7 @@ Action page_acttbl[] = {
|
||||
|
||||
Page *alloc_page()
|
||||
{
|
||||
Page *p = emalloc(sizeof(Page));
|
||||
Page *p = cext_emalloc(sizeof(Page));
|
||||
char buf[MAX_BUF], buf2[16];
|
||||
int id = count_items((void **) page) + 1;
|
||||
|
||||
@ -111,7 +109,7 @@ XRectangle *rectangles(unsigned int *num)
|
||||
XRectangle r;
|
||||
|
||||
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++) {
|
||||
if (!XGetWindowAttributes(dpy, wins[i], &wa))
|
||||
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);
|
||||
}
|
||||
|
238
cmd/wm/wm.c
238
cmd/wm/wm.c
@ -16,6 +16,8 @@
|
||||
|
||||
#include "wm.h"
|
||||
|
||||
static Draw d = { 0 };
|
||||
static XRectangle initial_rect;
|
||||
static int other_wm_running;
|
||||
static int (*x_error_handler) (Display *, XErrorEvent *);
|
||||
|
||||
@ -110,42 +112,47 @@ scale_rect(XRectangle * from_dim, XRectangle * to_dim,
|
||||
tgt->height = 1;
|
||||
}
|
||||
|
||||
static void draw_pager_page(Page * p, Draw * d)
|
||||
static void draw_pager_frame(void *item)
|
||||
{
|
||||
unsigned int i, j;
|
||||
XRectangle r = d->rect;
|
||||
char name[4];
|
||||
if (p == page[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);
|
||||
Frame *f = (Frame *)item;
|
||||
if (f == cext_get_top_item(&f->area->frames)) {
|
||||
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.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", index_item((void **) page, p));
|
||||
d->data = name;
|
||||
blitz_drawlabel(dpy, d);
|
||||
XSync(dpy, False);
|
||||
d.data = ((Client *)cext_get_top_item(&f->clients))->file[C_NAME]->content;
|
||||
scale_rect(&rect, &initial_rect, &f->area->rect, &d.rect);
|
||||
blitz_drawlabel(dpy, &d);
|
||||
XSync(dpy, False); /* do not clear upwards */
|
||||
}
|
||||
|
||||
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 */
|
||||
}
|
||||
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()
|
||||
@ -153,9 +160,9 @@ static void draw_pager()
|
||||
unsigned int ic, ir, tw, th, rows, cols, size;
|
||||
int i = 0;
|
||||
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 */
|
||||
tw = (rect.width - dx) / cols;
|
||||
th = ((double) tw / rect.width) * rect.height;
|
||||
@ -171,9 +178,9 @@ static void draw_pager()
|
||||
else
|
||||
d.rect.y = ir * (rect.height - th) / (rows - 1);
|
||||
d.rect.height = th;
|
||||
if (!page[i])
|
||||
if (!(p = cext_get_item(&pages, i)))
|
||||
return;
|
||||
draw_pager_page(page[i], &d);
|
||||
draw_pager_page(p);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -185,10 +192,11 @@ static Page *xy_to_pager_page(int x, int y)
|
||||
int i = 0;
|
||||
int dx;
|
||||
XRectangle r;
|
||||
Page *p;
|
||||
|
||||
if (!page)
|
||||
return 0;
|
||||
blitz_getbasegeometry((void **) page, &size, &cols, &rows);
|
||||
if (!cext_sizeof(&pages))
|
||||
return nil;
|
||||
blitz_getbasegeometry(&pages, &size, &cols, &rows);
|
||||
dx = (cols - 1) * GAP; /* GAPpx space */
|
||||
tw = (rect.width - dx) / cols;
|
||||
th = ((double) tw / rect.width) * rect.height;
|
||||
@ -202,14 +210,14 @@ static Page *xy_to_pager_page(int x, int y)
|
||||
else
|
||||
r.y = ir * (rect.height - th) / (rows - 1);
|
||||
r.height = th;
|
||||
if (!page[i])
|
||||
return 0;
|
||||
if (!(p = cext_get_item(&pages, i)))
|
||||
return nil;
|
||||
if (blitz_ispointinrect(x, y, &r))
|
||||
return page[i];
|
||||
return p;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return nil;
|
||||
}
|
||||
|
||||
static int handle_kpress(XKeyEvent * e)
|
||||
@ -231,7 +239,7 @@ static void pager(void *obj, char *cmd)
|
||||
XEvent ev;
|
||||
int i;
|
||||
|
||||
if (!page)
|
||||
if (!cext_sizeof(&pages))
|
||||
return;
|
||||
|
||||
XClearWindow(dpy, transient);
|
||||
@ -253,8 +261,8 @@ static void pager(void *obj, char *cmd)
|
||||
case KeyPress:
|
||||
XUnmapWindow(dpy, transient);
|
||||
if ((i = handle_kpress(&ev.xkey)) != -1)
|
||||
if (i < count_items((void **) page))
|
||||
sel_page(page[i]);
|
||||
if (i < cext_sizeof(&pages))
|
||||
sel_page(cext_get_item(&pages, i));
|
||||
XUngrabKeyboard(dpy, CurrentTime);
|
||||
return;
|
||||
break;
|
||||
@ -276,9 +284,9 @@ static void draw_icons()
|
||||
unsigned int i, ic, ir, tw, th, rows, cols, size;
|
||||
int dx, dy;
|
||||
|
||||
if (!detached)
|
||||
if (!cext_sizeof(&detached))
|
||||
return;
|
||||
blitz_getbasegeometry((void **) detached, &size, &cols, &rows);
|
||||
blitz_getbasegeometry(&detached, &size, &cols, &rows);
|
||||
dx = (cols - 1) * GAP; /* GAPpx space */
|
||||
dy = (rows - 1) * GAP; /* GAPpx space */
|
||||
tw = (rect.width - dx) / cols;
|
||||
@ -289,7 +297,7 @@ static void draw_icons()
|
||||
i = 0;
|
||||
for (ir = 0; ir < rows; ir++) {
|
||||
for (ic = 0; ic < cols; ic++) {
|
||||
Client *c = detached[i++];
|
||||
Client *c = cext_get_item(&detached, i++);
|
||||
XRectangle cr;
|
||||
if (!c)
|
||||
return;
|
||||
@ -313,9 +321,10 @@ static void icons(void *obj, char *cmd)
|
||||
{
|
||||
XEvent ev;
|
||||
int i, n;
|
||||
size_t size = cext_sizeof(&detached);
|
||||
Client *c;
|
||||
|
||||
if (!detached)
|
||||
if (!size)
|
||||
return;
|
||||
|
||||
XClearWindow(dpy, transient);
|
||||
@ -335,16 +344,16 @@ static void icons(void *obj, char *cmd)
|
||||
case KeyPress:
|
||||
XUnmapWindow(dpy, transient);
|
||||
if ((n = handle_kpress(&ev.xkey)) != -1) {
|
||||
for (i = 0; detached && detached[i]; i++)
|
||||
hide_client(detached[i]);
|
||||
for (i = 0; i < size; i++)
|
||||
hide_client(cext_get_item(&detached, i));
|
||||
if (n - 1 < i) {
|
||||
c = detached[n];
|
||||
detached = (Client **) detach_item((void **) detached, c, sizeof(Client *));
|
||||
c = cext_get_item(&detached, n);
|
||||
cext_detach_item(&detached, c);
|
||||
attach_client(c);
|
||||
}
|
||||
} else {
|
||||
for (i = 0; detached && detached[i]; i++)
|
||||
hide_client(detached[i]);
|
||||
for (i = 0; i < size; i++)
|
||||
hide_client(cext_get_item(&detached, i));
|
||||
}
|
||||
XUngrabKeyboard(dpy, CurrentTime);
|
||||
return;
|
||||
@ -352,10 +361,10 @@ static void icons(void *obj, char *cmd)
|
||||
case ButtonPress:
|
||||
if (ev.xbutton.button == Button1) {
|
||||
XUnmapWindow(dpy, transient);
|
||||
for (i = 0; detached && detached[i]; i++)
|
||||
hide_client(detached[i]);
|
||||
for (i = 0; i < size; i++)
|
||||
hide_client(cext_get_item(&detached, i));
|
||||
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);
|
||||
}
|
||||
XUngrabKeyboard(dpy, CurrentTime);
|
||||
@ -368,66 +377,68 @@ static void icons(void *obj, char *cmd)
|
||||
|
||||
static void _close_client(void *obj, char *cmd)
|
||||
{
|
||||
Frame *f = page ? SELFRAME(page[sel]) : 0;
|
||||
if (f->client[f->sel])
|
||||
close_client(f->client[f->sel]);
|
||||
Frame *f = get_sel_frame();
|
||||
if (f)
|
||||
close_client(cext_get_top_item(&f->clients));
|
||||
}
|
||||
|
||||
static void _attach_client(void *obj, char *cmd)
|
||||
{
|
||||
if (detached) {
|
||||
Client *c = detached[0];
|
||||
detached = (Client **) detach_item((void **) detached, c, sizeof(Client *));
|
||||
if (cext_sizeof(&detached)) {
|
||||
Client *c = cext_get_top_item(&detached);
|
||||
cext_detach_item(&detached, c);
|
||||
attach_client(c);
|
||||
}
|
||||
}
|
||||
|
||||
static void _detach_client(void *obj, char *cmd)
|
||||
{
|
||||
Frame *f;
|
||||
if (!page)
|
||||
return;
|
||||
f = SELFRAME(page[sel]);
|
||||
Frame *f = get_sel_frame();
|
||||
if (!f)
|
||||
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)
|
||||
{
|
||||
if (!page || !cmd)
|
||||
Page *p = get_sel_page();
|
||||
if (!p || !cmd)
|
||||
return;
|
||||
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))
|
||||
sel = index_next_item((void **) page, page[sel]);
|
||||
p = cext_get_down_item(&pages, p);
|
||||
else
|
||||
sel = _strtonum(cmd, 0, count_items((void **) page) - 1);
|
||||
sel_page(page[sel]);
|
||||
p = cext_get_item(&pages, _strtonum(cmd, 0, cext_sizeof(&pages) - 1));
|
||||
sel_page(p);
|
||||
}
|
||||
|
||||
static void _destroy_page(void *obj, char *cmd)
|
||||
{
|
||||
if (!page)
|
||||
return;
|
||||
destroy_page(page[sel]);
|
||||
Page *p = get_sel_page();
|
||||
if (p)
|
||||
destroy_page(p);
|
||||
}
|
||||
|
||||
static void new_page(void *obj, char *cmd)
|
||||
{
|
||||
if (page)
|
||||
hide_page(page[sel]);
|
||||
alloc_page("0");
|
||||
Page *p = get_sel_page();
|
||||
if (p)
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; client && client[i]; i++)
|
||||
if (client[i]->win == w)
|
||||
return client[i];
|
||||
return 0;
|
||||
return cext_find_item(&clients, &w, comp_win);
|
||||
}
|
||||
|
||||
void scan_wins()
|
||||
@ -531,18 +542,17 @@ void handle_after_write(IXPServer * s, File * f)
|
||||
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)
|
||||
{
|
||||
int i = 0;
|
||||
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;
|
||||
return cext_find_item(&layouts, name, comp_layout_name);
|
||||
}
|
||||
|
||||
static void init_atoms()
|
||||
@ -667,22 +677,23 @@ static int startup_error_handler(Display * dpy, XErrorEvent * error)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void clean_client_up(void *item)
|
||||
{
|
||||
Client *c = item;
|
||||
Frame *f = c->frame;
|
||||
if (f) {
|
||||
XWindowChanges wc;
|
||||
gravitate(c, tab_height(f), border_width(f), 1);
|
||||
XReparentWindow(dpy, c->win, root, f->rect.x + c->rect.x,
|
||||
f->rect.y + c->rect.y);
|
||||
wc.border_width = c->border;
|
||||
XConfigureWindow(dpy, c->win, CWBorderWidth, &wc);
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup()
|
||||
{
|
||||
int i;
|
||||
XWindowChanges wc;
|
||||
|
||||
for (i = 0; client && client[i]; i++) {
|
||||
Client *c = client[i];
|
||||
Frame *f = c->frame;
|
||||
if (f) {
|
||||
gravitate(c, tab_height(f), border_width(f), 1);
|
||||
XReparentWindow(dpy, c->win, root, f->rect.x + c->rect.x,
|
||||
f->rect.y + c->rect.y);
|
||||
wc.border_width = c->border;
|
||||
XConfigureWindow(dpy, c->win, CWBorderWidth, &wc);
|
||||
}
|
||||
}
|
||||
cext_iterate(&clients, clean_client_up);
|
||||
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
|
||||
}
|
||||
|
||||
@ -697,12 +708,7 @@ static void run()
|
||||
}
|
||||
def[WM_CTL]->after_write = handle_after_write;
|
||||
|
||||
client = 0;
|
||||
frame = 0;
|
||||
detached = 0;
|
||||
page = 0;
|
||||
layouts = 0;
|
||||
sel = 0;
|
||||
clients = frames = detached = pages = layouts = zero_container;
|
||||
|
||||
init_atoms();
|
||||
init_cursors();
|
||||
|
32
cmd/wm/wm.h
32
cmd/wm/wm.h
@ -6,7 +6,6 @@
|
||||
#include <stdio.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include "cext.h"
|
||||
#include "wmii.h"
|
||||
|
||||
/* array indexes of page file pointers */
|
||||
@ -112,8 +111,7 @@ typedef struct Client Client;
|
||||
*/
|
||||
|
||||
struct Page {
|
||||
Area **area;
|
||||
unsigned int sel;
|
||||
Container areas;
|
||||
File *file[P_LAST];
|
||||
};
|
||||
|
||||
@ -130,8 +128,7 @@ struct Layout {
|
||||
struct Area {
|
||||
Layout *layout;
|
||||
Page *page;
|
||||
Frame **frame;
|
||||
unsigned int sel;
|
||||
Container frames;
|
||||
XRectangle rect;
|
||||
void *aux; /* free pointer */
|
||||
File *file[A_LAST];
|
||||
@ -139,12 +136,11 @@ struct Area {
|
||||
|
||||
struct Frame {
|
||||
Area *area;
|
||||
Container clients;
|
||||
Window win;
|
||||
GC gc;
|
||||
XRectangle rect;
|
||||
Cursor cursor;
|
||||
Client **client;
|
||||
int sel;
|
||||
void *aux; /* free pointer */
|
||||
File *file[F_LAST];
|
||||
};
|
||||
@ -161,9 +157,6 @@ struct Client {
|
||||
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 */
|
||||
Display *dpy;
|
||||
@ -172,16 +165,16 @@ int screen_num;
|
||||
Window root;
|
||||
Window transient;
|
||||
XRectangle rect;
|
||||
Client **detached;
|
||||
Page **page;
|
||||
unsigned int sel;
|
||||
Frame **frame;
|
||||
Client **client;
|
||||
Container detached;
|
||||
Container pages;
|
||||
Container frames;
|
||||
Container clients;
|
||||
Container layouts;
|
||||
static Container zero_container = { 0 };
|
||||
XFontStruct *font;
|
||||
XColor xorcolor;
|
||||
GC xorgc;
|
||||
GC transient_gc;
|
||||
Layout **layouts;
|
||||
|
||||
Atom wm_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 hide_area(Area * a);
|
||||
void show_area(Area * a);
|
||||
Area *get_sel_area();
|
||||
|
||||
/* client.c */
|
||||
Client *alloc_client(Window w);
|
||||
@ -225,7 +219,7 @@ void destroy_client(Client * c);
|
||||
void configure_client(Client * c);
|
||||
void handle_client_property(Client * c, XPropertyEvent * e);
|
||||
void close_client(Client * c);
|
||||
void draw_client(Client * c);
|
||||
void draw_client(void *item);
|
||||
void draw_clients(Frame * f);
|
||||
void gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert);
|
||||
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 attach_client(Client *c);
|
||||
void detach_client(Client *c);
|
||||
Client *get_sel_client();
|
||||
|
||||
/* frame.c */
|
||||
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);
|
||||
unsigned int tab_height(Frame * f);
|
||||
unsigned int border_width(Frame * f);
|
||||
Frame *get_sel_frame();
|
||||
Frame *get_sel_frame_of_area(Area *a);
|
||||
|
||||
/* event.c */
|
||||
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);
|
||||
|
||||
/* page.c */
|
||||
Page *get_sel_page();
|
||||
Page *alloc_page();
|
||||
void free_page(Page * p);
|
||||
void destroy_page(Page * p);
|
||||
|
12
cmd/wmibar.c
12
cmd/wmibar.c
@ -16,8 +16,6 @@
|
||||
|
||||
#include "wmii.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
/* array indexes for file pointers */
|
||||
typedef enum {
|
||||
B_CTL,
|
||||
@ -290,17 +288,15 @@ static void draw_bar(void *obj, char *arg)
|
||||
n = 0;
|
||||
for (f = label; f; f = f->next)
|
||||
n++;
|
||||
paths = emalloc(sizeof(char *) * n);
|
||||
paths = cext_emalloc(sizeof(char *) * n);
|
||||
i = 0;
|
||||
for (f = label; f; f = f->next)
|
||||
paths[i++] = f->name;
|
||||
qsort(paths, n, sizeof(char *), comp_str);
|
||||
for (i = 0; i < n; i++) {
|
||||
snprintf(buf, sizeof(buf), "/%s", paths[i]);
|
||||
item = emalloc(sizeof(Item));
|
||||
items =
|
||||
(Item **) attach_item_end((void **) items, item,
|
||||
sizeof(Item *));
|
||||
item = cext_emalloc(sizeof(Item));
|
||||
items = (Item **) attach_item_end((void **) items, item, sizeof(Item *));
|
||||
init_item(buf, item);
|
||||
}
|
||||
draw();
|
||||
@ -533,7 +529,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
geom[0] = '\0';
|
||||
if (argc > i)
|
||||
_strlcpy(geom, argv[i], sizeof(geom));
|
||||
cext_strlcpy(geom, argv[i], sizeof(geom));
|
||||
|
||||
ixps = wmii_setup_server(sockfile);
|
||||
run(geom);
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "../libixp2/ixp.h"
|
||||
#include "blitz.h"
|
||||
#include "cext.h"
|
||||
|
||||
/*
|
||||
* filesystem specification
|
||||
@ -193,7 +192,7 @@ static int make_qid(Qid * dir, char *wname, Qid * new)
|
||||
return TRUE;
|
||||
}
|
||||
/* 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)
|
||||
return FALSE;
|
||||
/* found */
|
||||
@ -208,7 +207,7 @@ static int make_qid(Qid * dir, char *wname, Qid * new)
|
||||
|
||||
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,
|
||||
s->fcall.aname);
|
||||
map->qid = root_qid;
|
||||
@ -257,7 +256,7 @@ static int walk(IXPServer * s, IXPConn * c)
|
||||
(Map **) detach_item((void **) c->aux, map, sizeof(Map *));
|
||||
free(map);
|
||||
}
|
||||
map = emalloc(sizeof(Map));
|
||||
map = cext_emalloc(sizeof(Map));
|
||||
map->qid = qid;
|
||||
map->fid = s->fcall.newfid;
|
||||
c->aux =
|
||||
@ -302,28 +301,28 @@ static int _read(IXPServer * s, IXPConn * c)
|
||||
}
|
||||
stat.mode = 0xff;
|
||||
stat.atime = stat.mtime = time(0);
|
||||
_strlcpy(stat.uid, getenv("USER"), sizeof(stat.uid));
|
||||
_strlcpy(stat.gid, getenv("USER"), sizeof(stat.gid));
|
||||
_strlcpy(stat.muid, getenv("USER"), sizeof(stat.muid));
|
||||
cext_strlcpy(stat.uid, getenv("USER"), sizeof(stat.uid));
|
||||
cext_strlcpy(stat.gid, getenv("USER"), sizeof(stat.gid));
|
||||
cext_strlcpy(stat.muid, getenv("USER"), sizeof(stat.muid));
|
||||
|
||||
fprintf(stderr, "%d\n", qpath_item(map->qid.path));
|
||||
switch (qpath_type(map->qid.path)) {
|
||||
default:
|
||||
case Droot:
|
||||
p = s->fcall.data;
|
||||
_strlcpy(stat.name, "display", sizeof(stat.name));
|
||||
cext_strlcpy(stat.name, "display", sizeof(stat.name));
|
||||
stat.length = strlen(align);
|
||||
make_qid(&root_qid, "display", &stat.qid);
|
||||
stat.size = ixp_sizeof_stat(&stat);
|
||||
s->fcall.count = stat.size;
|
||||
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);
|
||||
make_qid(&root_qid, "font", &stat.qid);
|
||||
stat.size = ixp_sizeof_stat(&stat);;
|
||||
s->fcall.count += stat.size;
|
||||
p = ixp_enc_stat(p, &stat);
|
||||
_strlcpy(stat.name, "new", sizeof(stat.name));
|
||||
cext_strlcpy(stat.name, "new", sizeof(stat.name));
|
||||
stat.length = 0;
|
||||
make_qid(&root_qid, "new", &stat.qid);
|
||||
stat.size = ixp_sizeof_stat(&stat);;
|
||||
@ -438,7 +437,7 @@ int main(int argc, char *argv[])
|
||||
atexit(exit_cleanup);
|
||||
|
||||
/* default item settings */
|
||||
item = emalloc(sizeof(Item));
|
||||
item = cext_emalloc(sizeof(Item));
|
||||
item->id = 0;
|
||||
item->text[0] = '\0';
|
||||
item->value = 0;
|
||||
|
@ -9,8 +9,6 @@
|
||||
|
||||
#include "wmii.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
/* array indexes for file pointers */
|
||||
typedef enum {
|
||||
F_CTL,
|
||||
@ -121,7 +119,7 @@ static void bind(void *obj, char *arg)
|
||||
|
||||
if (!arg)
|
||||
return;
|
||||
_strlcpy(cmd, arg, sizeof(cmd));
|
||||
cext_strlcpy(cmd, arg, sizeof(cmd));
|
||||
sfile = strchr(cmd, ' ');
|
||||
if (!sfile) {
|
||||
fprintf(stderr,
|
||||
@ -137,7 +135,7 @@ static void bind(void *obj, char *arg)
|
||||
arg);
|
||||
return; /* shortcut with empty argument */
|
||||
}
|
||||
b = emalloc(sizeof(Bind));
|
||||
b = cext_emalloc(sizeof(Bind));
|
||||
*b = zero_bind;
|
||||
|
||||
b->client = init_ixp_client(sfile);
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
#include "wmii.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
/* array indexes for file pointers */
|
||||
typedef enum {
|
||||
K_CTL,
|
||||
@ -123,18 +121,18 @@ static void create_shortcut(File * f)
|
||||
size_t i, toks;
|
||||
Shortcut *s = 0, *r = 0;
|
||||
|
||||
_strlcpy(buf, f->name, sizeof(buf));
|
||||
toks = tokenize(chain, 8, buf, ',');
|
||||
cext_strlcpy(buf, f->name, sizeof(buf));
|
||||
toks = cext_tokenize(chain, 8, buf, ',');
|
||||
|
||||
for (i = 0; i < toks; i++) {
|
||||
if (!s)
|
||||
r = s = emalloc(sizeof(Shortcut));
|
||||
r = s = cext_emalloc(sizeof(Shortcut));
|
||||
else {
|
||||
s->next = emalloc(sizeof(Shortcut));
|
||||
s->next = cext_emalloc(sizeof(Shortcut));
|
||||
s = s->next;
|
||||
}
|
||||
*s = zero_shortcut;
|
||||
_strlcpy(s->name, chain[i], MAX_BUF);
|
||||
cext_strlcpy(s->name, chain[i], MAX_BUF);
|
||||
k = strrchr(chain[i], '-');
|
||||
if (k)
|
||||
k++;
|
||||
@ -492,7 +490,7 @@ int main(int argc, char *argv[])
|
||||
screen_num = DefaultScreen(dpy);
|
||||
size[0] = '\0';
|
||||
if (argc > i)
|
||||
_strlcpy(size, argv[i], sizeof(size));
|
||||
cext_strlcpy(size, argv[i], sizeof(size));
|
||||
|
||||
ixps = wmii_setup_server(sockfile);
|
||||
|
||||
|
@ -18,8 +18,6 @@
|
||||
|
||||
#include "wmii.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
/* array indexes for file pointers */
|
||||
typedef enum {
|
||||
M_CTL,
|
||||
@ -113,7 +111,7 @@ static void _exec(char *cmd)
|
||||
add_history(cmd);
|
||||
if (files[M_PRE_COMMAND]->content) {
|
||||
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,
|
||||
cmd);
|
||||
}
|
||||
@ -242,7 +240,7 @@ static int update_items(char *pattern)
|
||||
items = 0;
|
||||
item_size = size;
|
||||
if (item_size)
|
||||
items = (File **) emalloc((item_size + 1) * sizeof(File *));
|
||||
items = (File **) cext_emalloc((item_size + 1) * sizeof(File *));
|
||||
}
|
||||
size = 0;
|
||||
|
||||
@ -354,7 +352,7 @@ static void handle_kpress(XKeyEvent * e)
|
||||
|
||||
text[0] = '\0';
|
||||
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);
|
||||
}
|
||||
buf[0] = '\0';
|
||||
@ -462,9 +460,9 @@ static void handle_kpress(XKeyEvent * e)
|
||||
if ((num == 1) && !iscntrl((int) buf[0])) {
|
||||
buf[num] = '\0';
|
||||
if (len > 0)
|
||||
_strlcat(text, buf, sizeof(text));
|
||||
cext_strlcat(text, buf, sizeof(text));
|
||||
else
|
||||
_strlcpy(text, buf, sizeof(text));
|
||||
cext_strlcpy(text, buf, sizeof(text));
|
||||
set_text(text);
|
||||
update_items(files[M_COMMAND]->content);
|
||||
}
|
||||
@ -653,7 +651,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
size[0] = '\0';
|
||||
if (argc > i)
|
||||
_strlcpy(size, argv[i], sizeof(size));
|
||||
cext_strlcpy(size, argv[i], sizeof(size));
|
||||
|
||||
ixps = wmii_setup_server(sockfile);
|
||||
items = 0;
|
||||
|
@ -229,7 +229,7 @@ int main(int argc, char *argv[])
|
||||
char *_argv[3];
|
||||
int _argc;
|
||||
while (fgets(line, 4096, stdin))
|
||||
if ((_argc = tokenize(_argv, 3, line, ' '))) {
|
||||
if ((_argc = cext_tokenize(_argv, 3, line, ' '))) {
|
||||
if ((ret = perform_cmd(_argc, _argv)))
|
||||
break;
|
||||
}
|
||||
|
@ -35,10 +35,12 @@ void cext_attach_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_top_item(Container *c, void *item);
|
||||
void cext_iterate(Container *c, void (*doit)(void *));
|
||||
void *cext_get_top_item(Container *c);
|
||||
void *cext_get_down_item(Container *c, void *item);
|
||||
void *cext_get_up_item(Container *c, void *item);
|
||||
void *cext_get_item(Container *c, size_t index);
|
||||
int cext_get_item_index(Container *c, void *item);
|
||||
size_t cext_sizeof(Container *c);
|
||||
|
||||
void **attach_item_begin(void **old, void *item, size_t size_item);
|
||||
|
@ -76,6 +76,12 @@ void *cext_find_item(Container *c, void *pattern, int (*comp)(void *pattern, voi
|
||||
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)
|
||||
{
|
||||
@ -121,6 +127,17 @@ void *cext_get_item(Container *c, size_t index)
|
||||
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 idx = 0;
|
||||
|
@ -117,7 +117,7 @@ static void *poll_server(IXPClient * c, void *request, size_t req_len,
|
||||
handle_dead_server(c);
|
||||
return 0;
|
||||
}
|
||||
result = emalloc(*out_len);
|
||||
result = cext_emalloc(*out_len);
|
||||
header = 1;
|
||||
}
|
||||
r = read(c->fd, ((char *) result) + num, *out_len - num);
|
||||
@ -256,7 +256,7 @@ IXPClient *init_ixp_client(char *sockfile)
|
||||
socklen_t su_len;
|
||||
|
||||
/* init */
|
||||
IXPClient *c = (IXPClient *) emalloc(sizeof(IXPClient));
|
||||
IXPClient *c = (IXPClient *) cext_emalloc(sizeof(IXPClient));
|
||||
*c = zero_client;
|
||||
c->create = cixp_create;
|
||||
c->open = cixp_open;
|
||||
|
@ -17,7 +17,7 @@ void *tcreate_message(char *path, size_t * msg_len)
|
||||
char *msg;
|
||||
ReqHeader h;
|
||||
*msg_len = sizeof(ReqHeader) + strlen(path) + 1;
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.req = TCREATE;
|
||||
memcpy(msg, &h, sizeof(ReqHeader));
|
||||
memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1);
|
||||
@ -29,7 +29,7 @@ void *topen_message(char *path, size_t * msg_len)
|
||||
char *msg;
|
||||
ReqHeader h;
|
||||
*msg_len = sizeof(ReqHeader) + strlen(path) + 1;
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.req = TOPEN;
|
||||
memcpy(msg, &h, sizeof(ReqHeader));
|
||||
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;
|
||||
ReqHeader h;
|
||||
*msg_len = sizeof(ReqHeader);
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.req = TREAD;
|
||||
h.fd = fd;
|
||||
h.offset = offset;
|
||||
@ -57,7 +57,7 @@ void *twrite_message(int fd, size_t offset, void *content,
|
||||
char *msg;
|
||||
ReqHeader h;
|
||||
*msg_len = sizeof(ReqHeader) + content_len;
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.req = TWRITE;
|
||||
h.fd = fd;
|
||||
h.offset = offset;
|
||||
@ -72,7 +72,7 @@ void *tclose_message(int fd, size_t * msg_len)
|
||||
char *msg;
|
||||
ReqHeader h;
|
||||
*msg_len = sizeof(ReqHeader);
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.req = TCLUNK;
|
||||
h.fd = fd;
|
||||
memcpy(msg, &h, sizeof(ReqHeader));
|
||||
@ -84,7 +84,7 @@ void *tremove_message(char *path, size_t * msg_len)
|
||||
char *msg;
|
||||
ReqHeader h;
|
||||
*msg_len = sizeof(ReqHeader) + strlen(path) + 1;
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.req = TREMOVE;
|
||||
memcpy(msg, &h, sizeof(ReqHeader));
|
||||
memcpy(msg + sizeof(ReqHeader), path, strlen(path) + 1);
|
||||
@ -98,7 +98,7 @@ void *rcreate_message(size_t * msg_len)
|
||||
char *msg;
|
||||
ResHeader h;
|
||||
*msg_len = sizeof(ResHeader);
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.res = RCREATE;
|
||||
memcpy(msg, &h, sizeof(ResHeader));
|
||||
return msg;
|
||||
@ -109,7 +109,7 @@ void *ropen_message(int fd, size_t * msg_len)
|
||||
char *msg;
|
||||
ResHeader h;
|
||||
*msg_len = sizeof(ResHeader);
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.res = ROPEN;
|
||||
h.fd = fd;
|
||||
memcpy(msg, &h, sizeof(ResHeader));
|
||||
@ -121,7 +121,7 @@ void *rread_message(void *content, size_t content_len, size_t * msg_len)
|
||||
char *msg;
|
||||
ResHeader h;
|
||||
*msg_len = sizeof(ResHeader) + content_len;
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.res = RREAD;
|
||||
h.buf_len = content_len;
|
||||
memcpy(msg, &h, sizeof(ResHeader));
|
||||
@ -134,7 +134,7 @@ void *rwrite_message(size_t * msg_len)
|
||||
char *msg;
|
||||
ResHeader h;
|
||||
*msg_len = sizeof(ResHeader);
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.res = RWRITE;
|
||||
memcpy(msg, &h, sizeof(ResHeader));
|
||||
return msg;
|
||||
@ -145,7 +145,7 @@ void *rclose_message(size_t * msg_len)
|
||||
char *msg;
|
||||
ResHeader h;
|
||||
*msg_len = sizeof(ResHeader);
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.res = RCLUNK;
|
||||
memcpy(msg, &h, sizeof(ResHeader));
|
||||
return msg;
|
||||
@ -156,7 +156,7 @@ void *rremove_message(size_t * msg_len)
|
||||
char *msg;
|
||||
ResHeader h;
|
||||
*msg_len = sizeof(ResHeader);
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.res = RREMOVE;
|
||||
memcpy(msg, &h, sizeof(ResHeader));
|
||||
return msg;
|
||||
@ -168,7 +168,7 @@ void *rerror_message(char *errstr, size_t * msg_len)
|
||||
size_t len = strlen(errstr) + 1;
|
||||
ResHeader h;
|
||||
*msg_len = sizeof(ResHeader) + len;
|
||||
msg = emalloc(*msg_len);
|
||||
msg = cext_emalloc(*msg_len);
|
||||
h.res = RERROR;
|
||||
memcpy(msg, &h, sizeof(ResHeader));
|
||||
memmove(msg + sizeof(ResHeader), errstr, len);
|
||||
|
@ -53,7 +53,7 @@ File *ixp_create(IXPServer * s, char *path)
|
||||
}
|
||||
/* only create missing parts, if file is directory */
|
||||
while (tok) {
|
||||
f = (File *) emalloc(sizeof(File));
|
||||
f = (File *) cext_emalloc(sizeof(File));
|
||||
*f = zero_file;
|
||||
f->name = strdup(tok);
|
||||
f->parent = p;
|
||||
@ -90,7 +90,7 @@ static char *_ls(File * f)
|
||||
|
||||
for (p = f; p; p = p->next)
|
||||
num++;
|
||||
tmp = emalloc(sizeof(File *) * num);
|
||||
tmp = cext_emalloc(sizeof(File *) * num);
|
||||
i = 0;
|
||||
for (p = f; p; p = p->next) {
|
||||
size += strlen(p->name) + 1;
|
||||
@ -99,7 +99,7 @@ static char *_ls(File * f)
|
||||
tmp[i++] = p;
|
||||
}
|
||||
qsort(tmp, num, sizeof(char *), comp_file_name);
|
||||
result = emalloc(size);
|
||||
result = cext_emalloc(size);
|
||||
result[0] = '\0';
|
||||
for (i = 0; i < num; i++) {
|
||||
strncat(result, tmp[i]->name, size);
|
||||
|
@ -81,7 +81,7 @@ static void handle_ixp_read(Connection * c, ReqHeader * h)
|
||||
void *data = 0;
|
||||
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);
|
||||
free(c->data);
|
||||
if (c->s->errstr) {
|
||||
@ -219,7 +219,7 @@ static void read_conn(Connection * c)
|
||||
return;
|
||||
}
|
||||
c->remain = c->len;
|
||||
c->data = emalloc(c->len);
|
||||
c->data = cext_emalloc(c->len);
|
||||
c->header = 1;
|
||||
}
|
||||
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;
|
||||
|
||||
/* init */
|
||||
s = (IXPServer *) emalloc(sizeof(IXPServer));
|
||||
s = (IXPServer *) cext_emalloc(sizeof(IXPServer));
|
||||
*s = zero_server;
|
||||
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->create = ixp_create;
|
||||
s->remove = ixp_remove;
|
||||
|
@ -44,7 +44,7 @@ int ixp_client_init(IXPClient * c, char *sockfile)
|
||||
c->fcall.id = TVERSION;
|
||||
c->fcall.tag = IXP_NOTAG;
|
||||
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)) {
|
||||
ixp_client_deinit(c);
|
||||
return FALSE;
|
||||
@ -61,7 +61,7 @@ int ixp_client_init(IXPClient * c, char *sockfile)
|
||||
c->fcall.tag = IXP_NOTAG;
|
||||
c->fcall.fid = c->root_fid;
|
||||
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';
|
||||
if (!do_fcall(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.tag = IXP_NOTAG;
|
||||
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.mode = mode;
|
||||
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.newfid = newfid;
|
||||
if (filepath) {
|
||||
_strlcpy(c->fcall.name, filepath, sizeof(c->fcall.name));
|
||||
c->fcall.nwname =
|
||||
tokenize((char **) c->fcall.wname, IXP_MAX_WELEM,
|
||||
c->fcall.name, '/');
|
||||
cext_strlcpy(c->fcall.name, filepath, sizeof(c->fcall.name));
|
||||
c->fcall.nwname = cext_tokenize((char **) c->fcall.wname, IXP_MAX_WELEM, c->fcall.name, '/');
|
||||
}
|
||||
return do_fcall(c);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ static void server_client_read(IXPServer * s, IXPConn * c)
|
||||
if (!s->errstr)
|
||||
s->errstr = "function not supported";
|
||||
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);
|
||||
if (ixp_send_message(c->fd, msg, msize, &s->errstr) != msize)
|
||||
ixp_server_rm_conn(s, c);
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <cext.h>
|
||||
|
||||
#define BLITZ_FONT "fixed"
|
||||
#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_ispointinrect(int x, int y, XRectangle * r);
|
||||
int blitz_distance(XRectangle * origin, XRectangle * target);
|
||||
void
|
||||
blitz_getbasegeometry(void **items, unsigned int *size,
|
||||
unsigned int *cols, unsigned int *rows);
|
||||
void blitz_getbasegeometry(Container *c, unsigned int *size, unsigned int *cols, unsigned int *rows);
|
||||
|
||||
/* mouse.c */
|
||||
char *blitz_buttontostr(unsigned int button);
|
||||
|
@ -7,8 +7,6 @@
|
||||
#include <string.h>
|
||||
#include "blitz.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
XFontStruct *blitz_getfont(Display * dpy, char *fontstr)
|
||||
{
|
||||
XFontStruct *font;
|
||||
@ -28,7 +26,7 @@ unsigned long blitz_loadcolor(Display * dpy, int mon, char *colstr)
|
||||
XColor color;
|
||||
char col[8];
|
||||
|
||||
_strlcpy(col, colstr, sizeof(col));
|
||||
cext_strlcpy(col, colstr, sizeof(col));
|
||||
col[7] = '\0';
|
||||
XAllocNamedColor(dpy, DefaultColormap(dpy, mon), col, &color, &color);
|
||||
return color.pixel;
|
||||
@ -87,7 +85,7 @@ static void draw_text(Display * dpy, Draw * d)
|
||||
return;
|
||||
|
||||
len = strlen(d->data);
|
||||
_strlcpy(text, d->data, sizeof(text));
|
||||
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;
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "blitz.h"
|
||||
#include <cext.h>
|
||||
|
||||
static int strtoalign(Align * result, char *val)
|
||||
{
|
||||
@ -57,7 +56,7 @@ int blitz_strtorect(XRectangle * root, XRectangle * r, char *val)
|
||||
return FALSE;
|
||||
sx = sy = sw = sh = 0;
|
||||
x = y = w = h = 0;
|
||||
_strlcpy(buf, val, sizeof(buf));
|
||||
cext_strlcpy(buf, val, sizeof(buf));
|
||||
|
||||
x = strtok_r(buf, ",", &p);
|
||||
if (x) {
|
||||
@ -201,13 +200,11 @@ int blitz_distance(XRectangle * origin, XRectangle * target)
|
||||
((oy - ty) * (oy - ty))));
|
||||
}
|
||||
|
||||
void
|
||||
blitz_getbasegeometry(void **items, unsigned int *size,
|
||||
unsigned int *cols, unsigned int *rows)
|
||||
void blitz_getbasegeometry(Container *c, unsigned int *size, unsigned int *cols, unsigned int *rows)
|
||||
{
|
||||
float sq, dummy;
|
||||
|
||||
*size = count_items((void **) items);
|
||||
*size = cext_sizeof(c);
|
||||
sq = sqrt(*size);
|
||||
if (modff(sq, &dummy) < 0.5)
|
||||
*rows = floor(sq);
|
||||
|
18
liblitz/kb.c
18
liblitz/kb.c
@ -7,8 +7,6 @@
|
||||
|
||||
#include "blitz.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
/* free the result manually! */
|
||||
char *blitz_modtostr(unsigned long mod)
|
||||
{
|
||||
@ -16,20 +14,20 @@ char *blitz_modtostr(unsigned long mod)
|
||||
result[0] = '\0';
|
||||
|
||||
if (mod & ShiftMask)
|
||||
_strlcat(result, "S-", sizeof(result));
|
||||
cext_strlcat(result, "S-", sizeof(result));
|
||||
if (mod & ControlMask)
|
||||
_strlcat(result, "C-", sizeof(result));
|
||||
cext_strlcat(result, "C-", sizeof(result));
|
||||
if (mod & Mod1Mask)
|
||||
_strlcat(result, "M-", sizeof(result));
|
||||
cext_strlcat(result, "M-", sizeof(result));
|
||||
if (mod & Mod2Mask)
|
||||
_strlcat(result, "M2-", sizeof(result));
|
||||
cext_strlcat(result, "M2-", sizeof(result));
|
||||
if (mod & Mod3Mask)
|
||||
_strlcat(result, "M3-", sizeof(result));
|
||||
cext_strlcat(result, "M3-", sizeof(result));
|
||||
if (mod & Mod4Mask)
|
||||
_strlcat(result, "WIN-", sizeof(result));
|
||||
cext_strlcat(result, "WIN-", sizeof(result));
|
||||
if (mod & Mod5Mask)
|
||||
_strlcat(result, "M5-", sizeof(result));
|
||||
return estrdup(result);
|
||||
cext_strlcat(result, "M5-", sizeof(result));
|
||||
return cext_estrdup(result);
|
||||
}
|
||||
|
||||
unsigned long blitz_strtomod(char *val)
|
||||
|
@ -9,15 +9,13 @@
|
||||
|
||||
#include "blitz.h"
|
||||
|
||||
#include <cext.h>
|
||||
|
||||
/* free the result manually! */
|
||||
char *blitz_buttontostr(unsigned int button)
|
||||
{
|
||||
char result[8];
|
||||
result[0] = '\0';
|
||||
snprintf(result, 8, "Button%ud", button - Button1);
|
||||
return estrdup(result);
|
||||
return cext_estrdup(result);
|
||||
}
|
||||
|
||||
unsigned int blitz_strtobutton(char *val)
|
||||
|
@ -5,16 +5,13 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "cext.h"
|
||||
#include "blitz.h"
|
||||
|
||||
long long _strtonum(const char *numstr, long long minval, long long maxval)
|
||||
{
|
||||
const char *errstr;
|
||||
long long ret = __strtonum(numstr, minval, maxval, &errstr);
|
||||
long long ret = cext_strtonum(numstr, minval, maxval, &errstr);
|
||||
if (errstr)
|
||||
fprintf(stderr,
|
||||
"liblitz: cannot convert '%s' into integer: %s\n",
|
||||
numstr, errstr);
|
||||
fprintf(stderr, "liblitz: cannot convert '%s' into integer: %s\n", numstr, errstr);
|
||||
return ret;
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
static pid_t mypid;
|
||||
static char *mysockfile;
|
||||
|
||||
/* convenience stuff ----------------------------------------------- */
|
||||
|
||||
File *wmii_create_ixpfile(IXPServer * s, char *key, char *val)
|
||||
{
|
||||
File *f = ixp_create(s, key);
|
||||
@ -38,10 +36,10 @@ void wmii_get_ixppath(File * f, char *path, size_t size)
|
||||
|
||||
buf[0] = '\0';
|
||||
if (path)
|
||||
_strlcpy(buf, path, sizeof(buf));
|
||||
cext_strlcpy(buf, path, sizeof(buf));
|
||||
snprintf(path, size, "%s/", f->name);
|
||||
if (buf[0] != '\0')
|
||||
_strlcat(path, buf, size);
|
||||
cext_strlcat(path, buf, size);
|
||||
if (f->parent)
|
||||
wmii_get_ixppath(f->parent, path, size);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ void win_prop(Display * dpy, Window w, Atom a, char *res, int len)
|
||||
unsigned char *prop;
|
||||
|
||||
if (property(dpy, w, a, XA_STRING, 100L, &prop)) {
|
||||
_strlcpy(res, (char *) prop, len);
|
||||
cext_strlcpy(res, (char *) prop, len);
|
||||
XFree(prop);
|
||||
}
|
||||
res[len - 1] = '\0';
|
||||
|
Loading…
Reference in New Issue
Block a user