From 40abae9c301f3ef23b69d26ef91160721895380a Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 21 May 2008 13:15:13 -0400 Subject: [PATCH] Allow bar on top or bottom. Cleanup. --- cmd/wmii/bar.c | 15 +++++---------- cmd/wmii/client.c | 7 +++---- cmd/wmii/column.c | 8 +++----- cmd/wmii/dat.h | 6 ++++++ cmd/wmii/ewmh.c | 2 +- cmd/wmii/fns.h | 1 + cmd/wmii/frame.c | 4 ++-- cmd/wmii/message.c | 36 +++++++++++++++++++++++++++++------- cmd/wmii/view.c | 44 ++++++++++++++++++++++++++++++-------------- 9 files changed, 80 insertions(+), 43 deletions(-) diff --git a/cmd/wmii/bar.c b/cmd/wmii/bar.c index c8a4170a..e0d21005 100644 --- a/cmd/wmii/bar.c +++ b/cmd/wmii/bar.c @@ -36,16 +36,11 @@ bar_init(WMScreen *s) { void bar_resize(WMScreen *s) { - View *v; s->brect = s->r; - s->brect.min.y = s->brect.max.y - labelh(def.font); + s->brect.max.y = labelh(def.font); - reshapewin(s->barwin, s->brect); - - bar_draw(s); - for(v=view; v; v=v->next) - view_arrange(v); + view_update(screen->sel); } void @@ -65,9 +60,9 @@ bar_sety(int y) { r = &screen->brect; - dy = y - r->min.y; - r->min.y += dy; - r->max.y += dy; + dy = Dy(*r); + r->min.y = y; + r->max.y = y + dy; reshapewin(screen->barwin, *r); } diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c index 36c05e9d..a27603b3 100644 --- a/cmd/wmii/client.c +++ b/cmd/wmii/client.c @@ -618,8 +618,7 @@ fullscreen(Client *c, int fullscreen) { for(f=c->frame; f; f=f->cnext) f->oldarea = -1; if((f = c->sel)) - if(f->view == screen->sel) - view_focus(screen, f->view); + view_update(f->view); } } @@ -780,8 +779,8 @@ client_prop(Client *c, Atom a) { if(c->w.hints) c->fixedsize = eqpt(c->w.hints->min, c->w.hints->max); if(memcmp(&h, c->w.hints, sizeof h)) - if(c->sel && c->sel->view == screen->sel) - view_focus(screen, screen->sel); + if(c->sel) + view_update(c->sel->view); break; case XA_WM_HINTS: wmh = XGetWMHints(display, c->w.w); diff --git a/cmd/wmii/column.c b/cmd/wmii/column.c index cc48c398..151d941c 100644 --- a/cmd/wmii/column.c +++ b/cmd/wmii/column.c @@ -41,8 +41,7 @@ column_new(View *v, Area *pos, uint w) { return nil; view_arrange(v); - if(v == screen->sel) - view_focus(screen, v); + view_update(v); #endif } @@ -384,7 +383,7 @@ column_resize(Area *a, int w) { an->r.min.x += dw; /* view_arrange(a->view); */ - view_focus(screen, a->view); + view_update(a->view); } static void @@ -461,7 +460,6 @@ column_resizeframe(Frame *f, Rectangle r) { column_resizeframe_h(f, r); /* view_arrange(v); */ - if(v == screen->sel) - view_focus(screen, v); + view_update(v); } diff --git a/cmd/wmii/dat.h b/cmd/wmii/dat.h index 173633aa..e753629e 100644 --- a/cmd/wmii/dat.h +++ b/cmd/wmii/dat.h @@ -66,6 +66,11 @@ enum { Toggle, }; +enum Barpos { + BBottom, + BTop, +}; + enum { CurNormal, CurNECorner, CurNWCorner, CurSECorner, CurSWCorner, @@ -315,6 +320,7 @@ EXTERN struct WMScreen { Window* barwin; Image* ibuf; Image* ibuf32; + int barpos; Rectangle r; Rectangle brect; diff --git a/cmd/wmii/ewmh.c b/cmd/wmii/ewmh.c index 8d483252..24bacc23 100644 --- a/cmd/wmii/ewmh.c +++ b/cmd/wmii/ewmh.c @@ -295,7 +295,7 @@ ewmh_getstrut(Client *c) { Dprint(DEwmh, "\tright: %R\n", c->strut->right); Dprint(DEwmh, "\tbottom: %R\n", c->strut->bottom); free(strut); - view_focus(screen, screen->sel); + view_update(screen->sel); } int diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h index 1ffa1da4..9d7877e3 100644 --- a/cmd/wmii/fns.h +++ b/cmd/wmii/fns.h @@ -227,6 +227,7 @@ void view_restack(View*); void view_scale(View*, int w); Client* view_selclient(View*); void view_select(const char*); +void view_update(View*); void view_update_all(void); void view_update_rect(View*); Rectangle* view_rects(View*, uint *num, Frame *ignore); diff --git a/cmd/wmii/frame.c b/cmd/wmii/frame.c index 00cf542a..5910b2d8 100644 --- a/cmd/wmii/frame.c +++ b/cmd/wmii/frame.c @@ -508,8 +508,8 @@ frame_swap(Frame *fa, Frame *fb) { fa->cnext = c->frame; c->frame = fa; - if(c->sel && c->sel->view == screen->sel) - view_focus(screen, c->sel->view); + if(c->sel) + view_update(c->sel->view); } void diff --git a/cmd/wmii/message.c b/cmd/wmii/message.c index 1e868408..626914a7 100644 --- a/cmd/wmii/message.c +++ b/cmd/wmii/message.c @@ -20,6 +20,7 @@ static char enum { LFULLSCREEN, LURGENT, + LBAR, LBORDER, LCLIENT, LCOLMODE, @@ -51,6 +52,7 @@ enum { char *symtab[] = { "Fullscreen", "Urgent", + "bar", "border", "client", "colmode", @@ -88,6 +90,11 @@ char* debugtab[] = { "generic", }; +static char* barpostab[] = { + "bottom", + "top", +}; + /* Edit ,y/^[a-zA-Z].*\n.* {\n/d * Edit s/^([a-zA-Z].*)\n(.*) {\n/\1 \2;\n/ * Edit ,x/^static.*\n/d @@ -127,6 +134,11 @@ getdebug(char *s) { return _bsearch(s, debugtab, nelem(debugtab)); } +static int +getbarpos(char *s) { + return _bsearch(s, barpostab, nelem(barpostab)); +} + static int gettoggle(IxpMsg *m) { switch(getsym(msg_getword(m))) { @@ -405,6 +417,7 @@ message_root(void *p, IxpMsg *m) { Font *fn; char *s, *ret; ulong n; + int i; USED(p); ret = nil; @@ -413,11 +426,21 @@ message_root(void *p, IxpMsg *m) { return nil; switch(getsym(s)) { + case LBAR: /* bar on? <"top" | "bottom"> */ + s = msg_getword(m); + if(!strcmp(s, "on")) + s = msg_getword(m); + i = getbarpos(s); + if(i < 0) + return Ebadvalue; + screen->barpos = i; + view_update(screen->sel); + break; case LBORDER: if(!getulong(msg_getword(m), &n)) return Ebadvalue; def.border = n; - view_focus(screen, screen->sel); + view_update(screen->sel); break; case LDEBUG: ret = msg_debug(m); @@ -428,7 +451,7 @@ message_root(void *p, IxpMsg *m) { break; case LFOCUSCOLORS: ret = msg_parsecolors(m, &def.focuscolor); - view_focus(screen, screen->sel); + view_update(screen->sel); break; case LFONT: fn = loadfont(m->pos); @@ -438,7 +461,7 @@ message_root(void *p, IxpMsg *m) { bar_resize(screen); }else ret = "can't load font"; - view_focus(screen, screen->sel); + view_update(screen->sel); break; case LGRABMOD: s = msg_getword(m); @@ -452,7 +475,7 @@ message_root(void *p, IxpMsg *m) { break; case LNORMCOLORS: ret = msg_parsecolors(m, &def.normcolor); - view_focus(screen, screen->sel); + view_update(screen->sel); break; case LSELCOLORS: fprint(2, "%s: warning: selcolors have been removed\n", argv0); @@ -536,9 +559,7 @@ message_view(View *v, IxpMsg *m) { column_arrange(a, true); view_restack(v); - if(v == screen->sel) - view_focus(screen, v); - frame_draw_all(); + view_update(v); return nil; case LGROW: return msg_grow(v, m); @@ -977,6 +998,7 @@ readctl_root(void) { bufprint("font %s\n", def.font->name); bufprint("grabmod %s\n", def.grabmod); bufprint("border %d\n", def.border); + bufprint("bar on %s\n", barpostab[screen->barpos]); if(debugflag) { bufprint("debug "); printdebug(debugflag); diff --git a/cmd/wmii/view.c b/cmd/wmii/view.c index cae40115..25111d5e 100644 --- a/cmd/wmii/view.c +++ b/cmd/wmii/view.c @@ -149,7 +149,7 @@ view_findarea(View *v, int idx, bool create) { } static void -update_frame_selectors(View *v) { +frames_update_sel(View *v) { Area *a; Frame *f; @@ -183,10 +183,15 @@ view_update_rect(View *v) { r.min.x += min(left, .3 * Dx(screen->r)); r.max.x += max(right, -.3 * Dx(screen->r)); r.max.y += max(bottom, -.3 * Dy(screen->r)); - r.max.y -= Dy(screen->brect); + if(screen->barpos == BTop) { + bar_sety(r.min.y); + r.min.y += Dy(screen->brect); + }else { + r.max.y -= Dy(screen->brect); + bar_sety(r.max.y); + } v->r = r; - bar_sety(r.max.y); brect = screen->brect; brect.min.x = screen->r.min.x; brect.max.x = screen->r.max.x; @@ -206,20 +211,18 @@ view_update_rect(View *v) { } void -view_focus(WMScreen *s, View *v) { +view_update(View *v) { Client *c; Frame *f, *fnext; Area *a, *an; bool fscrn; - - USED(s); - XGrabServer(display); + if(v != screen->sel) + return; - _view_select(v); - update_frame_selectors(v); + frames_update_sel(v); view_arrange(v); - div_update_all(); + fscrn = false; for(a=v->area; a; a=an) { an = a->next; @@ -237,6 +240,7 @@ view_focus(WMScreen *s, View *v) { } } } + for(c=client; c; c=c->next) { f = c->sel; if(f && f->view == v) @@ -257,10 +261,22 @@ view_focus(WMScreen *s, View *v) { frame_draw_all(); sync(); - XUngrabServer(display); flushenterevents(); } +void +view_focus(WMScreen *s, View *v) { + + USED(s); + + XGrabServer(display); + + _view_select(v); + view_update(v); + + XUngrabServer(display); +} + void view_select(const char *arg) { char buf[256]; @@ -314,7 +330,7 @@ view_detach(Frame *f) { c->sel = f->cnext; if(v == screen->sel) - view_focus(screen, v); + view_update(v); else if(empty_p(v)) view_destroy(v); } @@ -478,7 +494,7 @@ view_update_all(void) { old = screen->sel; for(v=view; v; v=v->next) - update_frame_selectors(v); + frames_update_sel(v); for(v=view; v; v=n) { n=v->next; @@ -486,7 +502,7 @@ view_update_all(void) { view_destroy(v); } - view_focus(screen, screen->sel); + view_update(screen->sel); } uint