]> Pileus Git - wmpus/commitdiff
Add residual tracking in wm-wmii
authorAndy Spencer <andy753421@gmail.com>
Mon, 20 Apr 2015 04:46:48 +0000 (04:46 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 20 Apr 2015 06:28:11 +0000 (06:28 +0000)
This prevents extra space caused by
floating point round-off while tiling.

util.c
util.h
wm-wmii.c

diff --git a/util.c b/util.c
index b589fd3d7247bbe5b554de84b520ec359b40d9d8..52bcf954eb1afa1e5d7ea4a3bbd77efa92c06db3 100644 (file)
--- a/util.c
+++ b/util.c
@@ -126,6 +126,14 @@ list_t *list_sort(list_t *list, int rev, int (*func)(void *a, void*b))
 }
 
 /* Misc */
+int residual(float num, float *state)
+{
+       float f = num + *state;
+       int   i = (int)(f+0.5);
+       *state = f - i;
+       return i;
+}
+
 int str2num(char *str, int def)
 {
        char *end = NULL;
diff --git a/util.h b/util.h
index bc23ecd9a6005fce68d6007bec1b6cb016845039..16fe41eb4162b19aa07176f762dd79d590a55429 100644 (file)
--- a/util.h
+++ b/util.h
@@ -58,6 +58,8 @@ list_t *list_find(list_t *list, void *data);
 list_t *list_sort(list_t *list, int rev, int (*func)(void*,void*));
 
 /* Misc */
+int residual(float num, float *state);
+
 int str2num(char *str, int def);
 
 int warn(char *fmt, ...);
index e31f07422ec23b37da60e11379532fac9927a29e..506cced362e9de6f0a71080e8f894f0a73e2adad 100644 (file)
--- a/wm-wmii.c
+++ b/wm-wmii.c
@@ -617,13 +617,15 @@ static void wm_update_cols(dpy_t *dpy)
        int mx=0, my=0; // Maximum usable size (screen size minus margins)
        int       sy=0; // Stack size (height of focused stack window)
 
+       float rx=0, ry=0; // Residuals for floating point round off
+
        /* Scale horizontally */
        x  = dpy->geom->x;
        mx = dpy->geom->w - (list_length(dpy->cols)+1)*margin;
        for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next)
                tx += COL(lcol)->width;
        for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next)
-               COL(lcol)->width *= (float)mx / tx;
+               COL(lcol)->width = residual(COL(lcol)->width * (float)mx/tx, &rx);
 
        /* Scale each column vertically */
        win_t *focus = get_focus();
@@ -645,13 +647,11 @@ static void wm_update_cols(dpy_t *dpy)
                        }
                        win->h = ROW(lrow)->height;
                        state_t state = ST_SHOW;
-                       int height = 0;
                        switch (col->layout) {
                        case SPLIT:
-                               sys_move(win, x+margin, y+margin,
-                                       col->width, win->h * ((float)my / ty));
-                               height = win->h;
-                               y += height + margin;
+                               sys_move(win, x+margin, y+margin, col->width,
+                                       residual(win->h * ((float)my/ty), &ry));
+                               y += win->h + margin;
                                break;
                        case STACK:
                                if (lrow->next && ROW(lrow->next)->win == col->row->win) {