added string definitions to BlitzColor and BlitzFont, removed cmd/wm/wm.h:struct Color

This commit is contained in:
Anselm R. Garbe 2006-06-19 10:28:37 +02:00
parent 8bbeb9a970
commit a94fc7cf54
9 changed files with 65 additions and 102 deletions

View File

@ -27,8 +27,7 @@ create_bar(char *name)
b->id = id++;
cext_strlcpy(b->name, name, sizeof(b->name));
cext_strlcpy(b->color.string, def.normcolor.string, sizeof(b->color.string));
b->color.col = def.normcolor.col;
b->color = def.normcolor;
for(i=&lbar; *i; i=&(*i)->next)
if(strcmp((*i)->name, name) < 0)
@ -54,7 +53,7 @@ unsigned int
height_of_bar()
{
enum { BAR_PADDING = 4 };
return blitzfont.ascent + blitzfont.descent + BAR_PADDING;
return def.font.ascent + def.font.descent + BAR_PADDING;
}
void
@ -98,9 +97,9 @@ draw_bar()
d.drawable = barpmap;
d.rect = brect;
d.rect.x = d.rect.y = 0;
d.font = blitzfont;
d.font = def.font;
d.color = def.normcolor.col;
d.color = def.normcolor;
blitz_drawlabel(&d);
blitz_drawborder(&d);
@ -112,7 +111,7 @@ draw_bar()
b->rect.y = 0;
b->rect.width = brect.height;
if(strlen(b->data))
b->rect.width += blitz_textwidth(&blitzfont, b->data);
b->rect.width += blitz_textwidth(&def.font, b->data);
b->rect.height = brect.height;
w += b->rect.width;
}
@ -134,7 +133,7 @@ draw_bar()
}
for(b=lbar; b; b=b->next) {
d.color = b->color.col;
d.color = b->color;
d.rect = b->rect;
d.data = b->data;
if(b == exp)

View File

@ -290,13 +290,13 @@ draw_client(Client *c)
for(size=fidx; t; t=t->anext, size++);
d.drawable = c->framewin;
d.font = blitzfont;
d.font = def.font;
d.gc = c->gc;
if(sel_screen && (c == sel_client()))
d.color = def.selcolor.col;
d.color = def.selcolor;
else
d.color = def.normcolor.col;
d.color = def.normcolor;
/* draw border */
if(def.border) {
@ -316,27 +316,27 @@ draw_client(Client *c)
snprintf(buf, sizeof(buf), "%s%d/%d",
/* if */ (f->area == f->area->view->area) ? "~" : "",
fidx + 1, size);
w = d.rect.width = d.rect.height + blitz_textwidth(&blitzfont, buf);
w = d.rect.width = d.rect.height + blitz_textwidth(&def.font, buf);
if(w > f->rect.width)
return;
d.rect.x = f->rect.width - d.rect.width;
d.data = buf;
if(f->area->sel == f)
d.color = def.selcolor.col;
d.color = def.selcolor;
else
d.color = def.normcolor.col;
d.color = def.normcolor;
blitz_drawlabel(&d);
blitz_drawborder(&d);
d.rect.x = 0;
if(sel_screen && (c == sel_client()))
d.color = def.selcolor.col;
d.color = def.selcolor;
else
d.color = def.normcolor.col;
d.color = def.normcolor;
/* tag bar */
d.rect.width = d.rect.height + blitz_textwidth(&blitzfont, c->tags);
d.rect.width = d.rect.height + blitz_textwidth(&def.font, c->tags);
if(d.rect.width + w > f->rect.width)
return;
if(d.rect.width > f->rect.width / 3)

View File

@ -24,7 +24,7 @@ struct FileId {
View *view;
Client *client;
Rules *rule;
Color *col;
BlitzColor *col;
};
unsigned int id;
unsigned int index;
@ -455,7 +455,7 @@ fs_read(Req *r) {
return respond(r, nil);
case FsFCSel:
case FsFCNorm:
write_buf(r, (void *)f->col->string, strlen(f->col->string));
write_buf(r, (void *)f->col->colstr, strlen(f->col->colstr));
return respond(r, nil);
case FsFColRules:
case FsFTagRules:
@ -465,7 +465,7 @@ fs_read(Req *r) {
write_buf(r, (void *)def.keys, def.keyssz);
return respond(r, nil);
case FsFFont:
write_buf(r, (void *)def.font, strlen(def.font));
write_buf(r, (void *)def.font.fontstr, strlen(def.font.fontstr));
return respond(r, nil);
case FsFCtags:
write_buf(r, (void *)f->client->tags, strlen(f->client->tags));
@ -486,7 +486,7 @@ fs_read(Req *r) {
return respond(r, nil);
case FsFTindex:
buf = view_index(f->view);
n = strlen(buf);
n = strlen((char *)buf);
write_buf(r, (void *)buf, n);
return respond(r, nil);
case FsFEvent:
@ -599,13 +599,13 @@ data_to_cstring(Req *r) {
/* This should be moved to liblitz */
int
parse_colors(char **buf, int *buflen, Color *col) {
parse_colors(char **buf, int *buflen, BlitzColor *col) {
unsigned int i;
if(*buflen < 23 || 3 != sscanf(*buf, "#%06x #%06x #%06x", &i,&i,&i))
return 0;
(*buflen) -= 23;
bcopy(*buf, col->string, 23);
blitz_loadcolor(&col->col, col->string);
bcopy(*buf, col->colstr, 23);
blitz_loadcolor(col);
return 1;
}
@ -627,10 +627,10 @@ fs_write(Req *r) {
return respond(r, nil);
case FsFFont:
data_to_cstring(r);
i=strlen(def.font);
write_to_buf(r, &def.font, &i, 0);
def.font[i] = '\0';
blitz_loadfont(&blitzfont, def.font);
i=strlen(def.font.fontstr);
write_to_buf(r, &def.font.fontstr, &i, 0);
def.font.fontstr[i] = '\0';
blitz_loadfont(&def.font);
r->ofcall.count = i- r->ifcall.offset;
return respond(r, nil);
case FsFCtags:

View File

@ -148,7 +148,7 @@ init_screen()
gcv.subwindow_mode = IncludeInferiors;
gcv.function = GXxor;
gcv.foreground = def.selcolor.col.bg;
gcv.foreground = def.selcolor.bg;
gcv.plane_mask = AllPlanes;
gcv.graphics_exposures = False;
xorgc = XCreateGC(dpy, root, GCForeground | GCGraphicsExposures |
@ -299,19 +299,19 @@ main(int argc, char *argv[])
def.tagrules.size = 0;
def.keys = nil;
def.keyssz = 0;
def.font = strdup(BLITZ_FONT);
def.font.fontstr = strdup(BLITZ_FONT);
def.border = 2;
def.colmode = Coldefault;
cext_strlcpy(def.selcolor.string, BLITZ_SELCOLORS, sizeof(def.selcolor.string));
blitz_loadcolor(&def.selcolor.col, def.selcolor.string);
cext_strlcpy(def.normcolor.string, BLITZ_NORMCOLORS, sizeof(def.normcolor.string));
blitz_loadcolor(&def.normcolor.col, def.normcolor.string);
cext_strlcpy(def.selcolor.colstr, BLITZ_SELCOLORS, sizeof(def.selcolor.colstr));
blitz_loadcolor(&def.selcolor);
cext_strlcpy(def.normcolor.colstr, BLITZ_NORMCOLORS, sizeof(def.normcolor.colstr));
blitz_loadcolor(&def.normcolor);
cext_strlcpy(def.grabmod, "Mod1", sizeof(def.grabmod));
def.mod = Mod1Mask;
init_atoms();
init_cursors();
blitz_loadfont(&blitzfont, def.font);
blitz_loadfont(&def.font);
init_lock_keys();
init_screen();

View File

@ -41,42 +41,6 @@ enum {
CurLast
};
/* 8-bit qid.path.type */
/*
enum {
FsDroot,
FsDdef,
FsDtag,
FsDview,
FsDarea,
FsDclients,
FsDclient,
FsDGclient,
FsDbars,
FsDbar,
FsFdata,
FsFcolors,
FsFfont,
FsFselcolors,
FsFnormcolors,
FsFkeys,
FsFgrabmod,
FsFborder,
FsFbar,
FsFgeom,
FsFevent,
FsFctl,
FsFname,
FsFtagrules,
FsFcolrules,
FsFprops,
FsFmode,
FsFtags,
FsFindex,
FsLast
};
*/
enum { MIN_COLWIDTH = 64 };
enum { WM_PROTOCOL_DELWIN = 1 };
@ -154,18 +118,13 @@ struct Key {
KeyCode key;
};
typedef struct Color {
char string[24];
BlitzColor col;
} Color;
typedef struct Bar Bar;
struct Bar {
Bar *next;
char buf[280];
char name[256];
char data[256];
Color color;
BlitzColor color;
unsigned short id;
XRectangle rect;
};
@ -185,9 +144,9 @@ typedef struct Rules {
/* default values */
typedef struct {
Color selcolor;
Color normcolor;
char *font;
BlitzColor selcolor;
BlitzColor normcolor;
BlitzFont font;
unsigned int border;
unsigned int snap;
char *keys;
@ -228,7 +187,6 @@ Display *dpy;
int screen;
Window root;
XRectangle rect;
BlitzFont blitzfont;
IXPServer srv;
Pixmap barpmap;
Window barwin;

View File

@ -345,7 +345,7 @@ main(int argc, char *argv[])
{
int i;
XSetWindowAttributes wa;
char *fontstr, *selcolstr, *normcolstr, *maxname;
char *maxname, *p;
XEvent ev;
/* command line args */
@ -387,18 +387,22 @@ main(int argc, char *argv[])
/* set font and colors */
blitz_x11_init(dpy);
fontstr = getenv("WMII_FONT");
if (!fontstr)
fontstr = strdup(BLITZ_FONT);
blitz_loadfont(&draw.font, fontstr);
normcolstr = getenv("WMII_NORMCOLORS");
if (!normcolstr || strlen(normcolstr) != 23)
normcolstr = strdup(BLITZ_NORMCOLORS);
blitz_loadcolor(&normcolor, normcolstr);
selcolstr = getenv("WMII_SELCOLORS");
if (!selcolstr || strlen(selcolstr) != 23)
selcolstr = strdup(BLITZ_SELCOLORS);
blitz_loadcolor(&selcolor, selcolstr);
draw.font.fontstr = getenv("WMII_FONT");
if (!draw.font.fontstr)
draw.font.fontstr = strdup(BLITZ_FONT);
blitz_loadfont(&draw.font);
if((p = getenv("WMII_NORMCOLORS")))
cext_strlcpy(normcolor.colstr, p, sizeof(normcolor.colstr));
if(strlen(normcolor.colstr) != 23)
cext_strlcpy(normcolor.colstr, BLITZ_NORMCOLORS, sizeof(normcolor.colstr));
blitz_loadcolor(&normcolor);
if((p = getenv("WMII_SELCOLORS")))
cext_strlcpy(selcolor.colstr, p, sizeof(selcolor.colstr));
if(strlen(selcolor.colstr) != 23)
cext_strlcpy(selcolor.colstr, BLITZ_SELCOLORS, sizeof(selcolor.colstr));
blitz_loadcolor(&selcolor);
wa.override_redirect = 1;
wa.background_pixmap = ParentRelative;

View File

@ -38,6 +38,7 @@ struct BlitzColor {
unsigned long bg;
unsigned long fg;
unsigned long border;
char colstr[24]; /* #RRGGBB #RRGGBB #RRGGBB */
};
struct BlitzFont {
@ -45,6 +46,7 @@ struct BlitzFont {
XFontSet set;
int ascent;
int descent;
char *fontstr;
};
struct BlitzWidget {
@ -79,7 +81,7 @@ void blitz_x11_init(Display *dpy);
Bool blitz_x11_event(XEvent *ev);
/* color.c */
int blitz_loadcolor(BlitzColor *c, char *colstr);
int blitz_loadcolor(BlitzColor *c);
/* label.c */
void blitz_drawlabel(BlitzDraw *d);
@ -97,4 +99,4 @@ void blitz_destroy_tile(BlitzWidget *t);
/* font.c */
unsigned int blitz_textwidth(BlitzFont *font, char *text);
void blitz_loadfont(BlitzFont *font, char *fontstr);
void blitz_loadfont(BlitzFont *font);

View File

@ -22,13 +22,13 @@ xloadcolor(char *colstr)
}
int
blitz_loadcolor(BlitzColor *c, char *colstr)
blitz_loadcolor(BlitzColor *c)
{
if(!colstr || strlen(colstr) != 23)
if(!c->colstr || strlen(c->colstr) != 23)
return -1;
c->fg = xloadcolor(&colstr[0]);
c->bg = xloadcolor(&colstr[8]);
c->border = xloadcolor(&colstr[16]);
c->fg = xloadcolor(&c->colstr[0]);
c->bg = xloadcolor(&c->colstr[8]);
c->border = xloadcolor(&c->colstr[16]);
return 0;
}

View File

@ -23,9 +23,9 @@ blitz_textwidth(BlitzFont *font, char *text)
}
void
blitz_loadfont(BlitzFont *font, char *fontstr)
blitz_loadfont(BlitzFont *font)
{
char *fontname = fontstr;
char *fontname = font->fontstr;
char **missing = nil, *def = "?";
int n;