[hackers] [wmii] Fixed a lot of focus code, including a segfault.

From: Kris Maglione <jg_AT_suckless.org>
Date: Sun Feb 11 02:10:29 2007

changeset: 1834:9ef7f6580de7
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Feb 10 20:09:11 2007 -0500
summary: Fixed a lot of focus code, including a segfault.

diff -r 42bcccb70b9f -r 9ef7f6580de7 area.c
--- a/area.c Sat Feb 10 15:13:35 2007 -0500
+++ b/area.c Sat Feb 10 20:09:11 2007 -0500
@@ -65,11 +65,11 @@ create_area(View *v, Area *pos, unsigned
         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
 
 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;
@@ -127,6 +127,15 @@ attach_to_area(Area *a, Frame *f, Bool s
         v = a->view;
         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)
@@ -138,28 +147,22 @@ attach_to_area(Area *a, Frame *f, Bool s
                 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(f)
+ update_frame_widget_colors(f);
+ if(old_a) {
+ if(old_a->sel)
+ update_frame_widget_colors(old_a->sel);
+ if(a->floating != old_a->floating)
+ v->revert = old_a;
+ }
+
         if(v != screen->sel)
                 return;
 
- if(f)
+ if(f) {
+ draw_frame(f);
                 XSetInputFocus(blz.dpy, f->client->win, RevertToPointerRoot, CurrentTime);
- else
+ }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) {
- update_frame_widget_colors(old_a->sel);
- draw_frame(old_a->sel);
- }
- if(a->floating != old_a->floating)
- v->revert = old_a;
- }
-
+ 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 -r 42bcccb70b9f -r 9ef7f6580de7 client.c
--- a/client.c Sat Feb 10 15:13:35 2007 -0500
+++ b/client.c Sat Feb 10 20:09:11 2007 -0500
@@ -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 -r 42bcccb70b9f -r 9ef7f6580de7 frame.c
--- a/frame.c Sat Feb 10 15:13:35 2007 -0500
+++ b/frame.c Sat Feb 10 20:09:11 2007 -0500
@@ -155,6 +155,53 @@ swap_frames(Frame *fa, Frame *fb) {
         trect = fa->rect;
         fa->rect = fb->rect;
         fb->rect = trect;
+}
+
+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
diff -r 42bcccb70b9f -r 9ef7f6580de7 mouse.c
--- a/mouse.c Sat Feb 10 15:13:35 2007 -0500
+++ b/mouse.c Sat Feb 10 20:09:11 2007 -0500
@@ -432,9 +432,10 @@ do_mouse_resize(Client *c, Bool grabbox,
 
                         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 -r 42bcccb70b9f -r 9ef7f6580de7 view.c
--- a/view.c Sat Feb 10 15:13:35 2007 -0500
+++ b/view.c Sat Feb 10 20:09:11 2007 -0500
@@ -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 -r 42bcccb70b9f -r 9ef7f6580de7 wmii.h
--- a/wmii.h Sat Feb 10 15:13:35 2007 -0500
+++ b/wmii.h Sat Feb 10 20:09:11 2007 -0500
@@ -277,7 +277,6 @@ extern void map_client(Client *c);
 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 resize_frame(Frame *f, XRect
 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);
Received on Sun Feb 11 2007 - 02:10:29 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:55:09 UTC