This diff adds a new configuration option to cwm(1) called windowspawn that controls where new windows are placed. It can be one of `center', `cursor' (the default) or `random'.
(BTW, I also removed a few pointless casts while I was at it that has nothing to do with this feature). Is anyone interested in having this feature? Index: calmwm.h =================================================================== RCS file: /cvs/xenocara/app/cwm/calmwm.h,v retrieving revision 1.90 diff -u -p -u -p -r1.90 calmwm.h --- calmwm.h 18 May 2009 00:17:46 -0000 1.90 +++ calmwm.h 16 Jun 2009 12:38:09 -0000 @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $Id: calmwm.h,v 1.90 2009/05/18 00:17:46 oga Exp $ + * $Id: calmwm.h,v 1.2 2009/06/15 23:45:39 tpfaff Exp $ */ #ifndef _CALMWM_H_ @@ -260,6 +260,11 @@ struct conf { #define CONF_MAMOUNT 1 int mamount; +#define CONF_WS_CURSOR 1 +#define CONF_WS_CENTER 2 +#define CONF_WS_RANDOM 3 + int windowspawn; + #define CONF_COLOR_ACTIVEBORDER "#CCCCCC" #define CONF_COLOR_INACTIVEBORDER "#666666" #define CONF_COLOR_GROUPBORDER "blue" @@ -389,8 +394,8 @@ void *xmalloc(size_t); void *xcalloc(size_t, size_t); char *xstrdup(const char *); -#define XMALLOC(p, t) ((p) = (t *)xmalloc(sizeof * (p))) -#define XCALLOC(p, t) ((p) = (t *)xcalloc(1, sizeof * (p))) +#define XMALLOC(p, t) ((p) = xmalloc(sizeof * (p))) +#define XCALLOC(p, t) ((p) = xcalloc(1, sizeof * (p))) struct screen_ctx *screen_fromroot(Window); struct screen_ctx *screen_current(void); Index: client.c =================================================================== RCS file: /cvs/xenocara/app/cwm/client.c,v retrieving revision 1.51 diff -u -p -u -p -r1.51 client.c --- client.c 30 May 2009 00:30:17 -0000 1.51 +++ client.c 16 Jun 2009 12:38:09 -0000 @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $Id: client.c,v 1.51 2009/05/30 00:30:17 okan Exp $ + * $Id: client.c,v 1.3 2009/06/16 12:12:07 tpfaff Exp $ */ #include "headers.h" @@ -582,7 +582,17 @@ client_placecalc(struct client_ctx *cc) int xmouse, ymouse, xorig, yorig; int xmax, ymax; - xu_ptr_getpos(sc->rootwin, &xmouse, &ymouse); + if (Conf.windowspawn == CONF_WS_RANDOM) { + xmouse = rand() / (RAND_MAX / sc->xmax + 1); + ymouse = rand() / (RAND_MAX / sc->ymax + 1); + } + else if (Conf.windowspawn == CONF_WS_CENTER) { + xmouse = sc->xmax / 2; + ymouse = sc->ymax / 2; + } + else + xu_ptr_getpos(sc->rootwin, &xmouse, &ymouse); + if (HasXinerama) { info = screen_find_xinerama(sc, xmouse, ymouse); if (info == NULL) Index: conf.c =================================================================== RCS file: /cvs/xenocara/app/cwm/conf.c,v retrieving revision 1.63 diff -u -p -u -p -r1.63 conf.c --- conf.c 30 May 2009 00:30:27 -0000 1.63 +++ conf.c 16 Jun 2009 12:38:09 -0000 @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $Id: conf.c,v 1.63 2009/05/30 00:30:27 okan Exp $ + * $Id: conf.c,v 1.2 2009/06/16 10:51:14 tpfaff Exp $ */ #include "headers.h" @@ -98,6 +98,7 @@ conf_init(struct conf *c) c->flags = 0; c->bwidth = CONF_BWIDTH; c->mamount = CONF_MAMOUNT; + c->windowspawn = CONF_WS_CURSOR; TAILQ_INIT(&c->ignoreq); TAILQ_INIT(&c->cmdq); Index: cwmrc.5 =================================================================== RCS file: /cvs/xenocara/app/cwm/cwmrc.5,v retrieving revision 1.25 diff -u -p -u -p -r1.25 cwmrc.5 --- cwmrc.5 17 May 2009 23:40:57 -0000 1.25 +++ cwmrc.5 16 Jun 2009 12:38:10 -0000 @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 17 2009 $ +.Dd $Mdocdate: June 16 2009 $ .Dt CWMRC 5 .Os .Sh NAME @@ -192,6 +192,11 @@ The default behavior for new windows is By enabling sticky group mode, .Xr cwm 1 will assign new windows to the currently selected group. +.Pp +.It Ic windowspawn Ar where +Control the placement of new windows. +.Ar where +can be center, random, or cursor (default). .El .Sh EXAMPLE CONFIGURATION .Bd -literal Index: parse.y =================================================================== RCS file: /cvs/xenocara/app/cwm/parse.y,v retrieving revision 1.20 diff -u -p -u -p -r1.20 parse.y --- parse.y 17 May 2009 23:40:57 -0000 1.20 +++ parse.y 16 Jun 2009 12:38:10 -0000 @@ -67,6 +67,7 @@ typedef struct { %token FONTNAME STICKY GAP MOUSEBIND %token AUTOGROUP BIND COMMAND IGNORE %token YES NO BORDERWIDTH MOVEAMOUNT +%token WINDOWSPAWN %token COLOR %token ACTIVEBORDER INACTIVEBORDER %token GROUPBORDER UNGROUPBORDER @@ -173,6 +174,14 @@ main : FONTNAME STRING { free($2); free($3); } + | WINDOWSPAWN STRING { + if (strcasecmp ($2, "random") == 0) + conf->windowspawn = CONF_WS_RANDOM; + else if (strcasecmp ($2, "center") == 0) + conf->windowspawn = CONF_WS_CENTER; + else + conf->windowspawn = CONF_WS_CURSOR; + } ; color : COLOR colors @@ -243,6 +252,7 @@ lookup(char *s) { "no", NO}, { "sticky", STICKY}, { "ungroupborder", UNGROUPBORDER}, + { "windowspawn", WINDOWSPAWN}, { "yes", YES} }; const struct keywords *p; @@ -535,6 +545,7 @@ parse_config(const char *filename, struc xconf->flags = conf->flags; xconf->bwidth = conf->bwidth; xconf->mamount = conf->mamount; + xconf->windowspawn = conf->windowspawn; while ((cmd = TAILQ_FIRST(&conf->cmdq)) != NULL) { TAILQ_REMOVE(&conf->cmdq, cmd, entry); Index: xutil.c =================================================================== RCS file: /cvs/xenocara/app/cwm/xutil.c,v retrieving revision 1.15 diff -u -p -u -p -r1.15 xutil.c --- xutil.c 17 May 2009 23:40:57 -0000 1.15 +++ xutil.c 16 Jun 2009 12:38:10 -0000 @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $Id: xutil.c,v 1.15 2009/05/17 23:40:57 okan Exp $ + * $Id: xutil.c,v 1.2 2009/06/15 20:05:27 tpfaff Exp $ */ #include "headers.h" @@ -161,8 +161,8 @@ xu_setstate(struct client_ctx *cc, int s { long dat[2]; - dat[0] = (long)state; - dat[1] = (long)None; + dat[0] = state; + dat[1] = None; cc->state = state; XChangeProperty(X_Dpy, cc->win, WM_STATE, WM_STATE, 32,