[hackers] [wmii] Allow resizing of rightmost and leftmost divs. Needs work. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Fri, 2 Oct 2009 02:10:01 +0000 (UTC)

changeset: 2503:14f6a5b79924
user: Kris Maglione <jg_AT_suckless.org>
date: Thu Oct 01 21:49:24 2009 -0400
files: cmd/wmii/area.c cmd/wmii/column.c cmd/wmii/dat.h cmd/wmii/fns.h cmd/wmii/layout.c cmd/wmii/main.c cmd/wmii/mouse.c cmd/wmii/view.c
description:
Allow resizing of rightmost and leftmost divs. Needs work.

diff -r 8512fbc165ca -r 14f6a5b79924 cmd/wmii/area.c
--- a/cmd/wmii/area.c Thu Oct 01 20:18:22 2009 -0400
+++ b/cmd/wmii/area.c Thu Oct 01 21:49:24 2009 -0400
@@ -74,16 +74,16 @@
 Area*
 area_create(View *v, Area *pos, int scrn, uint width) {
         static ushort id = 1;
- uint i;
- uint minwidth;
+ int i, j;
+ uint minwidth, index;
         int numcols;
         Area *a;
 
         assert(!pos || pos->screen == scrn);
         SET(i);
         if(v->areas) { /* Creating a column. */
- minwidth = Dx(v->r[scrn])/NCOL;
- i = pos ? area_idx(pos) : 1;
+ minwidth = column_minwidth();
+ index = pos ? area_idx(pos) : 1;
                 numcols = 0;
                 for(a=v->areas[scrn]; a; a=a->next)
                         numcols++;
@@ -92,7 +92,7 @@
                  */
                 if(width == 0) {
                         if(numcols >= 0) {
- width = view_newcolwidth(v, i);
+ width = view_newcolwidth(v, index);
                                 if (width == 0)
                                         width = Dx(v->r[scrn]) / (numcols + 1);
                         }
@@ -102,9 +102,17 @@
 
                 if(width < minwidth)
                         width = minwidth;
- if(numcols && (numcols * minwidth + width) > Dx(v->r[scrn]))
+ minwidth = numcols * minwidth + minwidth;
+ if(minwidth > Dx(v->r[scrn]))
                         return nil;
 
+ i = minwidth - Dx(v->pad[scrn]) - Dx(v->r[scrn]);
+ if(i > 0 && Dx(v->pad[scrn])) {
+ j = min(i/2, v->pad[scrn].min.x);
+ v->pad[scrn].min.x -= j;
+ v->pad[scrn].max.x += i - j;
+ }
+
                 view_scale(v, scrn, Dx(v->r[scrn]) - width);
         }
 
@@ -145,7 +153,7 @@
                 area_focus(a);
 
         if(!a->floating)
- event("CreateColumn %ud\n", i);
+ event("CreateColumn %ud\n", index);
         return a;
 }
 
diff -r 8512fbc165ca -r 14f6a5b79924 cmd/wmii/column.c
--- a/cmd/wmii/column.c Thu Oct 01 20:18:22 2009 -0400
+++ b/cmd/wmii/column.c Thu Oct 01 21:49:24 2009 -0400
@@ -80,6 +80,12 @@
                                   a->max ? '+' : '-');
 }
 
+int
+column_minwidth(void)
+{
+ return 4 * labelh(def.font);
+}
+
 Area*
 column_new(View *v, Area *pos, int scrn, uint w) {
         Area *a;
@@ -698,7 +704,7 @@
         a = f->area;
         v = a->view;
 
- minw = Dx(v->r[a->screen]) / NCOL;
+ minw = column_minwidth();
 
         al = a->prev;
         ar = a->next;
diff -r 8512fbc165ca -r 14f6a5b79924 cmd/wmii/dat.h
--- a/cmd/wmii/dat.h Thu Oct 01 20:18:22 2009 -0400
+++ b/cmd/wmii/dat.h Thu Oct 01 21:49:24 2009 -0400
@@ -279,6 +279,7 @@
         int selcol;
         bool dead;
         Rectangle *r;
+ Rectangle *pad;
 };
 
 /* Yuck. */
diff -r 8512fbc165ca -r 14f6a5b79924 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Thu Oct 01 20:18:22 2009 -0400
+++ b/cmd/wmii/fns.h Thu Oct 01 21:49:24 2009 -0400
@@ -109,6 +109,7 @@
 void column_detach(Frame*);
 void column_frob(Area*);
 void column_insert(Area*, Frame*, Frame*);
+int column_minwidth(void);
 Area* column_new(View*, Area*, int, uint);
 void column_remove(Frame*);
 void column_resize(Area*, int);
diff -r 8512fbc165ca -r 14f6a5b79924 cmd/wmii/layout.c
--- a/cmd/wmii/layout.c Thu Oct 01 20:18:22 2009 -0400
+++ b/cmd/wmii/layout.c Thu Oct 01 21:49:24 2009 -0400
@@ -203,7 +203,7 @@
                 return; /* XXX: Multihead. */
 
         fw->ra = nil;
- minw = Dx(v->r[a->screen])/NCOL;
+ minw = column_minwidth();
         if(abs(pt.x - a->r.min.x) < minw/2) {
                 pt.x = a->r.min.x;
                 fw->ra = a->prev;
diff -r 8512fbc165ca -r 14f6a5b79924 cmd/wmii/main.c
--- a/cmd/wmii/main.c Thu Oct 01 20:18:22 2009 -0400
+++ b/cmd/wmii/main.c Thu Oct 01 21:49:24 2009 -0400
@@ -178,6 +178,7 @@
         for(v=view; v; v=v->next) {
                 v->areas = erealloc(v->areas, m * sizeof *v->areas);
                 v->r = erealloc(v->r, m * sizeof *v->r);
+ v->pad = erealloc(v->pad, m * sizeof *v->pad);
         }
 
         for(i=nscreens; i < m; i++) {
diff -r 8512fbc165ca -r 14f6a5b79924 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Thu Oct 01 20:18:22 2009 -0400
+++ b/cmd/wmii/mouse.c Thu Oct 01 21:49:24 2009 -0400
@@ -229,7 +229,7 @@
         if(align&East)
                 d = d->next;
 
- min.x = Dx(v->r[a->screen])/NCOL;
+ min.x = column_minwidth();
         min.y = /*frame_delta_h() +*/ labelh(def.font);
         /* Set the limits of where this box may be dragged. */
 #define frob(pred, f, aprev, rmin, rmax, plus, minus, xy) BLOCK( \
@@ -312,23 +312,19 @@
 mouse_resizecol(Divide *d) {
         Window *cwin;
         View *v;
- Area *a;
         Rectangle r;
         Point pt;
- int minw;
+ int minw, scrn;
 
         v = selview;
 
- a = d->left;
- /* Fix later */
- if(a == nil || a->next == nil)
- return;
+ scrn = (d->left ? d->left : d->right)->screen;
 
         pt = querypointer(&scr.root);
 
- minw = Dx(v->r[a->screen])/NCOL;
- r.min.x = a->r.min.x + minw;
- r.max.x = a->next->r.max.x - minw;
+ minw = column_minwidth();
+ r.min.x = d->left ? d->left->r.min.x + minw : v->r[scrn].min.x;
+ r.max.x = d->right ? d->right->r.max.x - minw : v->r[scrn].max.x;
         r.min.y = pt.y;
         r.max.y = pt.y+1;
 
@@ -340,7 +336,19 @@
         while(readmotion(&pt))
                 div_set(d, pt.x);
 
- column_resize(a, pt.x - a->r.min.x);
+ if(d->left)
+ d->left->r.max.x = pt.x;
+ else
+ v->pad[scrn].min.x = pt.x - v->r[scrn].min.x;
+
+ if(d->right)
+ d->right->r.min.x = pt.x;
+ else
+ v->pad[scrn].max.x = pt.x - v->r[scrn].max.x;
+ print("%R\n", v->pad[scrn]);
+ print("%d %d\n", pt.x - v->r[scrn].min.x, pt.x - v->r[scrn].max.x);
+
+ view_arrange(v);
 
 done:
         ungrabpointer();
diff -r 8512fbc165ca -r 14f6a5b79924 cmd/wmii/view.c
--- a/cmd/wmii/view.c Thu Oct 01 20:18:22 2009 -0400
+++ b/cmd/wmii/view.c Thu Oct 01 21:49:24 2009 -0400
@@ -74,15 +74,18 @@
         v = emallocz(sizeof *v);
         v->id = id++;
         v->r = emallocz(nscreens * sizeof *v->r);
- v->areas = emallocz(nscreens * sizeof *v->areas);
+ v->pad = emallocz(nscreens * sizeof *v->pad);
 
         utflcpy(v->name, name, sizeof v->name);
 
         event("CreateTag %s\n", v->name);
         area_create(v, nil, screen->idx, 0);
 
+ v->areas = emallocz(nscreens * sizeof *v->areas);
+
         for(i=0; i < nscreens; i++)
                 view_init(v, i);
+
         
         area_focus(v->firstarea);
 
@@ -104,6 +107,8 @@
 
 void
 view_init(View *v, int iscreen) {
+ v->r[iscreen] = screens[iscreen]->r;
+ print("%d: %R\n", iscreen, screens[iscreen]->r);;
         v->areas[iscreen] = nil;
         column_new(v, nil, iscreen, 0);
 }
@@ -469,9 +474,10 @@
         uint minwidth;
         Area *a;
         float scale;
- int dx;
+ int dx, minx;
 
- minwidth = Dx(v->r[scrn])/NCOL; /* XXX: Multihead. */
+ minwidth = column_minwidth();
+ minx = v->r[scrn].min.x + v->pad[scrn].min.x;
 
         if(!v->areas[scrn])
                 return;
@@ -484,7 +490,7 @@
         }
 
         scale = (float)width / dx;
- xoff = v->r[scrn].min.x;
+ xoff = minx;
         for(a=v->areas[scrn]; a; a=a->next) {
                 a->r.max.x = xoff + Dx(a->r) * scale;
                 a->r.min.x = xoff;
@@ -496,14 +502,14 @@
         if(numcol * minwidth > width)
                 return;
 
- xoff = v->r[scrn].min.x;
+ xoff = minx;
         for(a=v->areas[scrn]; a; a=a->next) {
                 a->r.min.x = xoff;
 
                 if(Dx(a->r) < minwidth)
                         a->r.max.x = xoff + minwidth;
                 if(!a->next)
- a->r.max.x = v->r[scrn].min.x + width;
+ a->r.max.x = minx + width;
                 xoff = a->r.max.x;
         }
 }
@@ -519,7 +525,7 @@
 
         view_update_rect(v);
         for(s=0; s < nscreens; s++)
- view_scale(v, s, Dx(v->r[s]));
+ view_scale(v, s, Dx(v->r[s]) + Dx(v->pad[s]));
         foreach_area(v, s, a) {
                 if(a->floating)
                         continue;
Received on Fri Oct 02 2009 - 02:10:01 UTC

This archive was generated by hypermail 2.2.0 : Fri Oct 02 2009 - 02:12:06 UTC