wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 529a035b51b2acdbe33f2290887e6a1414e82f7c
parent 8b8b9ada4750823e42d07d73dc4451b7d107ce12
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Mon, 19 Jun 2006 18:26:06 +0200

remove BlitzDraw from draw_client, using 4 BlitzWidget's instead (in frame), renamed draw_client into draw_frame


Diffstat:
cmd/wm/client.c | 95+++++--------------------------------------------------------------------------
cmd/wm/event.c | 2+-
cmd/wm/frame.c | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cmd/wm/fs.c | 4++--
cmd/wm/wm.h | 15+++++++--------
liblitz/blitz.h | 4++--
liblitz/input.c | 17+++++++++--------
7 files changed, 118 insertions(+), 111 deletions(-)

diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -156,10 +156,10 @@ focus_client(Client *c, Bool restack) arrange_column(f->area, False); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); if(old && old != old_in_area && old != c) - draw_client(old); + draw_frame(old->sel); if(old_in_area && old_in_area != c) - draw_client(old_in_area); - draw_client(c); + draw_frame(old_in_area->sel); + draw_frame(c->sel); XSync(dpy, False); snprintf(buf, sizeof(buf), "ClientFocus %d\n", idx_of_client(c)); write_event(buf); @@ -269,96 +269,11 @@ prop_client(Client *c, XPropertyEvent *e) if(e->atom == XA_WM_NAME || e->atom == net_atom[NetWMName]) { update_client_name(c); if(c->frame) - draw_client(c); + draw_frame(c->sel); } } void -draw_client(Client *c) -{ - BlitzDraw d = { 0 }; - Frame *f, *t; - char buf[256]; - int fidx; - unsigned int w, size; - - if(!c->frame) - return; /* might not have been attached atm */ - - f = c->sel; - for(fidx=0, t=f->area->frame; t && t != f; t=t->anext, fidx++); - for(size=fidx; t; t=t->anext, size++); - - d.drawable = c->framewin; - d.font = def.font; - d.gc = c->gc; - - if(sel_screen && (c == sel_client())) - d.color = def.selcolor; - else - d.color = def.normcolor; - - /* draw border */ - if(def.border) { - d.rect = f->rect; - d.rect.x = d.rect.y = 0; - d.notch = &c->rect; - blitz_drawlabel(&d); - blitz_drawborder(&d); - } - d.rect.x = 0; - d.rect.y = 0; - d.rect.height = height_of_bar(); - d.notch = nil; - - /* mode bar */ - d.align = CENTER; - 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(&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; - else - d.color = def.normcolor; - blitz_drawlabel(&d); - blitz_drawborder(&d); - d.rect.x = 0; - - if(sel_screen && (c == sel_client())) - d.color = def.selcolor; - else - d.color = def.normcolor; - - /* tag bar */ - 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) - d.rect.width = f->rect.width / 3; - d.data = c->tags; - blitz_drawlabel(&d); - blitz_drawborder(&d); - d.rect.x += d.rect.width; - - /* title bar */ - d.align = WEST; - if(d.rect.x + w > f->rect.width) - return; - d.rect.width = f->rect.width - (d.rect.x + w); - d.data = c->name; - blitz_drawlabel(&d); - blitz_drawborder(&d); - - XSync(dpy, False); -} - -void gravitate_client(Client *c, Bool invert) { int dx = 0, dy = 0; @@ -807,7 +722,7 @@ draw_clients() Client *c; for(c=client; c; c=c->next) if(c->sel && (c->sel->area->view == sel)) - draw_client(c); + draw_frame(c->sel); } static Bool diff --git a/cmd/wm/event.c b/cmd/wm/event.c @@ -238,7 +238,7 @@ handle_expose(XEvent *e) if(ev->window == barwin) draw_bar(); else if((c = frame_of_win(ev->window))) - draw_client(c); + draw_frame(c->sel); } } diff --git a/cmd/wm/frame.c b/cmd/wm/frame.c @@ -4,6 +4,7 @@ */ #include <stdlib.h> +#include <string.h> #include "wm.h" @@ -22,6 +23,17 @@ create_frame(Area *a, Client *c) f->rect.width += 2 * def.border; f->rect.height += def.border + height_of_bar(); f->collapsed = False; + + f->tile = blitz_create_tile(c->framewin, c->gc); + f->tagbar = blitz_create_input(c->framewin, c->gc, &def.font); + f->titlebar = blitz_create_input(c->framewin, c->gc, &def.font); + f->posbar = blitz_create_input(c->framewin, c->gc, &def.font); + f->tile->notch = &c->rect; + f->tagbar->text = c->tags; + f->titlebar->text = c->name; + f->titlebar->align = WEST; + f->tagbar->align = f->posbar->align = CENTER; + a->sel = f; c->sel = f; @@ -65,6 +77,13 @@ destroy_frame(Frame *f) Area *a = f->area; Frame **ft, *pr = nil; + blitz_destroy_tile(f->tile); + blitz_destroy_input(f->tagbar); + blitz_destroy_input(f->titlebar); + if(f->posbar->text) + free(f->posbar->text); + blitz_destroy_input(f->posbar); + for(ft=&c->frame; *ft && *ft != f; pr = *ft, ft=&(*ft)->cnext); cext_assert(*ft == f); *ft = f->cnext; @@ -104,3 +123,76 @@ frame_of_win(Window w) for(c=client; c && c->framewin != w; c=c->next); return c; } + +void +update_frame_widget_colors(Frame *f) +{ + if(sel_screen && (f->client == sel_client())) + f->tile->color = f->tagbar->color = f->titlebar->color + = def.selcolor; + else + f->tile->color = f->tagbar->color = f->titlebar->color + = def.normcolor; + + if(f->area->sel == f) + f->posbar->color = def.selcolor; + else + f->posbar->color = def.normcolor; +} + +void +resize_frame(Frame *f) +{ + + Frame *p; + unsigned int fidx, size, w; + char buf[256]; + + for(fidx=0, p=f->area->frame; p && p != f; p=p->anext, fidx++); + for(size=fidx; p; p=p->anext, size++); + + if(def.border) { + f->tile->rect = f->rect; + f->tile->rect.x = f->tile->rect.y = 0; + } + + f->posbar->rect = f->tile->rect; + f->posbar->rect.height = height_of_bar(); + + snprintf(buf, sizeof(buf), "%s%d/%d", + (f->area == f->area->view->area) ? "~" : "", fidx + 1, size); + if(f->posbar->text) + free(f->posbar->text); + f->posbar->text = strdup(buf); + + w = f->posbar->rect.width = + f->posbar->rect.height + blitz_textwidth(&def.font, f->posbar->text); + + f->posbar->rect.x = f->rect.width - f->posbar->rect.width; + + /* tag bar */ + f->tagbar->rect = f->posbar->rect; + f->tagbar->rect.x = 0; + f->tagbar->rect.width = + f->tagbar->rect.height + blitz_textwidth(&def.font, f->tagbar->text); + + if(f->tagbar->rect.width > f->rect.width / 3) + f->tagbar->rect.width = f->rect.width / 3; + + f->titlebar->rect = f->tagbar->rect; + f->titlebar->rect.x = f->tagbar->rect.x + f->tagbar->rect.width; + f->titlebar->rect.width = f->rect.width - (f->tagbar->rect.width + f->posbar->rect.width); +} + +void +draw_frame(Frame *f) +{ + /* XXX: should be called on area change focus/attach/detach */ + update_frame_widget_colors(f); + /* XXX: should be called after resize */ + resize_frame(f); + f->tile->draw(f->tile); + f->tagbar->draw(f->tagbar); + f->titlebar->draw(f->titlebar); + f->posbar->draw(f->posbar); +} diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c @@ -555,7 +555,7 @@ fs_clunk(Req *r) { case FsFCtags: apply_tags(f->client, f->client->tags); update_views(); - draw_client(f->client); + draw_frame(f->client->sel); break; } respond(r, nil); @@ -689,7 +689,7 @@ fs_write(Req *r) { return respond(r, nil); case FsFRctl: data_to_cstring(r); - if(r->ifcall.count == 0) + if(!r->ifcall.data || r->ifcall.count == 0) return respond(r, nil); /* XXX: This needs to be moved to client_message(char *) */ diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -83,6 +83,10 @@ struct Frame { XRectangle revert; Client *client; Bool collapsed; + BlitzWidget *tile; + BlitzWidget *tagbar; + BlitzWidget *titlebar; + BlitzWidget *posbar; }; struct Client { @@ -231,7 +235,6 @@ void destroy_client(Client *c); void configure_client(Client *c); void prop_client(Client *c, XPropertyEvent *e); void kill_client(Client *c); -void draw_client(Client *client); void gravitate_client(Client *c, Bool invert); void unmap_client(Client *c); void map_client(Client *c); @@ -279,8 +282,9 @@ void insert_frame(Frame *pos, Frame *f, Bool before); int idx_of_frame(Frame *f); Frame *frame_of_id(Area *a, unsigned short id); Client *frame_of_win(Window w); +void draw_frame(Frame *f); -/* fs2.c */ +/* fs.c */ void fs_attach(Req *r); void fs_clunk(Req *r); void fs_create(Req *r); @@ -292,12 +296,7 @@ void fs_remove(Req *r); void fs_stat(Req *r); void fs_walk(Req *r); void fs_write(Req *r); - -/* fs.c */ -unsigned long long pack_qpath(unsigned char type, unsigned short i1, - unsigned short i2, unsigned short i3); -void write_event(char *event); -void new_ixp_conn(IXPConn *c); +void write_event(char *buf); /* geom.c */ BlitzAlign quadofcoord(XRectangle *rect, int x, int y); diff --git a/liblitz/blitz.h b/liblitz/blitz.h @@ -54,7 +54,7 @@ struct BlitzWidget { GC gc; BlitzColor color; BlitzAlign align; - BlitzFont font; + BlitzFont *font; XRectangle rect; /* relative rect */ XRectangle *notch; /* relative notch rect */ char *text; @@ -88,7 +88,7 @@ void blitz_drawlabel(BlitzDraw *d); void blitz_drawborder(BlitzDraw *d); /* input.c */ -BlitzWidget *blitz_create_input(Drawable drawable, GC gc); +BlitzWidget *blitz_create_input(Drawable drawable, GC gc, BlitzFont *font); void blitz_draw_input(BlitzWidget *i); void blitz_destroy_input(BlitzWidget *i); diff --git a/liblitz/input.c b/liblitz/input.c @@ -9,11 +9,12 @@ #include "blitz.h" BlitzWidget * -blitz_create_input(Drawable drawable, GC gc) +blitz_create_input(Drawable drawable, GC gc, BlitzFont *font) { BlitzWidget *i = cext_emallocz(sizeof(BlitzWidget)); i->drawable = drawable; i->gc = gc; + i->font = font; i->draw = blitz_draw_input; return i; } @@ -36,18 +37,18 @@ blitz_draw_input(BlitzWidget *i) len = strlen(text); gcv.foreground = i->color.fg; gcv.background = i->color.bg; - if(i->font.set) + if(i->font->set) XChangeGC(__blitz.display, i->gc, GCForeground | GCBackground, &gcv); else { - gcv.font = i->font.xfont->fid; + gcv.font = i->font->xfont->fid; XChangeGC(__blitz.display, i->gc, GCForeground | GCBackground | GCFont, &gcv); } - h = i->font.ascent + i->font.descent; - y = i->rect.y + i->rect.height / 2 - h / 2 + i->font.ascent; + h = i->font->ascent + i->font->descent; + y = i->rect.y + i->rect.height / 2 - h / 2 + i->font->ascent; /* shorten text if necessary */ - while (len && (w = blitz_textwidth(&i->font, text)) > i->rect.width) { + while (len && (w = blitz_textwidth(i->font, text)) > i->rect.width) { text[len - 1] = 0; len--; shortened = 1; @@ -76,8 +77,8 @@ blitz_draw_input(BlitzWidget *i) x = i->rect.x + h / 2; break; } - if(i->font.set) - XmbDrawString(__blitz.display, i->drawable, i->font.set, i->gc, x, y, text, len); + if(i->font->set) + XmbDrawString(__blitz.display, i->drawable, i->font->set, i->gc, x, y, text, len); else XDrawString(__blitz.display, i->drawable, i->gc, x, y, text, len); }