On 17.08.11, Bastien Dejean wrote:
> Is there any patch to make dwm handles a ruled based user specified
> initial geometry for floating windows?
I've just hacked together a working patch for dwm 5.9.
It adds a member named "geometry" to the Rule struct, enabling you to
add a typical X geometry string (WIDTHxHEIGHT+X+Y) to any rule in your
config.h.
See the rules array in config.def.h after applying the patch to see an
example.
Please note, that this patch is not well tested and that it is kind of
anti-dwm. I wrote it because I was bored.
Bert
diff -rup dwm-5.9-orig/config.def.h dwm-5.9/config.def.h
--- dwm-5.9-orig/config.def.h 2011-07-10 22:24:25.000000000 +0200
+++ dwm-5.9/config.def.h 2011-08-17 17:15:47.000000000 +0200
@@ -17,9 +17,10 @@ static const Bool topbar = Tr
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
static const Rule rules[] = {
- /* class instance title tags mask isfloating
monitor */
- { "Gimp", NULL, NULL, 0, True, -1 },
- { "Firefox", NULL, NULL, 1 << 8, False, -1 },
+ /* class instance title tags mask isfloating
geometry monitor */
+ { "Gimp", NULL, NULL, 0, True, NULL,
-1 },
+ { "Firefox", NULL, NULL, 1 << 8, False, NULL,
-1 },
+ { "XCalc", NULL, NULL, 0, True,
"225x333+200+100", -1 },
};
/* layout(s) */
diff -rup dwm-5.9-orig/dwm.c dwm-5.9/dwm.c
--- dwm-5.9-orig/dwm.c 2011-07-10 22:24:25.000000000 +0200
+++ dwm-5.9/dwm.c 2011-08-17 17:19:07.000000000 +0200
@@ -148,6 +148,7 @@ typedef struct {
const char *title;
unsigned int tags;
Bool isfloating;
+ const char *geometry;
int monitor;
} Rule;
@@ -290,6 +291,8 @@ applyrules(Client *c) {
const Rule *r;
Monitor *m;
XClassHint ch = { 0 };
+ int geomask, x, y;
+ unsigned int w, h;
/* rule matching */
c->isfloating = c->tags = 0;
@@ -307,6 +310,19 @@ applyrules(Client *c) {
for(m = mons; m && m->num != r->monitor; m =
m->next);
if(m)
c->mon = m;
+ if(r->geometry) {
+ c->isfloating = True;
+ /* long version, so that it's possible
to add some checks */
+ geomask = XParseGeometry(r->geometry,
&x, &y, &w, &h);
+ if(geomask & WidthValue)
+ c->w = w;
+ if(geomask & HeightValue)
+ c->h = h;
+ if(geomask & XValue)
+ c->x = x;
+ if(geomask & YValue)
+ c->y = y;
+ }
}
}
if(ch.res_class)
@@ -1104,6 +1120,12 @@ manage(Window w, XWindowAttributes *wa)
die("fatal: could not malloc() %u bytes\n", sizeof(Client));
c->win = w;
updatetitle(c);
+ /* geometry */
+ c->x = c->oldx = wa->x;
+ c->y = c->oldy = wa->y;
+ c->w = c->oldw = wa->width;
+ c->h = c->oldh = wa->height;
+ c->oldbw = wa->border_width;
if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
c->mon = t->mon;
c->tags = t->tags;
@@ -1112,12 +1134,6 @@ manage(Window w, XWindowAttributes *wa)
c->mon = selmon;
applyrules(c);
}
- /* geometry */
- c->x = c->oldx = wa->x;
- c->y = c->oldy = wa->y;
- c->w = c->oldw = wa->width;
- c->h = c->oldh = wa->height;
- c->oldbw = wa->border_width;
if(c->w == c->mon->mw && c->h == c->mon->mh) {
c->isfloating = True;
c->x = c->mon->mx;