[dev][dwm] Floating window center position fix

From: lolilolicon <lolilolicon_AT_gmail.com>
Date: Wed, 20 Jul 2011 23:53:16 +0800

I have a rule in config.h for MPlayer to always float. The bug was
observed when I played a 720p video whose window was 1280 pixels so it
filled the width of my laptop screen. The MPlayer window was supposed to
be centered, but a border line on the left was clearly visible. For
further confirmation, I set borderpx to 20. My observation was obviously
right. The patch is appended at the end.

Another thing I've observed but didn't care to fix when playing the video:
If the MPlayer window is always created in tag 4 (as per a rule), but I
run the mplayer command in xterm in tag 1, the visibility of the MPlayer
window border depends on some timing:

1) If I switch from tag 1 to tag 4 _after_ the MPlayer window is created,
   the border is visible.
2) If I switch from tag 1 to tag 4 _before_ the MPlayer window is created,
   the border is invisible. It seems for dwm the border exists, just not
   drawn. If I switch to another tag and back, or do a focusstack()
   using the default mod1+j combo or pretty about anything, the border
   will then be drawn.

Relevant entries in my test config.h are:

static const unsigned int borderpx = 20;
static const Rule rules[] = {
  { "MPlayer", NULL, NULL, 1 << 3, True, -1 },
};

And following is my patch for the center position bug:

Patch for dwm 5.9
diff -up a/dwm.c b/dwm.c
--- a/dwm.c 1970-01-01 00:00:00.000000000 +0000
+++ b/dwm.c 1970-01-01 00:00:00.000000000 +0000
@@ -624,9 +624,9 @@ configurerequest(XEvent *e) {
                         if(ev->value_mask & CWHeight)
                                 c->h = ev->height;
                         if((c->x + c->w) > m->mx + m->mw && c->isfloating)
- c->x = m->mx + (m->mw / 2 - c->w / 2); /* center in x direction */
+ c->x = m->mx + (m->mw / 2 - WIDTH(c) / 2); /* center in x direction */
                         if((c->y + c->h) > m->my + m->mh && c->isfloating)
- c->y = m->my + (m->mh / 2 - c->h / 2); /* center in y direction */
+ c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2); /* center in y direction */
                         if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
                                 configure(c);
                         if(ISVISIBLE(c))
Received on Wed Jul 20 2011 - 17:53:16 CEST

This archive was generated by hypermail 2.2.0 : Wed Jul 20 2011 - 18:00:05 CEST