wmii

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

commit ced1e98afff11de8fe66ba7720472a0c2cce4659
parent c6d176984846648f2b63d4816380520d0e4f3f9c
Author: Kris Maglione <jg@suckless.org>
Date:   Sat, 10 Feb 2007 20:09:11 -0500

Fixed a lot of focus code, including a segfault.


Diffstat:
area.c | 68++++++++++++++++++++++++++++++++++++--------------------------------
client.c | 49+++----------------------------------------------
frame.c | 47+++++++++++++++++++++++++++++++++++++++++++++++
mouse.c | 5+++--
view.c | 8+++-----
wmii.h | 2+-
6 files changed, 93 insertions(+), 86 deletions(-)

diff --git a/area.c b/area.c @@ -65,11 +65,11 @@ create_area(View *v, Area *pos, unsigned int w) { a->next = *p; *p = a; + if(!v->sel || (v->sel->floating && v->area->next == a && a->next == nil)) + focus_area(a); + if(i) write_event("CreateColumn %d\n", i); - - focus_area(a); - return a; } @@ -119,7 +119,7 @@ send_to_area(Area *to, Area *from, Frame *f) { void attach_to_area(Area *a, Frame *f, Bool send) { - unsigned int h, n_frame; + unsigned int w, h, n_frame; Frame *ft; Client *c; View *v; @@ -128,6 +128,15 @@ attach_to_area(Area *a, Frame *f, Bool send) { c = f->client; h = 0; + if(!a->floating && !send) { + w = newcolw_of_view(v); + if(w && v->area->next->frame) { + a = new_column(v, a, w); + arrange_view(v); + } + } + f->area = a; + n_frame = 1; for(ft=a->frame; ft; ft=ft->anext) n_frame++; @@ -138,28 +147,22 @@ attach_to_area(Area *a, Frame *f, Bool send) { if(a->frame) scale_column(a, a->rect.height - h); } - if(!send && !a->floating) { /* column */ - unsigned int w = newcolw_of_view(v); - if(v->area->next->frame && w) { - a = new_column(v, a, w); - arrange_view(v); - } - } - f->area = a; if(a->sel) insert_frame(nil, f, False); else insert_frame(a->sel, f, False); - if(!c->floating) /* column */ + + if(!a->floating) f->rect.height = h; - else /* floating */ + else place_client(a, c); - focus_client(f->client, False); + focus_frame(f, False); if(!a->floating) arrange_column(a, False); update_client_grab(f->client); + assert(a->sel); } void @@ -208,7 +211,8 @@ detach_from_area(Area *a, Frame *f) { } else if(v->area->next->frame) focus_area(v->area->next); - } + }else + assert(a->sel); } static void @@ -323,27 +327,27 @@ focus_area(Area *a) { return; v->sel = a; - if(v != screen->sel) - return; if(f) - XSetInputFocus(blz.dpy, f->client->win, RevertToPointerRoot, CurrentTime); - else - XSetInputFocus(blz.dpy, blz.root, RevertToPointerRoot, CurrentTime); - - if(f) { update_frame_widget_colors(f); - draw_frame(f); - } if(old_a) { - if(old_a->sel) { + if(old_a->sel) update_frame_widget_colors(old_a->sel); - draw_frame(old_a->sel); - } if(a->floating != old_a->floating) v->revert = old_a; } + if(v != screen->sel) + return; + + if(f) { + draw_frame(f); + XSetInputFocus(blz.dpy, f->client->win, RevertToPointerRoot, CurrentTime); + }else + XSetInputFocus(blz.dpy, blz.root, RevertToPointerRoot, CurrentTime); + + if(old_a && old_a->sel) + draw_frame(old_a->sel); if(a != old_a) { i = 0; @@ -388,13 +392,13 @@ select_area(Area *a, char *arg) { return Ebadvalue; for(p=a->frame; p->anext; p=p->anext) if(p->anext == f) break; - goto focus_client; + goto focus_frame; } else if(!strncmp(arg, "down", 5)) { if(!f) return Ebadvalue; p = f->anext ? f->anext : a->frame; - goto focus_client; + goto focus_frame; } else { if(sscanf(arg, "%d", &i) != 1) @@ -405,9 +409,9 @@ select_area(Area *a, char *arg) { focus_area(new); return nil; -focus_client: +focus_frame: frame_to_top(p); - focus_client(p->client, False); + focus_frame(p, False); if(v == screen->sel) restack_view(v); flush_masked_events(EnterWindowMask); diff --git a/client.c b/client.c @@ -80,7 +80,7 @@ manage_client(Client *c) { update_views(); XSync(blz.dpy, False); if(c->sel->area->view == screen->sel) - focus_client(c, False); + focus(c, True); flush_masked_events(EnterWindowMask); } @@ -161,51 +161,8 @@ focus(Client *c, Bool restack) { if(!(f = c->sel)) return; v = f->area->view; arrange_column(f->area, False); - focus_client(c, restack); focus_view(screen, v); -} - -void -focus_client(Client *c, Bool restack) { - Client *old; - Frame *f, *old_f; - View *v; - Area *a, *old_a; - - f = c->sel; - a = f->area; - v = f->view; - old = sel_client(); - old_a = nil; - if(old) { - old_f = old->sel; - old_a = old_f->area; - } - - a->sel = f; - if(!a->floating && (a->mode == Colstack)) - arrange_column(a, False); - - if(v != screen->sel) - return; - - if(f->area != old_a) - focus_area(f->area); - else { - XSetInputFocus(blz.dpy, f->client->win, RevertToPointerRoot, CurrentTime); - update_frame_widget_colors(f); - draw_frame(f); - if(old) { - update_frame_widget_colors(old_f); - draw_frame(old_f); - } - } - - if(c != old) - write_event("ClientFocus 0x%x\n", c->win); - - if(restack) - restack_view(v); + focus_frame(c->sel, restack); } void @@ -654,7 +611,7 @@ send_client(Frame *f, char *arg) { }else return Ebadvalue; flush_masked_events(EnterWindowMask); - focus_client(f->client, True); + focus_frame(f, True); update_views(); return nil; } diff --git a/frame.c b/frame.c @@ -158,6 +158,53 @@ swap_frames(Frame *fa, Frame *fb) { } void +focus_frame(Frame *f, Bool restack) { + Frame *old, *old_in_a; + View *v; + Area *a, *old_a; + + a = f->area; + v = f->view; + old = v->sel->sel; + old_a = v->sel; + old_in_a = a->sel; + + a->sel = f; + if(!a->floating && (a->mode == Colstack)) + arrange_column(a, False); + + if(a != old_a) + focus_area(f->area); + else { + update_frame_widget_colors(f); + if(old) + update_frame_widget_colors(old); + } + + if(old_in_a) + update_frame_widget_colors(old_in_a); + + if(v != screen->sel) + return; + + if(a == old_a) { + XSetInputFocus(blz.dpy, f->client->win, RevertToPointerRoot, CurrentTime); + draw_frame(f); + } + else if(old_in_a) + draw_frame(old_in_a); + + if(f != old) { + if(old) + draw_frame(old); + write_event("ClientFocus 0x%x\n", f->client->win); + } + + if(restack) + restack_view(v); +} + +void update_frame_widget_colors(Frame *f) { if(f->area->sel == f) { if(sel_screen && (f->client == sel_client())) diff --git a/mouse.c b/mouse.c @@ -432,9 +432,10 @@ do_mouse_resize(Client *c, Bool grabbox, BlitzAlign align) { match_sizehints(c, &frect, floating, grav); - if(grabbox) + if(grabbox) { resize_client(c, &frect); - else { + XSync(blz.dpy, False); + } else { draw_xor_border(&ofrect); draw_xor_border(&frect); } diff --git a/view.c b/view.c @@ -125,10 +125,7 @@ focus_view(WMScreen *s, View *v) { unmap_client(c, IconicState); } } - if((c = sel_client())) - focus_client(c, True); - else - XSetInputFocus(blz.dpy, blz.root, RevertToPointerRoot, CurrentTime); + focus_area(v->sel); draw_frames(); XSync(blz.dpy, False); XUngrabServer(blz.dpy); @@ -412,7 +409,8 @@ newcolw_of_view(View *v) { char *toks[16]; strncpy(buf, r->value, sizeof(buf)); n = ixp_tokenize(toks, 16, buf, '+'); - for(a=v->area, i=0; a; a=a->next, i++); + for(a=v->area, i=0; a; a=a->next) + i++; if(n && n >= i) { if(sscanf(toks[i - 1], "%u", &n) == 1) return (screen->rect.width * n) / 100; diff --git a/wmii.h b/wmii.h @@ -277,7 +277,6 @@ extern void unmap_client(Client *c, int state); extern void map_client(Client *c); extern void reparent_client(Client *c, Window w, int x, int y); extern void manage_client(Client *c); -extern void focus_client(Client *c, Bool restack); extern void focus(Client *c, Bool restack); extern void resize_client(Client *c, XRectangle *r); extern void match_sizehints(Client *c, XRectangle *r, Bool floating, BlitzAlign sticky); @@ -327,6 +326,7 @@ extern void insert_frame(Frame *pos, Frame *f, Bool before); extern void resize_frame(Frame *f, XRectangle *r); extern Bool frame_to_top(Frame *f); extern void swap_frames(Frame *fa, Frame *fb); +extern void focus_frame(Frame *f, Bool restack); extern void draw_frame(Frame *f); extern void draw_frames(); extern void update_frame_widget_colors(Frame *f);