Hi,

what about renaming addtomwfact() to setmwfact() and allowing for
mwfact to be set both relatively and abolutely? Sometimes I need a
terminal window which has exactly 80 columns; that's where being able
to set mwfact explicitly would be nice.

The attached patch implements this minor change. The argument passed
to setmwfact() is handled as follows:

- If the first character is either '+' or '-', the value is added
  or subtracted from mwfact. This is the current behaviour of
  addtomwfact(), except that a plus sign is needed to incement mwfact.

- If the first chararcter is neither '+' nor '-', mwfact is set to the
  value, no matter what the current mwfact value is.

Furthermore, for large delta values mwfact currently doesn't come close
to its limits (0.1, 0.9). The patch fixes this as well.

It also prevents arrange() from being called if sscanf() fails
(shouldn't happen, but...).

Comments are welcome!


Cheers, Jukka

-- 
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~
diff -rup dwm.orig/tile.h dwm/tile.h
--- dwm.orig/tile.h     2007-08-15 21:53:12.000000000 +0200
+++ dwm/tile.h  2007-08-17 11:55:27.000000000 +0200
@@ -1,6 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 
 /* tile.c */
-void addtomwfact(const char *arg);     /* adds arg value [0.1 .. 0.9] to 
master width factor */
+void setmwfact(const char *arg);       /* sets master width factor */
 void tile(void);                       /* arranges all windows tiled */
 void zoom(const char *arg);            /* zooms the focused client to master 
area, arg is ignored */
diff -rup dwm.orig/tile.c dwm/tile.c
--- dwm.orig/tile.c     2007-08-16 09:21:04.000000000 +0200
+++ dwm/tile.c  2007-08-17 12:03:07.000000000 +0200
@@ -9,8 +9,9 @@ static double mwfact = MWFACT;
 /* extern */
 
 void
-addtomwfact(const char *arg) {
-       double delta;
+setmwfact(const char *arg) {
+       char sign;
+       double delta, newfact;
 
        if(!isarrange(tile))
                return;
@@ -18,9 +19,24 @@ addtomwfact(const char *arg) {
        /* arg handling, manipulate mwfact */
        if(arg == NULL)
                mwfact = MWFACT;
-       else if(1 == sscanf(arg, "%lf", &delta)) {
-               if(delta + mwfact > 0.1 && delta + mwfact < 0.9)
-                       mwfact += delta;
+       else {
+               switch(arg[0]) {
+                       case '-':
+                       case '+':
+                               if(2 != sscanf(arg, "%c%lf", &sign, &delta))
+                                       return;
+                               newfact = mwfact + (sign=='-' ? -1 : 1) * delta;
+                               break;
+                       default:
+                               if(1 != sscanf(arg, "%lf", &newfact))
+                                       return;
+                               break;
+               }
+               if(newfact < 0.1)
+                       newfact = 0.1;
+               else if(newfact > 0.9)
+                       newfact = 0.9;
+               mwfact = newfact;
        }
        arrange();
 }
diff -rup dwm.orig/config.arg.h dwm/config.arg.h
--- dwm.orig/config.arg.h       2007-08-17 10:39:09.000000000 +0200
+++ dwm/config.arg.h    2007-08-17 11:56:18.000000000 +0200
@@ -48,8 +48,8 @@ Key keys[] = { \
        { MODKEY,                       XK_b,           togglebar,      NULL }, 
\
        { MODKEY,                       XK_j,           focusnext,      NULL }, 
\
        { MODKEY,                       XK_k,           focusprev,      NULL }, 
\
-       { MODKEY,                       XK_h,           addtomwfact,    "-0.05" 
}, \
-       { MODKEY,                       XK_l,           addtomwfact,    "0.05" 
}, \
+       { MODKEY,                       XK_h,           setmwfact,      "-0.05" 
}, \
+       { MODKEY,                       XK_l,           setmwfact,      "+0.05" 
}, \
        { MODKEY,                       XK_m,           togglemax,      NULL }, 
\
        { MODKEY,                       XK_Return,      zoom,           NULL }, 
\
        { MODKEY|ShiftMask,             XK_space,       togglefloating, NULL }, 
\
diff -rup dwm.orig/config.default.h dwm/config.default.h
--- dwm.orig/config.default.h   2007-08-17 10:39:09.000000000 +0200
+++ dwm/config.default.h        2007-08-17 11:56:28.000000000 +0200
@@ -46,8 +46,8 @@ Key keys[] = { \
        { MODKEY,                       XK_b,           togglebar,      NULL }, 
\
        { MODKEY,                       XK_j,           focusnext,      NULL }, 
\
        { MODKEY,                       XK_k,           focusprev,      NULL }, 
\
-       { MODKEY,                       XK_h,           addtomwfact,    "-0.05" 
}, \
-       { MODKEY,                       XK_l,           addtomwfact,    "0.05" 
}, \
+       { MODKEY,                       XK_h,           setmwfact,      "-0.05" 
}, \
+       { MODKEY,                       XK_l,           setmwfact,      "+0.05" 
}, \
        { MODKEY,                       XK_m,           togglemax,      NULL }, 
\
        { MODKEY,                       XK_Return,      zoom,           NULL }, 
\
        { MODKEY|ShiftMask,             XK_space,       togglefloating, NULL }, 
\

Reply via email to