wmii

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

commit df071b6523a5f503deb76712c87bf36ab7e779ac
parent fb53776ae5c601c48dd825143acd83e9b292db5f
Author: Kris Maglione <jg@suckless.org>
Date:   Fri, 17 Oct 2008 10:39:13 -0400

Be smarter in EWMH strut allocation. Some smaller fixes.

Diffstat:
cmd/wmii.rc.rc | 14++++++++------
cmd/wmii/area.c | 12++++++------
cmd/wmii/bar.c | 10+++++-----
cmd/wmii/client.c | 40++++++++++++++++++++--------------------
cmd/wmii/column.c | 4++--
cmd/wmii/dat.h | 17++++++++++-------
cmd/wmii/div.c | 8++++----
cmd/wmii/event.c | 24++++++++++++------------
cmd/wmii/ewmh.c | 6+++---
cmd/wmii/float.c | 126+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
cmd/wmii/fns.h | 2++
cmd/wmii/frame.c | 16++++++++--------
cmd/wmii/fs.c | 6+++---
cmd/wmii/key.c | 2+-
cmd/wmii/layout.c | 10+++++-----
cmd/wmii/main.c | 15++++++++-------
cmd/wmii/message.c | 16++++++++--------
cmd/wmii/mouse.c | 4++--
cmd/wmii/view.c | 105+++++++++++++++++++++++++++++++++++++------------------------------------------
19 files changed, 234 insertions(+), 203 deletions(-)

diff --git a/cmd/wmii.rc.rc b/cmd/wmii.rc.rc @@ -161,11 +161,13 @@ fn Event-Start { } fn Action { - cmd=$1 action=Action-$cmd { shift - if(wi_fn-p $action) - $action $* - if not - wi_runcmd `{wi_script $cmd} $* - } + cmd=$1 action=Action-$"cmd { shift + if(! ~ $cmd '') { + if(wi_fn-p $action) + $action $* + if not + wi_runcmd `{wi_script $cmd} $* + } + } } diff --git a/cmd/wmii/area.c b/cmd/wmii/area.c @@ -90,10 +90,11 @@ area_create(View *v, Area *pos, int scrn, uint width) { a->view = v; a->screen = scrn; a->id = id++; - if(v->areas) - a->mode = def.colmode; - else + a->floating = !v->floating; + if(a->floating) a->mode = Coldefault; + else + a->mode = def.colmode; a->frame = nil; a->sel = nil; @@ -101,9 +102,8 @@ area_create(View *v, Area *pos, int scrn, uint width) { a->r.min.x = 0; a->r.max.x = width; - if(!v->floating) { + if(a->floating) { v->floating = a; - a->floating = true; a->screen = -1; } else if(pos) { @@ -273,7 +273,7 @@ area_focus(Area *a) { view_update(v); } - if(v != screen->sel) + if(v != selview) return; move_focus(old_a->sel, f); diff --git a/cmd/wmii/bar.c b/cmd/wmii/bar.c @@ -166,16 +166,16 @@ bar_draw(WMScreen *s) { } r = rectsubpt(s->brect, s->brect.min); - fill(screen->ibuf, r, def.normcolor.bg); + fill(disp.ibuf, r, def.normcolor.bg); foreach_bar(s, b) { align = Center; if(b == s->bar[BRight]) align = East; - fill(screen->ibuf, b->r, b->col.bg); - drawstring(screen->ibuf, def.font, b->r, align, b->text, b->col.fg); - border(screen->ibuf, b->r, 1, b->col.border); + fill(disp.ibuf, b->r, b->col.bg); + drawstring(disp.ibuf, def.font, b->r, align, b->text, b->col.fg); + border(disp.ibuf, b->r, 1, b->col.border); } - copyimage(s->barwin, r, screen->ibuf, ZP); + copyimage(s->barwin, r, disp.ibuf, ZP); } Bar* diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c @@ -265,7 +265,7 @@ client_destroy(Client *c) { r = client_grav(c, ZR); hide = false; - if(!c->sel || c->sel->view != screen->sel) + if(!c->sel || c->sel->view != selview) hide = true; XGrabServer(display); @@ -312,8 +312,8 @@ client_viewframe(Client *c, View *v) { Client* selclient(void) { - if(screen->sel->sel->sel) - return screen->sel->sel->sel->client; + if(selview->sel->sel) + return selview->sel->sel->client; return nil; } @@ -471,7 +471,7 @@ focus(Client *c, bool user) { */ v = f->view; - if(v != screen->sel) + if(v != selview) view_focus(screen, v); frame_focus(c->sel); } @@ -488,9 +488,9 @@ client_focus(Client *c) { Dprint(DFocus, "client_focus([%C]%s)\n", c, clientname(c)); Dprint(DFocus, "\t[%C]%s\n\t=> [%C]%s\n", - screen->focus, clientname(screen->focus), + disp.focus, clientname(disp.focus), c, clientname(c)); - if(screen->focus != c) { + if(disp.focus != c) { if(c) { if(!c->noinput) setfocus(&c->w, RevertToParent); @@ -514,7 +514,7 @@ client_resize(Client *c, Rectangle r) { f = c->sel; frame_resize(f, r); - if(f->view != screen->sel) { + if(f->view != selview) { client_unmap(c, IconicState); unmap_frame(c); return; @@ -605,7 +605,7 @@ fullscreen(Client *c, int fullscreen) { for(f=c->frame; f; f=f->cnext) { if(f->oldarea == 0) { frame_resize(f, f->floatr); - if(f->view == screen->sel) /* FIXME */ + if(f->view == selview) /* FIXME */ client_resize(f->client, f->r); } @@ -642,7 +642,7 @@ client_seturgent(Client *c, bool urgent, int from) { c->urgent = urgent; ewmh_updatestate(c); if(c->sel) { - if(c->sel->view == screen->sel) + if(c->sel->view == selview) frame_draw(c->sel); for(f=c->frame; f; f=f->cnext) { SET(ff); @@ -856,7 +856,7 @@ enter_event(Window *w, XCrossingEvent *e) { c = w->aux; if(e->detail != NotifyInferior) { if(e->detail != NotifyVirtual) - if(e->serial != ignoreenter && screen->focus != c) { + if(e->serial != ignoreenter && disp.focus != c) { Dprint(DFocus, "enter_notify([%C]%s)\n", c, c->name); focus(c, false); } @@ -874,10 +874,10 @@ focusin_event(Window *w, XFocusChangeEvent *e) { print_focus("focusin_event", c, c->name); if(e->mode == NotifyGrab) - screen->hasgrab = c; + disp.hasgrab = c; - old = screen->focus; - screen->focus = c; + old = disp.focus; + disp.focus = c; if(c != old) { if(c->sel) frame_draw(c->sel); @@ -889,12 +889,12 @@ focusout_event(Window *w, XFocusChangeEvent *e) { Client *c; c = w->aux; - if((e->mode == NotifyWhileGrabbed) && (screen->hasgrab != &c_root)) { - if(screen->focus) - screen->hasgrab = screen->focus; - }else if(screen->focus == c) { + if((e->mode == NotifyWhileGrabbed) && (disp.hasgrab != &c_root)) { + if(disp.focus) + disp.hasgrab = disp.focus; + }else if(disp.focus == c) { print_focus("focusout_event", &c_magic, "<magic>"); - screen->focus = &c_magic; + disp.focus = &c_magic; if(c->sel) frame_draw(c->sel); } @@ -969,7 +969,7 @@ client_setviews(Client *c, char **tags) { if(*tags) { if(!*fp || cmp > 0) { f = frame_create(c, view_create(*tags)); - if(f->view == screen->sel || !c->sel) + if(f->view == selview || !c->sel) c->sel = f; kludge = c; /* FIXME */ view_attach(f->view, f); @@ -1111,7 +1111,7 @@ apply_tags(Client *c, const char *tags) { c->floating = add; else if(!strcmp(buf+n, "!") || !strcmp(buf+n, "sel")) - cur = screen->sel->name; + cur = selview->name; else if(!Mbsearch(buf+n, badtags, bsstrcmp)) cur = buf+n; diff --git a/cmd/wmii/column.c b/cmd/wmii/column.c @@ -481,7 +481,7 @@ column_frob(Area *a) { for(f=a->frame; f; f=f->anext) f->r = f->colr; column_settle(a); - if(a->view == screen->sel) + if(a->view == selview) for(f=a->frame; f; f=f->anext) client_resize(f->client, f->r); } @@ -563,7 +563,7 @@ column_arrange(Area *a, bool dirty) { /* XXX */ if(a->sel->collapsed) area_setsel(a, a->sel); - if(v == screen->sel) { + if(v == selview) { //view_restack(v); client_resize(a->sel->client, a->sel->r); for(f=a->frame; f; f=f->anext) diff --git a/cmd/wmii/dat.h b/cmd/wmii/dat.h @@ -324,12 +324,7 @@ enum { EXTERN struct WMScreen { Bar* bar[2]; - View* sel; - Client* focus; - Client* hasgrab; Window* barwin; - Image* ibuf; - Image* ibuf32; bool showing; int barpos; int idx; @@ -337,9 +332,19 @@ EXTERN struct WMScreen { Rectangle r; Rectangle brect; } **screens, *screen; +EXTERN uint nscreens; + +EXTERN struct { + Client* focus; + Client* hasgrab; + Image* ibuf; + Image* ibuf32; + bool sel; +} disp; EXTERN Client* client; EXTERN View* view; +EXTERN View* selview; EXTERN Key* key; EXTERN Divide* divs; EXTERN Client c_magic; @@ -361,10 +366,8 @@ EXTERN IxpServer srv; EXTERN Ixp9Srv p9srv; /* X11 */ -EXTERN uint nscreens; EXTERN uint valid_mask; EXTERN uint numlock_mask; -EXTERN bool sel_screen; EXTERN Image* ibuf; EXTERN Image* ibuf32; diff --git a/cmd/wmii/div.c b/cmd/wmii/div.c @@ -54,8 +54,8 @@ div_set(Divide *d, int x) { d->x = x; r = rectaddpt(divimg->r, Pt(x - Dx(divimg->r)/2, 0)); /* XXX: Multihead. */ - r.min.y = screen->sel->screenr.min.y; - r.max.y = screen->sel->screenr.max.y; + r.min.y = selview->screenr.min.y; + r.max.y = selview->screenr.max.y; reshapewin(d->w, r); mapdiv(d); @@ -92,7 +92,7 @@ update_imgs(void) { w = 2 * (labelh(def.font) / 3); w = max(w, 10); /* XXX: Multihead. */ - h = Dy(screen->sel->screenr); + h = Dy(selview->screenr); if(divimg) { if(w == Dx(divimg->r) && h == Dy(divimg->r) @@ -123,7 +123,7 @@ div_update_all(void) { update_imgs(); - v = screen->sel; + v = selview; dp = &divs; foreach_area(v, s, a) { d = getdiv(dp); diff --git a/cmd/wmii/event.c b/cmd/wmii/event.c @@ -174,7 +174,7 @@ enternotify(XCrossingEvent *ev) { if((w = findwin(ev->window))) handle(w, enter, ev); else if(ev->window == scr.root.w) { - sel_screen = true; + disp.sel = true; frame_draw_all(); } } @@ -184,16 +184,16 @@ leavenotify(XCrossingEvent *ev) { xtime = ev->time; if((ev->window == scr.root.w) && !ev->same_screen) { - sel_screen = true; + disp.sel = true; frame_draw_all(); } } void print_focus(const char *fn, Client *c, const char *to) { - Dprint(DFocus, "%s() screen->focus:\n", fn); - Dprint(DFocus, "\t%C => %C\n", screen->focus, c); - Dprint(DFocus, "\t%s => %s\n", clientname(screen->focus), to); + Dprint(DFocus, "%s() disp.focus:\n", fn); + Dprint(DFocus, "\t%C => %C\n", disp.focus, c); + Dprint(DFocus, "\t%s => %s\n", clientname(disp.focus), to); } static void @@ -204,7 +204,7 @@ focusin(XFocusChangeEvent *ev) { /* Yes, we're focusing in on nothing, here. */ if(ev->detail == NotifyDetailNone) { print_focus("focusin", &c_magic, "<magic[none]>"); - screen->focus = &c_magic; + disp.focus = &c_magic; setfocus(screen->barwin, RevertToParent); return; } @@ -215,22 +215,22 @@ focusin(XFocusChangeEvent *ev) { ||(ev->detail == NotifyInferior) ||(ev->detail == NotifyAncestor))) return; - if((ev->mode == NotifyWhileGrabbed) && (screen->hasgrab != &c_root)) + if((ev->mode == NotifyWhileGrabbed) && (disp.hasgrab != &c_root)) return; if(ev->window == screen->barwin->w) { print_focus("focusin", nil, "<nil>"); - screen->focus = nil; + disp.focus = nil; } else if((w = findwin(ev->window))) handle(w, focusin, ev); else if(ev->mode == NotifyGrab) { if(ev->window == scr.root.w) - screen->hasgrab = &c_root; + disp.hasgrab = &c_root; /* Some unmanaged window has grabbed focus */ - else if((c = screen->focus)) { + else if((c = disp.focus)) { print_focus("focusin", &c_magic, "<magic>"); - screen->focus = &c_magic; + disp.focus = &c_magic; if(c->sel) frame_draw(c->sel); } @@ -249,7 +249,7 @@ focusout(XFocusChangeEvent *ev) { ||(ev->detail == NotifyAncestor))) return; if(ev->mode == NotifyUngrab) - screen->hasgrab = nil; + disp.hasgrab = nil; if((ev->mode == NotifyGrab) && XCheckMaskEvent(display, KeyPressMask, &me)) diff --git a/cmd/wmii/ewmh.c b/cmd/wmii/ewmh.c @@ -312,7 +312,7 @@ ewmh_getstrut(Client *c) { Dprint(DEwmh, "\tright: %R\n", c->strut->right); Dprint(DEwmh, "\tbottom: %R\n", c->strut->bottom); free(strut); - view_update(screen->sel); + view_update(selview); } static void @@ -439,7 +439,7 @@ ewmh_updatestate(Client *c) { int i; f = c->sel; - if(f == nil || f->view != screen->sel) + if(f == nil || f->view != selview) return; i = 0; @@ -496,7 +496,7 @@ ewmh_updateview(void) { if(starting) return; - i = viewidx(screen->sel); + i = viewidx(selview); changeprop_long(&scr.root, Net("CURRENT_DESKTOP"), "CARDINAL", &i, 1); } diff --git a/cmd/wmii/float.c b/cmd/wmii/float.c @@ -53,7 +53,7 @@ float_detach(Frame *f) { void float_resizeframe(Frame *f, Rectangle r) { - if(f->area->view == screen->sel) + if(f->area->view == selview) client_resize(f->client, r); else frame_resize(f, r); @@ -100,12 +100,65 @@ rect_push(Vector_rect *vec, Rectangle r) { vector_rpush(vec, r); } +Vector_rect* +unique_rects(Vector_rect *vec, Rectangle orig) { + static Vector_rect vec1, vec2; + Vector_rect *v1, *v2, *v; + Rectangle r1, r2; + int i, j; + + v1 = &vec1; + v2 = &vec2; + v1->n = 0; + vector_rpush(v1, orig); + for(i=0; i < vec->n; i++) { + v2->n = 0; + r1 = vec->ary[i]; + for(j=0; j < v1->n; j++) { + r2 = v1->ary[j]; + if(!rect_intersect_p(r1, r2)) { + rect_push(v2, r2); + continue; + } + if(r2.min.x < r1.min.x) + rect_push(v2, Rect(r2.min.x, r2.min.y, r1.min.x, r2.max.y)); + if(r2.min.y < r1.min.y) + rect_push(v2, Rect(r2.min.x, r2.min.y, r2.max.x, r1.min.y)); + if(r2.max.x > r1.max.x) + rect_push(v2, Rect(r1.max.x, r2.min.y, r2.max.x, r2.max.y)); + if(r2.max.y > r1.max.y) + rect_push(v2, Rect(r2.min.x, r1.max.y, r2.max.x, r2.max.y)); + } + v = v1; + v1 = v2; + v2 = v; + } + return v1; +} + +Rectangle +max_rect(Vector_rect *vec) { + Rectangle *r, *rp; + int i, a, area; + + area = 0; + r = 0; + for(i=0; i < vec->n; i++) { + rp = &vec->ary[i]; + a = Dx(*rp) * Dy(*rp); + if(a > area) { + area = a; + r = rp; + } + } + return r ? *r : ZR; +} + static void float_placeframe(Frame *f) { - static Vector_rect rvec, rvec2; - Vector_rect *vp, *vp2, *vptemp; - Rectangle *rp; - Rectangle r, fr; + static Vector_rect vec; + Vector_rect *vp; + Rectangle r; Point dim, p; Client *c; Frame *ff; @@ -125,49 +178,36 @@ float_placeframe(Frame *f) { return; } - dim.x = Dx(f->r); - dim.y = Dy(f->r); - - rvec.n = 0; - rvec2.n = 0; - vp = &rvec; - vp2 = &rvec2; - /* Find all rectangles on the floating layer into which * the new frame would fit. */ - vector_rpush(vp, a->r); - for(ff=a->frame; ff; ff=ff->anext) { - /* TODO: Find out why this is needed. + vec.n = 0; + for(ff=a->frame; ff; ff=ff->anext) + /* TODO: Find out why this check is needed. * The frame hasn't been inserted yet, but somehow, * its old rectangle winds up in the list. */ - if(ff->client == f->client) + if(ff->client != f->client) + vector_rpush(&vec, ff->r); + vp = unique_rects(&vec, a->r); + + area = LONG_MAX; + dim.x = Dx(f->r); + dim.y = Dy(f->r); + p = ZP; + + for(i=0; i < vp->n; i++) { + r = vp->ary[i]; + if(Dx(r) < dim.x || Dy(r) < dim.y) continue; - fr = ff->r; - vp2->n = 0; - for(i=0; i < vp->n; i++) { - r = vp->ary[i]; - if(!rect_intersect_p(fr, r)) { - rect_push(vp2, r); - continue; - } - if(r.min.x < fr.min.x && fr.min.x - r.min.x >= dim.x) - rect_push(vp2, Rect(r.min.x, r.min.y, fr.min.x, r.max.y)); - if(r.max.x > fr.max.x && r.max.x - fr.max.x >= dim.x) - rect_push(vp2, Rect(fr.max.x, r.min.y, r.max.x, r.max.y)); - if(r.min.y < fr.min.y && fr.min.y - r.min.y >= dim.y) - rect_push(vp2, Rect(r.min.x, r.min.y, r.max.x, fr.min.y)); - if(r.max.y > fr.max.y && r.max.y - fr.max.y >= dim.y) - rect_push(vp2, Rect(r.min.x, fr.max.y, r.max.x, r.max.y)); + l = Dx(r) * Dy(r); + if(l < area) { + area = l; + p = r.min; } - vptemp = vp; - vp = vp2; - vp2 = vptemp; } - p = ZP; - if(vp->n == 0) { + if(area == LONG_MAX) { /* Cascade. */ ff = a->sel; if(ff) @@ -175,16 +215,6 @@ float_placeframe(Frame *f) { if(p.x + Dx(f->r) > Dx(screen->r) || p.y + Dy(f->r) > screen->brect.min.y) p = ZP; - }else { - area = LONG_MAX; - for(i=0; i < vp->n; i++) { - rp = &vp->ary[i]; - l = Dx(*rp) * Dy(*rp); - if(l < area) { - area = l; - p = rp->min; - } - } } f->floatr = rectsetorigin(f->r, p); diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h @@ -139,6 +139,8 @@ void float_arrange(Area*); void float_attach(Area*, Frame*); void float_detach(Frame*); void float_resizeframe(Frame*, Rectangle); +Vector_rect* unique_rects(Vector_rect*, Rectangle); +Rectangle max_rect(Vector_rect*); /* frame.c */ Frame* frame_create(Client*, View*); diff --git a/cmd/wmii/frame.c b/cmd/wmii/frame.c @@ -210,7 +210,7 @@ enter_event(Window *w, XCrossingEvent *e) { c = w->aux; f = c->sel; - if(screen->focus != c || selclient() != c) { + if(disp.focus != c || selclient() != c) { Dprint(DFocus, "enter_notify(f) => [%C]%s%s\n", f->client, f->client->name, ignoreenter == e->serial ? " (ignored)" : ""); if(e->detail != NotifyInferior) @@ -425,7 +425,7 @@ frame_draw(Frame *f) { uint w; int n, m; - if(f->view != screen->sel) + if(f->view != selview) return; if(f->area == nil) /* Blech. */ return; @@ -435,7 +435,7 @@ frame_draw(Frame *f) { fr = rectsetorigin(c->framewin->r, ZP); /* Pick colors. */ - if(c == selclient() || c == screen->focus) + if(c == selclient() || c == disp.focus) col = &def.focuscolor; else col = &def.normcolor; @@ -454,7 +454,7 @@ frame_draw(Frame *f) { /* Odd focus. Unselected, with keyboard focus. */ /* Draw a border just inside the titlebar. */ - if(c != selclient() && c == screen->focus) { + if(c != selclient() && c == disp.focus) { border(img, insetrect(r, 1), 1, def.normcolor.bg); border(img, insetrect(r, 2), 1, def.focuscolor.border); } @@ -471,7 +471,7 @@ frame_draw(Frame *f) { /* Odd focus. Selected, without keyboard focus. */ /* Draw a border around the grabbox. */ - if(c != screen->focus && col == &def.focuscolor) + if(c != disp.focus && col == &def.focuscolor) border(img, insetrect(r, -1), 1, def.normcolor.bg); /* Draw a border on borderless+titleless selected apps. */ @@ -535,7 +535,7 @@ frame_draw_all(void) { Client *c; for(c=client; c; c=c->next) - if(c->sel && c->sel->view == screen->sel) + if(c->sel && c->sel->view == selview) frame_draw(c->sel); } @@ -574,7 +574,7 @@ move_focus(Frame *old_f, Frame *f) { noinput = (old_f && old_f->client->noinput) || (f && f->client->noinput) || - screen->hasgrab != &c_root; + disp.hasgrab != &c_root; if(noinput) { if(old_f) frame_draw(old_f); @@ -616,7 +616,7 @@ frame_focus(Frame *f) { if(old_a != v->oldsel && f != old_f) v->oldsel = nil; - if(v != screen->sel || a != v->sel) + if(v != selview || a != v->sel) return; move_focus(old_f, f); diff --git a/cmd/wmii/fs.c b/cmd/wmii/fs.c @@ -278,11 +278,11 @@ lookup_file(IxpFileId *parent, char *name) break; case FsDTags: if(!name || !strcmp(name, "sel")) { - if(screen->sel) { + if(selview) { push_file("sel"); file->volatil = true; - file->p.view = screen->sel; - file->id = screen->sel->id; + file->p.view = selview; + file->id = selview->id; }if(name) goto LastItem; } for(v=view; v; v=v->next) { diff --git a/cmd/wmii/key.c b/cmd/wmii/key.c @@ -153,7 +153,7 @@ fake_keypress(ulong mod, KeyCode key) { XKeyEvent e; Client *c; - c = screen->focus; + c = disp.focus; if(c == nil || c->w.w == 0) return; diff --git a/cmd/wmii/layout.c b/cmd/wmii/layout.c @@ -102,7 +102,7 @@ expose_event(Window *w, XExposeEvent *e) { f = w->aux; c = &def.focuscolor; - buf = screen->ibuf; + buf = disp.ibuf; r = rectsubpt(w->r, w->r.min); fill(buf, r, c->bg); @@ -123,10 +123,10 @@ find_area(Point pt) { Area *a; int s; - v = screen->sel; + v = selview; /* XXX: Multihead. Check this over. */ for(s=0; s < nscreens; s++) { - if(!rect_haspoint_p(pt, screen[s].r)) + if(!rect_haspoint_p(pt, screens[s]->r)) continue; for(a=v->areas[s]; a; a=a->next) if(pt.x < a->r.max.x) @@ -145,7 +145,7 @@ vplace(Framewin *fw, Point pt) { long l; int hr; - v = screen->sel; + v = selview; a = find_area(pt); if(a == nil) @@ -196,7 +196,7 @@ hplace(Framewin *fw, Point pt) { View *v; int minw; - v = screen->sel; + v = selview; a = find_area(pt); if(a == nil) diff --git a/cmd/wmii/main.c b/cmd/wmii/main.c @@ -191,6 +191,8 @@ init_screens(void) { ibuf32 = nil; /* Probably shouldn't do this until it's needed. */ if(render_visual) ibuf32 = allocimage(Dx(scr.rect), Dy(scr.rect), 32); + disp.ibuf = ibuf; + disp.ibuf32 = ibuf32; /* Resize and initialize screens. */ for(i=0; i < nscreens; i++) { @@ -202,14 +204,13 @@ init_screens(void) { screen->r = rects[i]; else screen->r = rectsetorigin(screen->r, scr.rect.max); + print("screens[%d]->r = %R\n", i, screens[i]->r); def.snap = Dy(screen->r) / 63; - screen->ibuf = ibuf; - screen->ibuf32 = ibuf32; bar_init(screens[i]); } screen = screens[0]; - if(screen->sel) - view_update(screen->sel); + if(selview) + view_update(selview); } static void @@ -397,7 +398,7 @@ extern int fmtevent(Fmt*); loadcolor(&def.focuscolor, FOCUSCOLORS); loadcolor(&def.normcolor, NORMCOLORS); - sel_screen = pointerscreen(); + disp.sel = pointerscreen(); init_screens(); @@ -411,7 +412,7 @@ extern int fmtevent(Fmt*); CWEventMask | CWCursor); - screen->focus = nil; + disp.focus = nil; setfocus(screen->barwin, RevertToParent); view_select("1"); @@ -421,7 +422,7 @@ extern int fmtevent(Fmt*); view_update_all(); ewmh_updateviews(); - event("FocusTag %s\n", screen->sel->name); + event("FocusTag %s\n", selview->name); i = ixp_serverloop(&srv); if(i) diff --git a/cmd/wmii/message.c b/cmd/wmii/message.c @@ -445,13 +445,13 @@ message_root(void *p, IxpMsg *m) { s = msg_getword(m); if(!setdef(&screen->barpos, s, barpostab, nelem(barpostab))) return Ebadvalue; - view_update(screen->sel); + view_update(selview); break; case LBORDER: if(!getulong(msg_getword(m), &n)) return Ebadvalue; def.border = n; - view_update(screen->sel); + view_update(selview); break; case LCOLMODE: s = msg_getword(m); @@ -467,7 +467,7 @@ message_root(void *p, IxpMsg *m) { break; case LFOCUSCOLORS: ret = msg_parsecolors(m, &def.focuscolor); - view_update(screen->sel); + view_update(selview); break; case LFONT: fn = loadfont(m->pos); @@ -478,7 +478,7 @@ message_root(void *p, IxpMsg *m) { bar_resize(screens[n]); }else ret = "can't load font"; - view_update(screen->sel); + view_update(selview); break; case LGRABMOD: s = msg_getword(m); @@ -493,11 +493,11 @@ message_root(void *p, IxpMsg *m) { case LINCMODE: if(!setdef(&def.incmode, msg_getword(m), incmodetab, nelem(incmodetab))) return Ebadvalue; - view_update(screen->sel); + view_update(selview); break; case LNORMCOLORS: ret = msg_parsecolors(m, &def.normcolor); - view_update(screen->sel); + view_update(selview); break; case LSELCOLORS: warning("selcolors have been removed"); @@ -546,7 +546,7 @@ readctl_root(void) { bufprint("grabmod %s\n", def.grabmod); bufprint("incmode %s\n", incmodetab[screen->barpos]); bufprint("normcolors %s\n", def.normcolor.colstr); - bufprint("view %s\n", screen->sel->name); + bufprint("view %s\n", selview->name); return buffer; } @@ -978,7 +978,7 @@ msg_selectframe(Frame *f, IxpMsg *m, int sym) { frame_focus(fp); frame_restack(fp, nil); - if(fp->view == screen->sel) + if(fp->view == selview) view_restack(fp->view); return nil; } diff --git a/cmd/wmii/mouse.c b/cmd/wmii/mouse.c @@ -216,7 +216,7 @@ mouse_resizecolframe(Frame *f, Align align) { f->collapsed = false; - v = screen->sel; + v = selview; d = divs; for(a=v->firstarea; a != f->area; a=a->next) d = d->next; @@ -318,7 +318,7 @@ mouse_resizecol(Divide *d) { Point pt; uint minw; - v = screen->sel; + v = selview; for(a = v->firstarea, dp = divs; a; a = a->next, dp = dp->next) if(dp->next == d) break; diff --git a/cmd/wmii/view.c b/cmd/wmii/view.c @@ -28,10 +28,10 @@ empty_p(View *v) { static void _view_select(View *v) { - if(screen->sel != v) { - if(screen->sel) - event("UnfocusTag %s\n",screen->sel->name); - screen->sel = v; + if(selview != v) { + if(selview) + event("UnfocusTag %s\n",selview->name); + selview = v; event("FocusTag %s\n", v->name); event("AreaFocus %a\n", v->sel); ewmh_updateview(); @@ -96,7 +96,7 @@ view_create(const char *name) { apply_tags(c, c->tags); view_arrange(v); - if(!screen->sel) + if(!selview) _view_select(v); ewmh_updateviews(); return v; @@ -140,7 +140,7 @@ view_destroy(View *v) { event("DestroyTag %s\n", v->name); - if(v == screen->sel) { + if(v == selview) { for(tv=view; tv; tv=tv->next) if(tv->next == *vp) break; if(tv == nil) @@ -200,39 +200,32 @@ fix_rect(Rectangle old, Rectangle new) { void view_update_rect(View *v) { - Rectangle r, sr, brect, scrnr; + static Vector_rect vec; + static Vector_rect *vp; + Rectangle r, sr, rr, brect, scrnr; WMScreen *scrn; Strut *strut; Frame *f; - int left, right, top, bottom; - int s; + int s, i; + /* These short variable names are hell, eh? */ /* XXX: - * Incidentally, really need to move screen->sel elsewhere. - if(v != screen->sel) + if(v != selview) return false; */ - - - top = 0; - left = 0; - right = 0; - bottom = 0; + vec.n = 0; for(f=v->floating->frame; f; f=f->anext) { strut = f->client->strut; if(!strut) continue; - /* Can do better in the future. */ - top = max(top, strut->top.max.y); - left = max(left, strut->left.max.x); - right = min(right, strut->right.min.x); - bottom = min(bottom, strut->bottom.min.y); + vector_rpush(&vec, strut->top); + vector_rpush(&vec, strut->left); + vector_rpush(&vec, rectaddpt(strut->right, Pt(scr.rect.max.x, 0))); + vector_rpush(&vec, rectaddpt(strut->bottom, Pt(0, scr.rect.max.y))); } - scrnr = scr.rect; - scrnr.min.y += top; - scrnr.min.x += left; - scrnr.max.x += right; - scrnr.max.y += bottom; + /* Find the largest screen space not occupied by struts. */ + vp = unique_rects(&vec, scr.rect); + scrnr = max_rect(vp); /* FIXME: Multihead. */ v->floating->r = scr.rect; @@ -241,33 +234,33 @@ view_update_rect(View *v) { scrn = screens[s]; r = fix_rect(scrn->r, scrnr); + /* Ugly. Very, very ugly. */ + /* + * Try to find some rectangle near the edge of the + * screen where the bar will fit. This way, for + * instance, a system tray can be placed there + * without taking up too much extra screen real + * estate. + */ + rr = r; + brect = scrn->brect; + for(i=0; i < vp->n; i++) { + sr = rect_intersection(vp->ary[i], scrn->r); + if(Dx(sr) < Dx(r)/2 || Dy(sr) < Dy(brect)) + continue; + if(scrn->barpos == BTop && sr.min.y < rr.min.y + || scrn->barpos != BTop && sr.max.y > rr.max.y) + rr = sr; + } if(scrn->barpos == BTop) { - bar_sety(scrn, r.min.y); - r.min.y += Dy(scrn->brect); + bar_sety(scrn, rr.min.y); + r.min.y = max(r.min.y, scrn->brect.max.y); }else { - r.max.y -= Dy(scrn->brect); - bar_sety(scrn, r.max.y); + bar_sety(scrn, rr.max.y - Dy(brect)); + r.max.y = min(r.max.y, scrn->brect.min.y); } - + bar_setbounds(scrn, rr.min.x, rr.max.x); v->r[s] = r; - - brect = scrn->brect; - brect.min.x = r.min.x; - brect.max.x = r.max.x; - for(f=v->floating->frame; f; f=f->anext) { - /* This is not pretty. :( */ - strut = f->client->strut; - if(!strut) - continue; - sr = strut->left; - if(rect_intersect_p(brect, sr)) - brect.min.x = sr.max.x; - sr = rectaddpt(strut->right, Pt(scr.rect.max.x, 0)); - if(rect_intersect_p(brect, sr)) - brect.max.x = sr.min.x; - } - - bar_setbounds(scrn, brect.min.x, brect.max.x); } } @@ -279,7 +272,7 @@ view_update(View *v) { bool fscrn; int s; - if(v != screen->sel) + if(v != selview) return; if(starting) return; @@ -410,7 +403,7 @@ view_detach(Frame *f) { if(c->sel == f) c->sel = f->cnext; - if(v == screen->sel) + if(v == selview) view_update(v); else if(empty_p(v)) view_destroy(v); @@ -436,7 +429,7 @@ view_restack(View *v) { Area *a; bool fscrn; - if(v != screen->sel) + if(v != selview) return; wins.n = 0; @@ -543,7 +536,7 @@ view_arrange(View *v) { a->r.max.y = v->r[s].max.y; column_arrange(a, false); } - if(v == screen->sel) + if(v == selview) div_update_all(); } @@ -571,7 +564,7 @@ void view_update_all(void) { View *n, *v, *old; - old = screen->sel; + old = selview; for(v=view; v; v=v->next) frames_update_sel(v); @@ -581,7 +574,7 @@ view_update_all(void) { view_destroy(v); } - view_update(screen->sel); + view_update(selview); } uint