diff --git a/layouts/tile.c b/layouts/tile.c index cb138785c..a25a27505 100644 --- a/layouts/tile.c +++ b/layouts/tile.c @@ -42,23 +42,17 @@ uicb_setnmaster(Display *disp, awesome_config *awesomeconf, const char * arg) { - int delta; - int wah = get_windows_area_height(disp, awesomeconf->statusbar); - if(!IS_ARRANGE(tile) && !IS_ARRANGE(tileleft) && !IS_ARRANGE(bstack) && !IS_ARRANGE(bstackportrait)) return; + if(!arg) nmaster = awesomeconf->nmaster; - else if(sscanf(arg, "%d", &delta)) - { - if((arg[0] == '+' || arg[0] == '-') - && !((nmaster + delta) < 1 || wah / (nmaster + delta) <= 2 * awesomeconf->borderpx)) - nmaster += delta; - else if(delta >= 1 && wah / delta <= 2 * awesomeconf->borderpx) - nmaster = delta; - else - return; - } + else + nmaster = (int) compute_new_value_from_arg(arg, (double) nmaster); + + if(nmaster < 1) + nmaster = 1; + if(sel) arrange(disp, drawcontext, awesomeconf); else diff --git a/util.c b/util.c index 3250e9061..b247b7e16 100644 --- a/util.c +++ b/util.c @@ -102,3 +102,19 @@ xgettextprop(Display *disp, Window w, Atom atom, char *text, unsigned int size) return True; } + +double +compute_new_value_from_arg(const char *arg, double current_value) +{ + double delta; + + if(arg && sscanf(arg, "%lf", &delta) == 1) + { + if(arg[0] == '+' || arg[0] == '-') + current_value += delta; + else + current_value = delta; + } + + return current_value; +} diff --git a/util.h b/util.h index e957a5967..c73a59b14 100644 --- a/util.h +++ b/util.h @@ -121,5 +121,6 @@ static inline char *a_strdup(const char *s) void eprint(const char *, ...) __attribute__ ((noreturn)) __attribute__ ((format(printf, 1, 2))); void uicb_spawn(Display *, DC *, awesome_config *, const char *); Bool xgettextprop(Display *, Window, Atom, char *, unsigned int); +double compute_new_value_from_arg(const char *, double); #endif