code cleanups

This commit is contained in:
Anselm R. Garbe 2006-04-13 16:52:33 +02:00
parent a126bbafb1
commit f750cd9813
6 changed files with 72 additions and 64 deletions

View File

@ -9,7 +9,7 @@
#include "wm.h"
static int
comp_label_intern(const void *l1, const void *l2)
comp_bar_intern(const void *l1, const void *l2)
{
Bar *ll1 = *(Bar **)l1;
Bar *ll2 = *(Bar **)l2;
@ -21,7 +21,7 @@ comp_label_intern(const void *l1, const void *l2)
}
static int
comp_label_name(const void *l1, const void *l2)
comp_bar_name(const void *l1, const void *l2)
{
Bar *ll1 = *(Bar **)l1;
Bar *ll2 = *(Bar **)l2;
@ -48,17 +48,16 @@ create_bar(char *name, Bool intern)
cext_strlcpy(l->name, name, sizeof(l->name));
cext_strlcpy(l->colstr, def.selcolor, sizeof(l->colstr));
l->color = def.sel;
cext_vattach(vector_of_bars(&label), l);
qsort(label.data, label.size, sizeof(Bar *), comp_label_name);
qsort(label.data, label.size, sizeof(Bar *), comp_label_intern);
cext_vattach(vector_of_bars(&bar), l);
qsort(bar.data, bar.size, sizeof(Bar *), comp_bar_name);
qsort(bar.data, bar.size, sizeof(Bar *), comp_bar_intern);
return l;
}
void
destroy_bar(Bar *l)
{
cext_vdetach(vector_of_bars(&label), l);
cext_vdetach(vector_of_bars(&bar), l);
}
unsigned int
@ -113,11 +112,11 @@ draw_bar()
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
if(!label.size)
if(!bar.size)
return;
for(i = 0; (i < label.size) && (w < brect.width); i++) {
l = label.data[i];
for(i = 0; (i < bar.size) && (w < brect.width); i++) {
l = bar.data[i];
if(l->intern) {
if(view.size && !strncmp(l->name, view.data[sel]->name, sizeof(l->name)))
l->color = def.sel;
@ -133,26 +132,26 @@ draw_bar()
w += l->rect.width;
}
if(i != label.size) { /* give all labels same width */
w = brect.width / label.size;
for(i = 0; i < label.size; i++) {
l = label.data[i];
if(i != bar.size) { /* give all bars same width */
w = brect.width / bar.size;
for(i = 0; i < bar.size; i++) {
l = bar.data[i];
l->rect.x = i * w;
l->rect.width = w;
}
}
else { /* expand label properly */
for(exp = 0; (exp < label.size) && (label.data[exp]->intern); exp++);
if(exp == label.size)
else { /* expand bar properly */
for(exp = 0; (exp < bar.size) && (bar.data[exp]->intern); exp++);
if(exp == bar.size)
exp = -1;
else
label.data[exp]->rect.width += (brect.width - w);
for(i = 1; i < label.size; i++)
label.data[i]->rect.x = label.data[i - 1]->rect.x + label.data[i - 1]->rect.width;
bar.data[exp]->rect.width += (brect.width - w);
for(i = 1; i < bar.size; i++)
bar.data[i]->rect.x = bar.data[i - 1]->rect.x + bar.data[i - 1]->rect.width;
}
for(i = 0; i < label.size; i++) {
l = label.data[i];
for(i = 0; i < bar.size; i++) {
l = bar.data[i];
d.color = l->color;
d.rect = l->rect;
d.data = l->data;
@ -171,8 +170,8 @@ int
idx_of_bar(Bar *l)
{
int i;
for(i = 0; i < label.size; i++)
if(label.data[i] == l)
for(i = 0; i < bar.size; i++)
if(bar.data[i] == l)
return i;
return -1;
}
@ -181,8 +180,8 @@ int
idx_of_bar_id(unsigned short id)
{
int i;
for(i = 0; i < label.size; i++)
if(label.data[i]->id == id)
for(i = 0; i < bar.size; i++)
if(bar.data[i]->id == id)
return i;
return -1;
}
@ -194,9 +193,9 @@ bar_of_name(const char *name)
unsigned int i;
cext_strlcpy(buf, name, sizeof(buf));
for(i = 0; i < label.size; i++)
if(!strncmp(label.data[i]->name, name, sizeof(label.data[i]->name)))
return label.data[i];
for(i = 0; i < bar.size; i++)
if(!strncmp(bar.data[i]->name, name, sizeof(bar.data[i]->name)))
return bar.data[i];
return nil;
}
@ -206,8 +205,8 @@ update_view_bars()
unsigned int i;
Bar *l = nil;
for(i = 0; (i < label.size) && label.data[i]->intern; i++) {
l = label.data[i];
for(i = 0; (i < bar.size) && bar.data[i]->intern; i++) {
l = bar.data[i];
if(!view_of_name(l->name)) {
destroy_bar(l);
i--;

View File

@ -60,10 +60,10 @@ handle_buttonpress(XEvent *e)
static char buf[32];
if(ev->window == barwin) {
unsigned int i;
for(i = 0; i < label.size; i++)
if(blitz_ispointinrect(ev->x, ev->y, &label.data[i]->rect)) {
for(i = 0; i < bar.size; i++)
if(blitz_ispointinrect(ev->x, ev->y, &bar.data[i]->rect)) {
snprintf(buf, sizeof(buf), "BarClick %s %d\n",
label.data[i]->name, ev->button);
bar.data[i]->name, ev->button);
write_event(buf);
return;
}

View File

@ -71,7 +71,7 @@ const char *err;
/*
* Qid->path is calculated related to the index of the associated structure.
* i1 is associated to tag, key, global client, or label
* i1 is associated to tag, key, global client, or bar
* i2 is associated to area
* i3 is associated to client
* ie /view/sel/ctl is i1id = sel tag id, i2id = sel area id , i3id = 0 (no id)
@ -158,7 +158,7 @@ qid2name(Qid *qid)
case FsDbar:
if(i1 == -1)
return nil;
return label.data[i1]->name;
return bar.data[i1]->name;
break;
case FsDarea:
if(i1 == -1 || i2 == -1)
@ -526,7 +526,7 @@ type2stat(Stat *stat, char *wname, Qid *dir)
return mkstat(stat, dir, wname, strlen(client.data[dir_i1]->tags), IXP_DMREAD | IXP_DMWRITE);
break;
case FsFdata:
return mkstat(stat, dir, wname, (dir_i1 == label.size) ? 0 : strlen(label.data[dir_i1]->data),
return mkstat(stat, dir, wname, (dir_i1 == bar.size) ? 0 : strlen(bar.data[dir_i1]->data),
IXP_DMREAD | IXP_DMWRITE);
break;
case FsFmode:
@ -679,10 +679,10 @@ xremove(IXPConn *c, Fcall *fcall)
switch(type) {
case FsDbar:
{
Bar *l = label.data[i1];
Bar *l = bar.data[i1];
if(l->intern)
return Enoperm;
/* now detach the label */
/* now detach the bar */
destroy_bar(l);
free(l);
draw_bar();
@ -765,15 +765,15 @@ xread(IXPConn *c, Fcall *fcall)
case FsDbars:
/* jump to offset */
len = 0;
for(i = 0; i < label.size; i++) {
len += type2stat(&stat, label.data[i]->name, &m->qid);
for(i = 0; i < bar.size; i++) {
len += type2stat(&stat, bar.data[i]->name, &m->qid);
if(len <= fcall->offset)
continue;
break;
}
/* offset found, proceeding */
for(; i < label.size; i++) {
len = type2stat(&stat, label.data[i]->name, &m->qid);
for(; i < bar.size; i++) {
len = type2stat(&stat, bar.data[i]->name, &m->qid);
if(fcall->count + len > fcall->iounit)
break;
fcall->count += len;
@ -905,8 +905,8 @@ xread(IXPConn *c, Fcall *fcall)
}
break;
case FsDbars:
for(i = 0; i < label.size; i++) {
len = type2stat(&stat, label.data[i]->name, &m->qid);
for(i = 0; i < bar.size; i++) {
len = type2stat(&stat, bar.data[i]->name, &m->qid);
if(fcall->count + len > fcall->iounit)
break;
fcall->count += len;
@ -914,7 +914,7 @@ xread(IXPConn *c, Fcall *fcall)
}
break;
case FsDbar:
if(i1 >= label.size)
if(i1 >= bar.size)
return Enofile;
fcall->count = type2stat(&stat, "colors", &m->qid);
p = ixp_enc_stat(p, &stat);
@ -1053,16 +1053,16 @@ xread(IXPConn *c, Fcall *fcall)
}
break;
case FsFdata:
if(i1 >= label.size)
if(i1 >= bar.size)
return Enofile;
if((fcall->count = strlen(label.data[i1]->data)))
memcpy(p, label.data[i1]->data, fcall->count);
if((fcall->count = strlen(bar.data[i1]->data)))
memcpy(p, bar.data[i1]->data, fcall->count);
break;
case FsFcolors:
if(i1 >= label.size)
if(i1 >= bar.size)
return Enofile;
if((fcall->count = strlen(label.data[i1]->colstr)))
memcpy(p, label.data[i1]->colstr, fcall->count);
if((fcall->count = strlen(bar.data[i1]->colstr)))
memcpy(p, bar.data[i1]->colstr, fcall->count);
break;
case FsFselcolors:
if((fcall->count = strlen(def.selcolor)))
@ -1236,19 +1236,19 @@ xwrite(IXPConn *c, Fcall *fcall)
break;
case FsFdata:
len = fcall->count;
if(len >= sizeof(label.data[i1]->data))
len = sizeof(label.data[i1]->data) - 1;
memcpy(label.data[i1]->data, fcall->data, len);
label.data[i1]->data[len] = 0;
if(len >= sizeof(bar.data[i1]->data))
len = sizeof(bar.data[i1]->data) - 1;
memcpy(bar.data[i1]->data, fcall->data, len);
bar.data[i1]->data[len] = 0;
draw_bar();
break;
case FsFcolors:
if((i1 >= label.size) || (fcall->count != 23) || (fcall->data[0] != '#')
if((i1 >= bar.size) || (fcall->count != 23) || (fcall->data[0] != '#')
|| (fcall->data[8] != '#') || (fcall->data[16] != '#'))
return Ebadvalue;
memcpy(label.data[i1]->colstr, fcall->data, fcall->count);
label.data[i1]->colstr[fcall->count] = 0;
blitz_loadcolor(dpy, screen, label.data[i1]->colstr, &label.data[i1]->color);
memcpy(bar.data[i1]->colstr, fcall->data, fcall->count);
bar.data[i1]->colstr[fcall->count] = 0;
blitz_loadcolor(dpy, screen, bar.data[i1]->colstr, &bar.data[i1]->color);
draw_bar();
break;
case FsFselcolors:
@ -1334,7 +1334,7 @@ xwrite(IXPConn *c, Fcall *fcall)
return Ebadvalue;
view.data[i1]->area.data[i2]->mode = i;
arrange_column(view.data[i1]->area.data[i2], True);
if(view.data[i1]->area.data[i2]->frame.size == 1) /* little hack to update the taglabel */
if(view.data[i1]->area.data[i2]->frame.size == 1) /* little hack to update the tagbar */
draw_client(view.data[i1]->area.data[i2]->frame.data[view.data[i1]->area.data[i2]->sel]->client);
break;
case FsFevent:

View File

@ -14,6 +14,14 @@ vector_of_views(ViewVector *vv)
return (Vector *) vv;
}
static int
comp_view_name(const void *v1, const void *v2)
{
View *vv1 = *(View **)v1;
View *vv2 = *(View **)v2;
return strcmp(vv1->name, vv2->name);
}
View *
create_view(char *name)
{
@ -26,6 +34,7 @@ create_view(char *name)
create_area(v);
sel = view.size;
cext_vattach(vector_of_views(&view), v);
qsort(view.data, view.size, sizeof(View *), comp_view_name);
return v;
}

View File

@ -284,8 +284,8 @@ main(int argc, char *argv[])
key.data = nil;
key.size = 0;
label.data = nil;
label.size = 0;
bar.data = nil;
bar.size = 0;
def.rules = nil;
def.rulessz = 0;
def.keys = nil;

View File

@ -164,7 +164,7 @@ ViewVector view;
unsigned int sel;
ClientVector client;
KeyVector key;
BarVector label;
BarVector bar;
Display *dpy;
int screen;
Window root;