Subject: Clever Placement is not clever

From: Olivier Chapuis <[email-masked]>
Date: Sun, 11 Jun 2000 13:01:04 +0200

Hello,

IMHO the clever placement style is not very clever.
The point is that the algorithm is based on the surface
in pixel that the new window cover. So, small windows
are very often covered by the new window. Moreover,
these small windows are often important windows
(a pager, a "winlist" with a few windows represented 
in it, a FvwmButton panel button ...etc. and you may 
do not want that such a window be stays on top).
I think that this was noted by some one a few month
ago?

I've mad a very simple patch which solves this and
more. The idea is to use a *percentage* method in
the place of the size method and also to maximize
percentage which are close to 100%. Moreover, the
patch try more positions than the current code.

The second point, is that this patch is not perfect but
gives IMHO very good results (the computation is done,
as before, windows by windows and we probably need some
more global computations, but such approach probably
need a very big patch and a quite elaborated mathematical 
theory ...).

So, attached to this mail the patch that I would like to
apply if I've got two votes for it and no against (one may
consider that it is a real bug fix patch but I am prudent).
Note that the patch is an "ifdef patch" so that we can easily
make comparison between the "new" and the "current" clever
placement code.

Olivier

Index: placement.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/placement.c,v
retrieving revision 1.66
diff -u -r1.66 placement.c
--- placement.c	2000/05/31 00:44:34	1.66
+++ placement.c	2000/06/11 11:02:20
@@ -84,6 +84,7 @@
 #else
 #define AVOIDICON 10    /*  Try hard no to place windows over icons */
 #endif
+#define NEW_CLEVERPLACEMENT_CODE 1
 
 /*  RBW - 11/02/1998  */
 static int SmartPlacement(FvwmWindow *t,
@@ -248,6 +249,9 @@
   int xtest;
   FvwmWindow *testw;
   int PageRight     =  Scr.MyDisplayWidth - pdeltax;
+#ifdef NEW_CLEVERPLACEMENT_CODE
+  int minx_inc = Scr.MyDisplayWidth/20;
+#endif
   int stickyx, stickyy;
 
   /* Test window at far right of screen */
@@ -299,6 +303,9 @@
         xnew = MIN(xnew, xtest);
     }
   }
+#ifdef NEW_CLEVERPLACEMENT_CODE
+  xnew = MIN(xnew,x+minx_inc);
+#endif
   return xnew;
 }
 /*  RBW - 11/02/1998  */
@@ -309,6 +316,9 @@
   int ytest;
   FvwmWindow *testw;
   int PageBottom    =  Scr.MyDisplayHeight - pdeltay;
+#ifdef NEW_CLEVERPLACEMENT_CODE
+  int miny_inc = Scr.MyDisplayHeight/20;
+#endif
   int stickyy;
 
   /* Test window at far bottom of screen */
@@ -353,6 +363,9 @@
         ynew = MIN(ynew, ytest);
     }
   }
+#ifdef NEW_CLEVERPLACEMENT_CODE
+  ynew = MIN(ynew,y+miny_inc);
+#endif
   return ynew;
 }
 
@@ -366,7 +379,11 @@
   int y12, y21, y22;
   int xl, xr, yt, yb; /* xleft, xright, ytop, ybottom */
   int aoi = 0;	    /* area of interference */
+#ifdef NEW_CLEVERPLACEMENT_CODE
+  float anew;
+#else
   int anew;
+#endif
   int avoidance_factor;
   int PageBottom    =  Scr.MyDisplayHeight - pdeltay;
   int PageRight     =  Scr.MyDisplayWidth - pdeltax;
@@ -420,6 +437,20 @@
       yt = MAX(y11, y21);
       yb = MIN(y12, y22);
       anew = (xr - xl) * (yb - yt);
+#ifdef NEW_CLEVERPLACEMENT_CODE
+      /* normalisation */
+      if ((x22-x21)*(y22-y21) != 0 && (x12-x11)*(y12-y11) != 0) {
+	anew = MAX(anew/((x22-x21)*(y22-y21)),anew/((x12-x11)*(y12-y11)))*100;
+	if (anew >= 99)
+	  anew *= 12;
+	else if (anew >= 95)
+	  anew *= 6;
+	else if (anew >= 85)
+	  anew *= 4;
+	else if (anew >= 60)
+	  anew *= 2;
+      }
+#endif
       if(IS_ICONIFIED(testw))
         avoidance_factor = AVOIDICON;
       else if(compare_window_layers(testw, t) > 0)

---

From: Olivier Chapuis <[email-masked]>
Date: Wed, 21 Jun 2000 06:05:25 +0200

> make comparison between the "new" and the "current" clever

Hello,
So no body try the patch and the current clever placement code?
Olivier
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
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: Mikhael Goikhman <[email-masked]>
Date: Sun, 25 Jun 2000 22:22:23 +0300

> So no body try the patch and the current clever placement code?

First to say, I didn't try this patch because I don't use CleverPlacement,
so I would not notice a difference (only the one who is experienced in
CleverPlacement would even notice). Your changes seem logical, I suggest
to commit them to enable a easier testing for people who are interesting.
If there are complains the preprocessor variable can always be unset.

Regards,
Mikhael.

---

From: Michael Han <[email-masked]>
Date: Sun, 25 Jun 2000 13:04:53 -0700

> So no body try the patch and the current clever placement code?
 
Olivier, I just tried out your patch. Some observations:

1) I haven't looked carefully at how you've changed the placement
logic, but CleverPlacement now does something I find odd... When
placing a largish new window, CleverPlacement may decide not to fill
unused desktop space in order to avoid obscuring a small window. I
don't know if I agree with that behavior.

2) CleverPlacement occassionally seems to place windows beneath
StaysOnTop windows. I'm not exactly sure why that happens, but the
rule of CleverPlacement appears to have been never to overlap
StaysOnTops, which I thought was a good rule.

In general though, I think I like the new CleverPlacement logic. It
sometimes has results I find surprising, but generally, I think those
results make better sense than the old code.
-- 
[email-masked]                               http://www.mikehan.com/
coffee achiever                              San Francisco, California
The life uncaffeinated is not worth living.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
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: Olivier Chapuis <[email-masked]>
Date: Tue, 27 Jun 2000 09:46:34 +0200

> StaysOnTops, which I thought was a good rule.
 
Agree, this is fixed in the version I've just commited.

> results make better sense than the old code.

Yes, the result is sometimes surprising because the placement of a new
window is done "against" each mapped windows. It will be better that the
placement was done "against" all the mapped window viewed as one
polygonal window. However, this leads to complicated computations and
I'm afraid that we have to show that P=NP before having a perfect
clever placement. I will think on this after 2.4 :o)
Any way, I hope that, in the average, the new clever placement code gives 
a better result than the old code (and for a minimal effort).

Thanks, Olivier