From fa126c8c7e00ee089af5f86ad6922d8257156425 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 20 Apr 2015 04:46:48 +0000 Subject: [PATCH] Add residual tracking in wm-wmii This prevents extra space caused by floating point round-off while tiling. --- util.c | 8 ++++++++ util.h | 2 ++ wm-wmii.c | 12 ++++++------ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/util.c b/util.c index b589fd3..52bcf95 100644 --- 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 bc23ecd..16fe41e 100644 --- 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, ...); diff --git a/wm-wmii.c b/wm-wmii.c index e31f074..506cced 100644 --- 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) { -- 2.43.2