finished internalized tag selector for bar

This commit is contained in:
Anselm R. Garbe 2006-03-24 13:36:35 +01:00
parent 829a64e302
commit 1b312231d6
6 changed files with 107 additions and 56 deletions

View File

@ -80,10 +80,9 @@ update_bar_geometry()
void
draw_bar()
{
unsigned int i = 0;
unsigned int x = 0, w = 0;
char name[256];
unsigned int i = 0, n = 0, x = 0, w = 0;
Draw d = { 0 };
Label *l = nil;
d.align = WEST;
d.gc = bargc;
@ -95,60 +94,61 @@ draw_bar()
d.color = def.norm;
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
if(ntag) {
for(i = 0; i < nview; i++) {
View *v = view[i];
tags2str(name, sizeof(name), v->tag, v->ntag);
d.data = name;
if(i == sel)
d.color = def.sel;
else
d.color = def.norm;
d.rect.x = x;
d.rect.width = brect.height;
if(strlen(name))
d.rect.width += XTextWidth(xfont, name, strlen(name));
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
x += d.rect.width;
}
if(!nlabel)
return;
for(i = 0; (i < nlabel) && label[i]->intern; i++) {
l = label[i];
if(nview && !strncmp(l->data, def.tag, sizeof(l->data)))
l->color = def.sel;
else
l->color = def.norm;
l->rect.y = 0;
l->rect.x = x;
l->rect.width = l->rect.height = brect.height;
if(strlen(l->name))
l->rect.width += XTextWidth(xfont, l->name, strlen(l->name));
x += l->rect.width;
}
if(nlabel) {
for(i = 0; i < nlabel; i++) {
Label *l = label[i];
l->rect.x = x;
l->rect.y = 0;
l->rect.height = brect.height;
l->rect.width = brect.height;
if(strlen(l->data))
l->rect.width += XTextWidth(xfont, l->data, strlen(l->data));
w += l->rect.width;
}
if(i)
n = i;
for(; i < nlabel; i++) {
l = label[i];
l->rect.x = x;
l->rect.y = 0;
l->rect.height = brect.height;
l->rect.width = brect.height;
if(strlen(l->data))
l->rect.width += XTextWidth(xfont, l->data, strlen(l->data));
w += l->rect.width;
}
if(w >= brect.width - x) {
/* failsafe mode, give all labels same width */
w = (brect.width - x) / nlabel;
for(i = 0; i < nlabel; i++) {
label[i]->rect.x = x + i * w;
label[i]->rect.width = w;
}
i--;
label[i]->rect.width = brect.width - label[i]->rect.x;
}
else {
label[0]->rect.x = brect.width - w;
for(i = 1; i < nlabel; i++)
label[i]->rect.x = label[i - 1]->rect.x + label[i - 1]->rect.width;
if(w >= brect.width - x) {
/* failsafe mode, give all labels same width */
w = (brect.width - x) / (nlabel - n);
for(i = n; i < nlabel; i++) {
l = label[i];
l->rect.x = x + i * w;
l->rect.width = w;
}
i--;
label[i]->rect.width = brect.width - label[i]->rect.x;
}
else {
label[n]->rect.x = brect.width - w;
for(i = n + 1; i < nlabel; i++)
label[i]->rect.x = label[i - 1]->rect.x + label[i - 1]->rect.width;
}
for(i = 0; i < nlabel; i++) {
d.color = label[i]->color;
d.rect = label[i]->rect;
d.data = label[i]->data;
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
}
for(i = 0; i < nlabel; i++) {
l = label[i];
fprintf(stderr, "%d=i %d %d %d %d\n", l->intern, l->rect.x, l->rect.y, l->rect.width, l->rect.height);
d.color = l->color;
d.rect = l->rect;
d.data = l->data;
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
}
XCopyArea(dpy, barpmap, barwin, bargc, 0, 0, brect.width, brect.height, 0, 0);
XSync(dpy, False);
@ -186,3 +186,32 @@ name2label(const char *name)
return label[i];
return nil;
}
void
update_bar_tags()
{
unsigned int i;
char vname[256];
Label *l = nil;
for(i = 0; (i < nlabel) && label[i]->intern; i++) {
l = label[i];
if(!istag(l->name) && !name2view(l->name)) {
destroy_label(l);
i--;
}
}
for(i = 0; i < ntag; i++) {
l = get_label(tag[i]);
l->intern = True;
cext_strlcpy(l->data, tag[i], sizeof(l->data));
}
for(i = 0; i < nview; i++) {
View *v = view[i];
tags2str(vname, sizeof(vname), v->tag, v->ntag);
l = get_label(vname);
l->intern = True;
cext_strlcpy(l->data, vname, sizeof(l->data));
}
draw_bar();
}

View File

@ -686,6 +686,8 @@ xremove(IXPConn *c, Fcall *fcall)
case FsDlabel:
{
Label *l = label[i1];
if(l->intern)
return Enoperm;
/* now detach the label */
destroy_label(l);
free(l);
@ -743,6 +745,7 @@ xread(IXPConn *c, Fcall *fcall)
break;
case FsDbar:
/* jump to offset */
len = 0;
for(i = 0; i < nlabel; i++) {
len += type2stat(&stat, label[i]->name, &m->qid);
if(len <= fcall->offset)

View File

@ -78,6 +78,8 @@ update_tags()
if(!nview && ntag)
select_view(tag[0]);
else
update_bar_tags();
}
unsigned int

View File

@ -87,7 +87,7 @@ focus_view(View *v)
XMoveWindow(dpy, client[i]->framewin,
2 * rect.width + f->rect.x, f->rect.y);
}
draw_bar();
update_bar_tags();
XSync(dpy, False);
XUngrabServer(dpy);
}
@ -134,12 +134,11 @@ vid2index(unsigned short id)
}
View *
get_view(char *name)
name2view(char *name)
{
unsigned int i, j, ntags;
View *v = nil;
char vname[256];
char tags[MAX_TAGS][MAX_TAGLEN];
unsigned int i;
for(i = 0; i < nview; i++) {
v = view[i];
@ -148,6 +147,19 @@ get_view(char *name)
return v;
}
return nil;
}
View *
get_view(char *name)
{
unsigned int i, j, ntags;
View *v = name2view(name);
char tags[MAX_TAGS][MAX_TAGLEN];
if(v)
return v;
ntags = str2tags(tags, name);
for(i = 0; i < nclient; i++)
for(j = 0; j < ntags; j++)

View File

@ -140,6 +140,7 @@ typedef struct {
char colstr[24];
Color color;
XRectangle rect;
Bool intern;
} Label;
/* default values */
@ -221,6 +222,7 @@ void update_bar_geometry();
unsigned int bar_height();
Label *name2label(const char *name);
int label2index(Label *l);
void update_bar_tags();
/* client.c */
Client *alloc_client(Window w, XWindowAttributes *wa);
@ -295,6 +297,7 @@ void attach_toview(View *v, Client *c);
Client *sel_client_of_view(View *v);
void restack_view(View *v);
Bool hasclient(View *v);
View *name2view(char *name);
/* wm.c */
void scan_wins();

View File

@ -95,6 +95,8 @@ do
then
exit
fi;;
LabelClick)
xwrite /ctl view $1;;
Key)
case "$1" in
$MODKEY-Control-c)