[hackers] [wmii] Refactoring in column.c

From: Kris Maglione <jg_AT_suckless.org>
Date: Sun Feb 11 03:05:33 2007

changeset: 1835:1704d599fc05
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Feb 10 21:02:34 2007 -0500
summary: Refactoring in column.c

diff -r 9ef7f6580de7 -r 1704d599fc05 README
--- a/README Sat Feb 10 20:09:11 2007 -0500
+++ b/README Sat Feb 10 21:02:34 2007 -0500
@@ -52,9 +52,9 @@ The following people have contributed es
 The following people have contributed especially to wmii in various ways:
 
 - Christoph Wegscheider <christoph dot wegscheider at wegi dot net>
-- Georg Neis <gn at wmii dot de>
+- Georg Neis <gn at suckless dot org>
 - Uwe Zeisberger <zeisberg at informatik dot uni-freiburg dot de>
-- Uriel <uriel at wmii dot de>
+- Uriel <uriel at suckless dot org>
 - Scot Doyle <scot at scotdoyle dot com>
 - Sebastian Hartmann <seb dot wmi at gmx dot de>
 - Bernhard Leiner <bleiner at gmail dot com>
diff -r 9ef7f6580de7 -r 1704d599fc05 column.c
--- a/column.c Sat Feb 10 20:09:11 2007 -0500
+++ b/column.c Sat Feb 10 21:02:34 2007 -0500
@@ -199,28 +199,35 @@ match_horiz(Area *a, XRectangle *r) {
         }
 }
 
-static void
-drop_resize(Frame *f, XRectangle *new) {
- Area *west = nil, *east = nil, *a = f->area;
- View *v = a->view;
- Frame *north = nil, *south = nil;
- unsigned int min_height = 2 * labelh(&def.font);
- unsigned int min_width = screen->rect.width/NCOL;
+void
+resize_column(Client *c, XRectangle *new) {
+ Area *west, *east, *a;
+ Frame *north, *south, *f;
+ View *v;
+ BlitzAlign sticky;
+ unsigned int min_height;
+ unsigned int min_width;
+
+ f = c->sel;
+ a = f->area;
+ v = a->view;
+ min_height = 2 * labelh(&def.font);
+ min_width = screen->rect.width/NCOL;
 
         for(west=v->area->next; west; west=west->next)
                 if(west->next == a) break;
- /* first managed area is indexed 1, thus (i > 1) ? ... */
         east = a->next;
         for(north=a->frame; north; north=north->anext)
                 if(north->anext == f) break;
         south = f->anext;
         /* validate (and trim if necessary) horizontal resize */
+ sticky = get_sticky(&f->rect, new);
         if(new->width < min_width) {
- if((new->x + new->width) == (f->rect.x + f->rect.width))
- new->x = a->rect.x + a->rect.width - min_width;
+ if(sticky & EAST)
+ new->x = r_east(&a->rect) - min_width;
                 new->width = min_width;
         }
- if(west && (new->x != f->rect.x)) {
+ if(west && !(sticky & WEST)) {
                 if(new->x < 0 || new->x < (west->rect.x + min_width)) {
                         new->width -= (west->rect.x + min_width) - new->x;
                         new->x = west->rect.x + min_width;
@@ -229,15 +236,16 @@ drop_resize(Frame *f, XRectangle *new) {
                 new->width += new->x - a->rect.x;
                 new->x = a->rect.x;
         }
- if(east && (new->x + new->width) != (f->rect.x + f->rect.width)) {
- if((new->x + new->width) > (east->rect.x + east->rect.width - min_width))
- new->width = east->rect.x + east->rect.width - min_width - new->x;
+ if(east && !(sticky & EAST)) {
+ if(r_east(new) > r_east(&east->rect) - min_width)
+ new->width = r_east(&east->rect) - min_width - new->x;
         } else
- new->width = a->rect.x + a->rect.width - new->x;
+ new->width = r_east(&a->rect) - new->x;
         if(new->width < min_width)
                 goto AfterHorizontal;
         /* horizontal resize */
- if(west && (new->x != a->rect.x)) {
+ sticky = get_sticky(&a->rect, new);
+ if(west && !(sticky & WEST)) {
                 west->rect.width = new->x - west->rect.x;
                 a->rect.width += a->rect.x - new->x;
                 a->rect.x = new->x;
@@ -245,10 +253,10 @@ drop_resize(Frame *f, XRectangle *new) {
                 match_horiz(west, &west->rect);
                 relax_column(west);
         }
- if(east && (new->x + new->width) != (a->rect.x + a->rect.width)) {
- east->rect.width -= new->x + new->width - east->rect.x;
- east->rect.x = new->x + new->width;
- a->rect.width = new->x + new->width - a->rect.x;
+ if(east && !(sticky & EAST)) {
+ east->rect.width -= r_east(new) - east->rect.x;
+ east->rect.x = r_east(new);
+ a->rect.width = r_east(new) - a->rect.x;
                 match_horiz(a, &a->rect);
                 match_horiz(east, &east->rect);
                 relax_column(east);
@@ -258,36 +266,36 @@ AfterHorizontal:
         if(a->mode != Coldefault)
                 goto AfterVertical;
         /* validate (and trim if necessary) vertical resize */
+ sticky = get_sticky(&f->rect, new);
         if(new->height < min_height) {
- if(f->rect.height < min_height
- && (new->y == f->rect.y || (new->y + new->height) == (f->rect.y + f->rect.height)))
+ if((f->rect.height < min_height) && sticky & (NORTH|SOUTH))
                         goto AfterVertical;
- if((new->y + new->height) == (f->rect.y + f->rect.height))
- new->y = f->rect.y + f->rect.height - min_height;
+ if(sticky & SOUTH)
+ new->y = r_south(&f->rect) - min_height;
                 new->height = min_height;
         }
- if(north && (new->y != f->rect.y))
+ if(north && !(sticky & NORTH))
                 if(new->y < 0 || new->y < (north->rect.y + min_height)) {
                         new->height -= (north->rect.y + min_height) - new->y;
                         new->y = north->rect.y + min_height;
                 }
- if(south && (new->y + new->height) != (f->rect.y + f->rect.height)) {
- if((new->y + new->height) > (south->rect.y + south->rect.height - min_height))
- new->height = (south->rect.y + south->rect.height - min_height) - new->y;
+ if(south && !(sticky & SOUTH)) {
+ if(r_south(new) > r_south(&south->rect) - min_height)
+ new->height = r_south(&south->rect) - min_height - new->y;
         }
         if(new->height < min_height)
                 goto AfterVertical;
         /* vertical resize */
- if(north && (new->y != f->rect.y)) {
+ if(north && !(sticky & NORTH)) {
                 north->rect.height = new->y - north->rect.y;
                 f->rect.height += f->rect.y - new->y;
                 f->rect.y = new->y;
                 resize_frame(north, &north->rect);
                 resize_frame(f, &f->rect);
         }
- if(south && (new->y + new->height != f->rect.y + f->rect.height)) {
- south->rect.height -= new->y + new->height - south->rect.y;
- south->rect.y = new->y + new->height;
+ if(south && !(sticky & SOUTH)) {
+ south->rect.height -= r_south(new) - south->rect.y;
+ south->rect.y = r_south(new);
                 f->rect.y = new->y;
                 f->rect.height = new->height;
                 resize_frame(f, &f->rect);
@@ -296,11 +304,6 @@ AfterVertical:
 AfterVertical:
         relax_column(a);
         focus_view(screen, v);
-}
-
-void
-resize_column(Client *c, XRectangle *r) {
- drop_resize(c->sel, r);
 }
 
 Area *
diff -r 9ef7f6580de7 -r 1704d599fc05 frame.c
--- a/frame.c Sat Feb 10 20:09:11 2007 -0500
+++ b/frame.c Sat Feb 10 21:02:34 2007 -0500
@@ -77,19 +77,11 @@ insert_frame(Frame *pos, Frame *f, Bool
 
 void
 resize_frame(Frame *f, XRectangle *r) {
- BlitzAlign stickycorner = 0;
+ BlitzAlign stickycorner;
         Client *c;
 
         c = f->client;
-
- if(f->rect.x != r->x && (f->rect.x + f->rect.width) == (r->x + r->width))
- stickycorner |= EAST;
- else
- stickycorner |= WEST;
- if(f->rect.y != r->y && (f->rect.y + f->rect.height) == (r->y + r->height))
- stickycorner |= SOUTH;
- else
- stickycorner |= NORTH;
+ stickycorner = get_sticky(&f->rect, r);
 
         f->rect = *r;
         if((f->area->mode != Colstack) || (f->area->sel == f))
diff -r 9ef7f6580de7 -r 1704d599fc05 geom.c
--- a/geom.c Sat Feb 10 20:09:11 2007 -0500
+++ b/geom.c Sat Feb 10 21:02:34 2007 -0500
@@ -40,3 +40,29 @@ strtorect(XRectangle *r, const char *val
         *r = new;
         return 0;
 }
+
+int
+r_east(XRectangle *r) {
+ return r->x + r->width;
+}
+
+int
+r_south(XRectangle *r) {
+ return r->y + r->height;
+}
+
+BlitzAlign
+get_sticky(XRectangle *src, XRectangle *dst) {
+ BlitzAlign stickycorner = 0;
+
+ if(src->x != dst->x && r_east(src) == r_east(dst))
+ stickycorner |= EAST;
+ else
+ stickycorner |= WEST;
+ if(src->y != dst->y && r_south(src) == r_south(dst))
+ stickycorner |= SOUTH;
+ else
+ stickycorner |= NORTH;
+
+ return stickycorner;
+}
diff -r 9ef7f6580de7 -r 1704d599fc05 wmii.h
--- a/wmii.h Sat Feb 10 20:09:11 2007 -0500
+++ b/wmii.h Sat Feb 10 21:02:34 2007 -0500
@@ -350,6 +350,9 @@ extern Bool ispointinrect(int x, int y,
 extern Bool ispointinrect(int x, int y, XRectangle * r);
 extern BlitzAlign quadofcoord(XRectangle *rect, int x, int y);
 extern int strtorect(XRectangle *r, const char *val);
+extern BlitzAlign get_sticky(XRectangle *src, XRectangle *dst);
+extern int r_east(XRectangle *r);
+extern int r_south(XRectangle *r);
 
 /* key.c */
 extern void kpress(Window w, unsigned long mod, KeyCode keycode);
Received on Sun Feb 11 2007 - 03:05:33 UTC

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