[hackers] [wmii] Don't segfault when trying to grab the first or last column devider.

From: Kris Maglione <jg_AT_suckless.org>
Date: Sat Apr 14 10:39:26 2007

changeset: 2072:2eb64322ff5b
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Apr 14 04:37:38 2007 -0400
summary: Don't segfault when trying to grab the first or last column devider.

diff -r b2b73f1fd3a0 -r 2eb64322ff5b cmd/wmii/client.c
--- a/cmd/wmii/client.c Sat Apr 14 03:03:06 2007 -0400
+++ b/cmd/wmii/client.c Sat Apr 14 04:37:38 2007 -0400
@@ -680,38 +680,6 @@ newcol_client(Client *c, char *arg) {
         flushevents(EnterWindowMask, False);
 }
 
-void
-move_client(Client *c, char *arg) {
- Frame *f = c->sel;
- XRectangle new = f->rect;
- int x, y;
-
- if(sscanf(arg, "%d %d", &x, &y) != 2)
- return;
- new.x += x;
- new.y += y;
- if(!f->area->floating)
- resize_column(f->client->sel, &new);
- else
- resize_client(f->client, &new);
-}
-
-void
-size_client(Client *c, char *arg) {
- Frame *f = c->sel;
- XRectangle new = f->rect;
- int w, h;
-
- if(sscanf(arg, "%d %d", &w, &h) != 2)
- return;
- new.width += w;
- new.height += h;
- if(!f->area->floating)
- resize_column(f->client->sel, &new);
- else
- resize_client(f->client, &new);
-}
-
 char *
 send_client(Frame *f, char *arg, Bool swap) {
         Area *to, *a;
diff -r b2b73f1fd3a0 -r 2eb64322ff5b cmd/wmii/column.c
--- a/cmd/wmii/column.c Sat Apr 14 03:03:06 2007 -0400
+++ b/cmd/wmii/column.c Sat Apr 14 04:37:38 2007 -0400
@@ -349,6 +349,7 @@ resize:
         if(a->view == screen->sel) {
                 restack_view(a->view);
                 resize_client(a->sel->client, &a->sel->rect);
+
                 for(f=a->frame; f; f=f->anext)
                         if(!f->collapsed && f != a->sel)
                                 resize_client(f->client, &f->rect);
diff -r b2b73f1fd3a0 -r 2eb64322ff5b cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Sat Apr 14 03:03:06 2007 -0400
+++ b/cmd/wmii/mouse.c Sat Apr 14 04:37:38 2007 -0400
@@ -17,7 +17,9 @@ enum {
 
 static void
 rect_morph_xy(XRectangle *rect, int dx, int dy, BlitzAlign *mask) {
- BlitzAlign new_mask = 0;
+ BlitzAlign nmask;
+
+ nmask = 0;
         if(*mask & NORTH) {
                 if(rect->height - dy >= 0 || *mask & SOUTH) {
                         rect->y += dy;
@@ -26,7 +28,7 @@ rect_morph_xy(XRectangle *rect, int dx,
                 else {
                         rect->y += rect->height;
                         rect->height = dy - rect->height;
- new_mask ^= NORTH|SOUTH;
+ nmask ^= NORTH|SOUTH;
                 }
         }
         if(*mask & SOUTH) {
@@ -35,7 +37,7 @@ rect_morph_xy(XRectangle *rect, int dx,
                 else {
                         rect->height = -dy - rect->height;
                         rect->y -= rect->height;
- new_mask ^= NORTH|SOUTH;
+ nmask ^= NORTH|SOUTH;
                 }
         }
         if(*mask & EAST) {
@@ -44,7 +46,7 @@ rect_morph_xy(XRectangle *rect, int dx,
                 else {
                         rect->width = -dx - rect->width;
                         rect->x -= rect->width;
- new_mask ^= EAST|WEST;
+ nmask ^= EAST|WEST;
                 }
         }
         if(*mask & WEST) {
@@ -55,10 +57,10 @@ rect_morph_xy(XRectangle *rect, int dx,
                 else {
                         rect->x += rect->width;
                         rect->width = dx - rect->width;
- new_mask ^= EAST|WEST;
- }
- }
- *mask ^= new_mask;
+ nmask ^= EAST|WEST;
+ }
+ }
+ *mask ^= nmask;
 }
 
 typedef struct {
@@ -198,23 +200,24 @@ find_droppoint(Frame *frame, int x, int
         enum { Delta = 5 };
         View *v;
         Area *a, *a_prev;
- Frame *f, *f_prev;
+ Frame *f;
         Bool before;
 
         v = frame->view;
- rect->y = 0;
- rect->height = screen->rect.height - screen->brect.height;
-
+
+ /* New column? */
         a_prev = v->area;
         for(a = a_prev->next; a && a->next; a = a->next) {
                 if(x < r_east(&a->rect))
                         break;
                 a_prev = a;
         }
+
+ rect->y = 0;
+ rect->height = screen->rect.height - screen->brect.height;
+ rect->width = 2 * Delta;
         if(x < (a->rect.x + labelh(&def.font))) {
                 rect->x = a->rect.x - Delta;
- rect->width = 2 * Delta;
-
                 if(do_move) {
                         a = new_column(v, a_prev, 0);
                         send_to_area(a, frame);
@@ -224,8 +227,6 @@ find_droppoint(Frame *frame, int x, int
         }
         if(x > (r_east(&a->rect) - labelh(&def.font))) {
                 rect->x = r_east(&a->rect) - Delta;
- rect->width = 2 * Delta;
-
                 if(do_move) {
                         a = new_column(v, a, 0);
                         send_to_area(a, frame);
@@ -234,23 +235,20 @@ find_droppoint(Frame *frame, int x, int
                 return;
         }
 
+ /* Over/under frame? */
+ for(f = a->frame; f; f = f->anext) {
+ if(y < f->rect.y)
+ break;
+ if(y < r_south(&f->rect))
+ break;
+ }
+
         rect->x = a->rect.x;
         rect->width = a->rect.width;
-
- f_prev = nil;
- for(f = a->frame; f; f = f->anext) {
- if(y < f->rect.y)
- break;
- if(y < r_south(&f->rect))
- break;
- f_prev = f;
- }
- if(f == nil)
- f = f_prev;
+ rect->height = 2 * Delta;
         if(y < (f->rect.y + labelh(&def.font))) {
                 before = True;
                 rect->y = f->rect.y - Delta;
- rect->height = 2 * Delta;
                 if(do_move)
                         goto do_move;
                 return;
@@ -258,12 +256,12 @@ find_droppoint(Frame *frame, int x, int
         if(y > r_south(&f->rect) - labelh(&def.font)) {
                 before = False;
                 rect->y = r_south(&f->rect) - Delta;
- rect->height = 2 * Delta;
                 if(do_move)
                         goto do_move;
                 return;
         }
 
+ /* No? Swap. */
         *rect = f->rect;
         if(do_move) {
                 swap_frames(frame, f);
@@ -372,7 +370,7 @@ mouse_resizecol(Divide *d) {
                 if(dp->next == d) break;
 
         /* Fix later */
- if(dp == nil || d->next == nil)
+ if(a || a->next == nil)
                 return;
 
         minw = screen->rect.width/NCOL;
@@ -417,7 +415,6 @@ mouse_resizecol(Divide *d) {
                         goto done;
                 case MotionNotify:
                         x = ev.xmotion.x_root;
-
                         XMoveWindow(blz.dpy, d->w, x, 0);
                         break;
                 case Expose:
Received on Sat Apr 14 2007 - 10:39:26 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:38 UTC