Subject: Off by 2 error in FvwmButtons

From: Tim Phipps <[email-masked]>
Date: Tue, 17 Nov 1998 14:26:26 +0000

Hi All,
	FvwmButtons gets it wrong when you give it a geometry of -0-0.  It
calculates the position hints by subtracting the width of the window
from the display width and then creates a simple window with a border
width of 1.  It should either take the border width into account when
calculating the position hints or set the border width to 0. Since
FvwmButtons is only ever run by fvwm which sets the borderwidth to 0
when reparenting I've attached a patch which does the latter.

Cheers,
Tim.

Index: FvwmButtons.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmButtons/FvwmButtons.c,v
retrieving revision 1.6
diff -u -B -b -r1.6 FvwmButtons.c
--- FvwmButtons.c	1998/11/15 18:00:12	1.6
+++ FvwmButtons.c	1998/11/17 14:21:10
@@ -1240,7 +1240,7 @@
 
   MyWindow = XCreateSimpleWindow(Dpy,Root,mysizehints.x,mysizehints.y,
 				 mysizehints.width,mysizehints.height,
-				 1,fore_pix,back_pix);
+				 0,fore_pix,back_pix);
   if(ub->c->flags&b_IconBack && !(ub->c->flags&b_TransBack))
     XSetWindowBackgroundPixmap(Dpy,MyWindow,ub->c->backicon->picture);

---

From: [email-masked]
Date: Tue, 17 Nov 1998 19:44:56 +0100

> when reparenting I've attached a patch which does the latter.

Done

Bye

Dominik
-- 
Dominik Vogt, Hewlett-Packard GmbH, Dept. BVS
Herrenberger Str.130, 71034 Boeblingen, Germany
phone: 07031/14-4596, fax: 07031/14-3883, [email-masked]
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: [email-masked]
Date: Tue, 17 Nov 1998 20:10:13 +0100

> when reparenting I've attached a patch which does the latter.

done

Dominik

---

From: Tim Phipps <[email-masked]>
Date: Wed, 18 Nov 1998 17:33:48 +0000

I got thinking about this and had a look for XCreate.*Window and found
lots of places where windows are created with non-zero borderwidths.
Having non-zero borderwidths is good in programs that may be run without
a window manager but fvwm and all it's modules only run when there is
one.

FvwmWinList.c has some really nasty cruft in it where various brave
souls have attempted to stop it creeping around. Attached is a patch
which I think fixes the problems.  Having a borderwidth of 12 helps make
errors obvious. I've also removed some commented out code and fixed an
off-by-one error in the height.

One thing that pops out of this is that when a window resizes itself
fvwm does not handle the windows gravity.  FvwmWinList sets the gravity
correctly when initializing and fvwm gets it right when it reparents the
window. Things go pear shaped when FvwmWinList resizes itself though. 
fvwm just changes the size when it should be shifting the origin if a
gravity of anything but NorthWest is specified.

Should we fix fvwm?  There are other modules that resize themselves
(FvwmIconMan for one). Do these have problems with gravity or do they do
their own thing. I know we're close to the real release so it might be
better to just live with it.

Anyway please test the following patch if your FvwmWinList wanders.

Cheers,
Tim.

Index: FvwmWinList.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmWinList/FvwmWinList.c,v
retrieving revision 1.3
diff -u -B -b -r1.3 FvwmWinList.c
--- FvwmWinList.c	1998/11/06 02:23:10	1.3
+++ FvwmWinList.c	1998/11/18 17:17:54
@@ -26,11 +26,6 @@
  * Moving a window doesnt send M_CONFIGURE, as I thought it should. Desktop
  * for that button is not updated.
 
- * There seems to be something incosistant about Resizing and the value given
- * back as win_x, win_y.  SEE RESIZE_BUG_HACK for my work around. 
- 
- * Don Mahurin ([email-masked])
-
 */
 
 #define TRUE 1
@@ -120,8 +115,6 @@
 long CurrentDesk = 0;
 int ShowCurrentDesk = 0;
 
-int RESIZE_BUG_HACK = 0;
-
 int ItemCountD(List *list )
 {
 	if(!ShowCurrentDesk)
@@ -280,20 +273,24 @@
     case M_CONFIGURE_WINDOW:
       if (body[0] == win)
       {
-        win_x=(int)body[3];
-        win_y=(int)body[4];
-
+        /* gross hack for anchored resizes, should be able to call XResizeWindow
+           and have fvwm move the window correctly w.r.t. the gravity.  Until this
+           is so this program has to do its own gravity management. */
+        /* what happens here is that fvwm sends the size and position of
+           FvwmWinLists' parent, this has to compensate for the frame
+           to get the position of the WinList window so that when XMoveResize
+           is called the window doesn't creep */
+        /* if fvwm is fixed to handle windows resizing themselves then this
+           whole section can be deleted. */
         win_title=(int)body[9];
         win_border=(int)body[10];
+        win_x = (int)body[3] + win_border;
+        win_y = (int)body[4] + win_border + win_title;
       }
       if ((i = FindItem(&windows,body[0]))!=-1) 
       { 
-/*	printf("does it go here on MOVE %ld, %ld ?\n", i, CurrentDesk);
-*/
 	if(UpdateItemDesk(&windows, i, body[7]) > 0)
         {
-/*         printf("why doesnt it go here on MOVE ?\n");
-*/
           AdjustWindow();
           RedrawWindow(1);
         }
@@ -364,20 +361,6 @@
       break;
     case M_FOCUS_CHANGE:
 
-/* old coded, before Task bar code spliced in
-
-      i=FindItem(&windows,body[0]);
-      if (i==current_focus) break;
-      if (current_focus!=-1)
-	if ((ItemFlags(&windows,ItemID(&windows,current_focus))&ICONIFIED)==0)
-	  if (UpdateButtonSet(&buttons,current_focus,0)!=-1) redraw=1;
-      current_focus=-1;
-      if (i!=-1&&(ItemFlags(&windows,body[0])&ICONIFIED)) break;
-      current_focus=i;
-      if (current_focus!=-1)
-	if (UpdateButtonSet(&buttons,current_focus,2)!=-1) redraw=1;
-* end of old code */
-
 /* Code copied Straight from TaskBar */
 
     if ((i=FindItem(&windows,body[0]))!=-1)
@@ -398,9 +381,7 @@
 	CurrentDesk = body[0];
 	if(ShowCurrentDesk)
 	{
-	  RESIZE_BUG_HACK = 1;
 	  AdjustWindow();
-	  RESIZE_BUG_HACK = 0;
 	  RedrawWindow(1);
         }
       break;
@@ -712,50 +693,26 @@
   }
   new_width=max(new_width, MinWidth);
   new_width=min(new_width, MaxWidth);
-  new_height=(total*(fontheight+6+1)-1);
+  new_height=(total*(fontheight+6+1));
   if (WindowIsUp && (new_height!=win_height  || new_width!=win_width))
   {
     if (Anchor)
+    /* if fvwm is fixed to handle windows with gravity resizing themselves
+       this will be redundant, just a XResizeWindow will work. How to handle
+       NoAnchor in that case is left as an exercise for the reader. */
     {
       if (win_grav==SouthEastGravity || win_grav==NorthEastGravity)
         win_x-=(new_width-win_width);
 
       if (win_grav==SouthEastGravity || win_grav==SouthWestGravity)
         win_y-=(new_height-win_height);
-
-#if 0
-      if(RESIZE_BUG_HACK)
-      {
-        if (win_grav==SouthEastGravity || win_grav==NorthEastGravity)
-		win_x+= win_border - 2;
-	else
-		win_x-=win_border;
-
-	if (win_grav==SouthEastGravity || win_grav==SouthWestGravity)
-		win_y+=win_border - 2;
-	else	
-		win_y-=win_border;
-      }
-#else /* ckh - need to come up w/ better way to calculate win_x & _y */
-        if (win_grav==SouthEastGravity || win_grav==NorthEastGravity)
-		win_x+= win_border-3;
-	else
-		win_x-=win_border;
-
-	if (win_grav==SouthEastGravity || win_grav==SouthWestGravity)
-		win_y+=win_border-3;
-	else	
-		win_y-=win_border;
-#endif /* 0 */
 
-      XMoveResizeWindow(dpy,win,win_x+win_border,win_y+win_title+win_border,
-        new_width,new_height);
+      XMoveResizeWindow(dpy, win, win_x, win_y, new_width, new_height);
 
     }
     else
-      XResizeWindow(dpy, win, new_width,new_height);
+      XResizeWindow(dpy, win, new_width, new_height);
 
-    XSync(dpy,False);
   }
   UpdateArray(&buttons,-1,-1,new_width,-1);
   if (new_height>0) win_height = new_height;
@@ -877,7 +834,7 @@
     fore[i] = GetColor(ForeColor[i] == NULL ? ForeColor[0] : ForeColor[i]);
   }
 
-  win=XCreateSimpleWindow(dpy,Root,hints.x,hints.y,hints.width,hints.height,1,
+  win=XCreateSimpleWindow(dpy,Root,hints.x,hints.y,hints.width,hints.height,0,
     fore[0],back[0]);
 
   wm_del_win=XInternAtom(dpy,"WM_DELETE_WINDOW",False);

---

From: Dominik Vogt <[email-masked]>
Date: Wed, 18 Nov 1998 18:45:36 +0100

On Wed, Nov 18, 1998 at 05:33:48PM +0000, [email-masked] wrote:
> ... and found

I thought about that too but didn't get very far. There are some
other problems related to border width:

 - SnapAttraction patch snaps the right border of a window
   off-screen (just one pixel or so of the border remains
   visible, the rest is on the next page).

 - same when you use geometry: -0+x on any window. The border
   is not completely visible.

Could you see after this?

>...

I'd say we try to fix. This kind of patches isn't very
obvious to users so I don't care if the work carries on over
the release (as long as we don't break things of course).

Should I commit the patch now or are you unsure about that?

Bye

Dominik

---

From: Tim Phipps <[email-masked]>
Date: Thu, 19 Nov 1998 17:52:22 +0000

> Could you see after this?

I don't see these problems, what modules are affected

> the release (as long as we don't break things of course).

I've had another think about this and a look through the ICCCM seems to
suggest that compliant programmes should not make XMove/ResizeWindow
calls, they should use ConfigureWindow instead. A look at the man page
for XMove/ResizeWindow says that for reparented windows the call will be
translated to a ConfigureRequest event so it may well be perfectly
reasonable to use XMove/ResizeWindow given that the window manager will
not be able to tell the difference between XMove and XConfigure. The
ICCCM is pretty clear that gravity must be respected when a window is
initially created and mapped but then it goes on to say that the window
manager is free to override the gravity later.  I'd say that fvwm
shouldn't be touched and clients should not assume that their gravity
can be used to get their position right if they resize themselves.  It
looks like the ICCCM doesn't specify how windows should resize
themselves.

> Should I commit the patch now or are you unsure about that?

Commit it, plus the following please:

FvwmGoodStuff.c: off by one due to borderwidth (not tested)
FvwmBanner.c: not centred by one and won't display a pixmap == screen
size
FvwmIconBox.c: got it right but I cleaned it up to prevent confusion
FvwmIconMan.c: ditto
FvwmIdent.c: ditto (should also apply to FvwmIdent-de.c &
FvwmIdent-foo.c)

Index: FvwmGoodStuff.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/extras/FvwmGoodStuff/FvwmGoodStuff.c,v
retrieving revision 1.3
diff -u -B -b -r1.3 FvwmGoodStuff.c
--- FvwmGoodStuff.c	1998/11/06 02:22:43	1.3
+++ FvwmGoodStuff.c	1998/11/19 15:08:06
@@ -892,7 +892,7 @@
     }
 
   mysizehints.win_gravity = gravity;
-#define BW 1
+
   if(d_depth < 2)
     {
       back_pix = GetColor("white");
@@ -911,7 +911,7 @@
 
   main_win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y,
 				 mysizehints.width,mysizehints.height,
-				 BW,fore_pix,back_pix);
+				 0,fore_pix,back_pix);
   XSetWMProtocols(dpy,main_win,&wm_del_win,1);
 
   XSetWMNormalHints(dpy,main_win,&mysizehints);
Index: FvwmBanner.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmBanner/FvwmBanner.c,v
retrieving revision 1.6
diff -u -B -b -r1.6 FvwmBanner.c
--- FvwmBanner.c	1998/11/12 11:22:04	1.6
+++ FvwmBanner.c	1998/11/19 16:38:42
@@ -184,7 +184,7 @@
 
   win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y,
 				 mysizehints.width,mysizehints.height,
-				 1,fore_pix ,None);
+				 0,fore_pix ,None);

   /* Set assorted info for the window */
Index: FvwmIconBox.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmIconBox/FvwmIconBox.c,v
retrieving revision 1.4
diff -u -B -b -r1.4 FvwmIconBox.c
--- FvwmIconBox.c	1998/11/15 18:00:13	1.4
+++ FvwmIconBox.c	1998/11/19 16:55:31
@@ -927,14 +927,14 @@
     {
       if (xneg)
 	{
-	  mysizehints.x = DisplayWidth(dpy,screen) + x - mysizehints.width-2;
+	  mysizehints.x = DisplayWidth(dpy,screen) + x - mysizehints.width;
 	  gravity = NorthEastGravity;
 	}
       else 
 	mysizehints.x = x;
       if (yneg)
 	{
-	  mysizehints.y = DisplayHeight(dpy,screen) + y - mysizehints.height-2;
+	  mysizehints.y = DisplayHeight(dpy,screen) + y - mysizehints.height;
 	  gravity = SouthWestGravity;
 	}
       else 
@@ -947,7 +947,7 @@
     }
 
   mysizehints.win_gravity = gravity;
-#define BW 1
+
   if(d_depth < 2)
     {
       back_pix = icon_back_pix = act_icon_fore_pix = GetColor("white");
@@ -973,7 +973,7 @@
 
   main_win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y,
 				 mysizehints.width,mysizehints.height,  
-				 BW,fore_pix,back_pix);
+				 0,fore_pix,back_pix);
   XSetWMProtocols(dpy,main_win,&wm_del_win,1);
   XSelectInput(dpy,main_win,MW_EVENTS);
 
Index: x.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmIconMan/x.c,v
retrieving revision 1.6
diff -u -B -b -r1.6 x.c
--- x.c	1998/11/15 18:00:14	1.6
+++ x.c	1998/11/19 17:32:50
@@ -607,9 +607,9 @@
   man->geometry.height = man->geometry.rows * man->geometry.boxheight;
 
   if ((geometry_mask & XValue) && (geometry_mask & XNegative))
-    man->geometry.x += globals.screenx - man->geometry.width - 2;
+    man->geometry.x += globals.screenx - man->geometry.width;
   if ((geometry_mask & YValue) && (geometry_mask & YNegative))
-    man->geometry.y += globals.screeny - man->geometry.height - 2;
+    man->geometry.y += globals.screeny - man->geometry.height;
 
   if (globals.transient) {
     Window dummyroot, dummychild;
@@ -708,7 +708,7 @@
   man->theWindow = XCreateWindow (theDisplay, theRoot, sizehints.x,
 				  sizehints.y, man->geometry.width,
 				  man->geometry.height,
-				  1, CopyFromParent, InputOutput,
+				  0, CopyFromParent, InputOutput,
 				  (Visual *)CopyFromParent, winattrmask,
 				  &winattr);
 #ifdef SHAPE
Index: FvwmIdent.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmIdent/FvwmIdent.c,v
retrieving revision 1.3
diff -u -B -b -r1.3 FvwmIdent.c
--- FvwmIdent.c	1998/11/06 02:23:04	1.3
+++ FvwmIdent.c	1998/11/19 17:39:58
@@ -389,13 +389,13 @@
 
   if((y+height+100)>ScreenHeight)
     {
-      y = ScreenHeight- 2 - height - 10;
+      y = ScreenHeight - height - 10;
       mysizehints.win_gravity = SouthWestGravity;      
     }
 	
   if((x+lmax+100)>ScreenWidth)
     {
-      x = ScreenWidth - 2 - lmax - 10;
+      x = ScreenWidth - lmax - 10;
       if((y+height+100)>ScreenHeight)
 	mysizehints.win_gravity = SouthEastGravity;            
       else
@@ -405,7 +405,7 @@
   mysizehints.y = y;

-#define BW 1
+
   if(d_depth < 2)
     {
       back_pix = GetColor("white");
@@ -420,7 +420,7 @@
 
   main_win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y,
 				 mysizehints.width,mysizehints.height,
-				 BW,fore_pix,back_pix);
+				 0,fore_pix,back_pix);
   XSetTransientForHint(dpy,main_win,app_win);
   wm_del_win = XInternAtom(dpy,"WM_DELETE_WINDOW",False);
   XSetWMProtocols(dpy,main_win,&wm_del_win,1);

---

From: Dan Espen <[email-masked]>
Date: Thu, 19 Nov 1998 13:06:16 -0500

> FvwmIdent.c: ditto (should also apply to FvwmIdent-de.c &

Argh!      After the  patch   is applied,   I'll   take  the  parts of
FvwmIdent-de.c that are  supposed to be  in  FvwmIdent.c and put  them
there and remove the  2 extra files.   (Could have sworn this was done
long ago.)

--
Dan Espen                                Phone: (732) 699-5570
444 Hoes Lane  Room RRC 1C-214           E-mail: [email-masked]
Piscataway, NJ 08854
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Dominik Vogt <[email-masked]>
Date: Thu, 19 Nov 1998 19:23:51 +0100

> I don't see these problems, what modules are affected

Any window, not just a specific module. Perhaps only the shadow
is off-screen? Try a low border width.

> Commit it, plus the following please:

OK, will be in tomorrow.

Bye

Dominik

---

From: Tim Phipps <[email-masked]>
Date: Fri, 20 Nov 1998 10:47:33 +0000

> is off-screen? Try a low border width.
I'll have a look at this, and I'll have a go at the handling of shaped
windows too: Fvwm will put a border round a shaped window and this
causes odd things with geometry and SnapAttraction.

Cheers,
Tim.

---

From: Dominik Vogt <[email-masked]>
Date: Fri, 20 Nov 1998 13:00:27 +0100

> causes odd things with geometry and SnapAttraction.

I tried with a big border size. Its definitely only a few pixels
(one or two), regardless of how thick the border is.

Bye

Dominik

---

From: Magnus & Tina <[email-masked]>
Date: Fri, 20 Nov 1998 22:24:59 +0100 (GMT+0100)

Whatever i specify as direction for a panel in FvwmButtons the 
panel still pops up at the same place.
It is always in relation to the upper left corner of the orriginal button.

/// Magnus Back

############################################################################
# FvwmButtons

*FvwmButtonsFore     Black
*FvwmButtonsBack     wheat2
#*FvwmButtonsBack        rgb:b0/b0/b0
*FvwmButtonsFont     -adobe-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*
*FvwmButtonsGeometry -1-1
*FvwmButtonsRows     15
*FvwmButtonsBoxSize  smart

*FvwmButtons (1x1 Swallow(UseOld,NoKill) procmeter 'Exec procmeter -force-spkt
cpu mem-free&')
*FvwmButtons (Swallow(UseOld,NoKill) wmppp 'Exec wmppp -u 1 &')
*FvwmButtons (Swallow(UseOld,NoKill) xclock 'Exec xclock -update 1 -bg wheat2
-padding 0 -hd gold -hl black &')
#*FvwmButtons (Title Staroffice,Icon good.xpm,Action 'Exec
/opt/kde/Office4/bin/soffice&')
*FvwmButtons (Title Rxvt,Icon ModeledHeadInClouds.xpm,Action 'Exec rxvt -iconic
-bg black -fg white&')
*FvwmButtons (Title Filerunner,Icon FileManager.xpm,Action 'Exec fr &')
*FvwmButtons (Title Nedit,Icon text.xpm,Action 'Exec nedit &')
*FvwmButtons (Title Media,Panel (down) media)
*FvwmButtons (Title Mozilla,Icon NetscapeLogo.xpm,Action 'Exec
/usr/local/netscape/netscape &')
*FvwmButtons (Title News,Icon News.xpm,Action 'Exec knews&')
*FvwmButtons (Title Mail,Icon xfmail.xpm,Action 'Exec xfmail&')
*FvwmButtons (Title Gimp,Icon gimpicon2.xpm,Action 'Exec gimp&')
*FvwmButtons (Title Cgoban,Icon cgoban.xpm,Action 'Exec cgoban&')
*FvwmButtons (Title Quit,Icon BulletHole.xpm,Action Quit)
*FvwmButtons (Swallow(UseOld,NoKill) FvwmPager 'FvwmPager 0 0')

*FvwmButtonsPanel media
*FvwmButtonsGeometry -172+73
*FvwmButtonsColumns     3
*FvwmButtonsFore     Black
*FvwmButtonsBack     wheat2
*FvwmButtonsFont     -adobe-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*
*FvwmButtons (Title Rxvt,Icon ModeledHeadInClouds.xpm,Action 'Exec rxvt -iconic
-bg black -fg white&')
*FvwmButtons (Title Filerunner,Icon FileManager.xpm,Action 'Exec fr &')
*FvwmButtons (Title Nedit,Icon text.xpm,Action 'Exec nedit &')

---

From: Tim Phipps <[email-masked]>
Date: Tue, 24 Nov 1998 10:44:17 +0000

> Could you see after this?

Well I tried, but I can't see where this is happening. Can you reproduce
this and send the config file setup.  I thought I had seen it but I
can't reproduce it.  Maybe it's one for Jitterbug.

Cheers,
Tim.

---

From: Dominik Vogt <[email-masked]>
Date: Tue, 24 Nov 1998 11:58:22 +0100

> can't reproduce it.  Maybe it's one for Jitterbug.

I'm really not doing anything unsusual, just BorderWidth and HandleWidth
set to 3. I can play with it at home to see if it is caused by something
in my config file tomorrow. Unfortunately you won't be able to do much
with my .fvwm2rc as it needs lots of files in various directories on
my system.

Bye

Dominik