Subject: IconBox "Gravity"

From: David Welton <[email-masked]>
Date: Mon, 13 Apr 1998 13:27:16 -0700

Hi, I found out that fvwm2 lacks any way to direct how icons are
placed within the IconBox, so I sat down and took a look at the code
and came up with this fix.

Basically, it looks at where your IconBox lies on the screen, and uses
this to determine how to lay out icons.  If it is towards the left, it
goes left to right, and right to left if it is towards the right.  If
it is towards the top, it goes top to bottom, etc...   So that with my
IconBox in the lower right corner, it starts at the bottom of the
screen and goes right to left and then up.  It's not as good as
actually having an IconBoxGravity (which should let you set both the
right to left and top to bottom gravities), but I think it's good
enough for what most people want, and it's something that could easily
be built on top of.

I'm not subscribed to this list, so please CC replies to me.

Thanks:-)
-- 
David Welton                          http://www.efn.org/~davidw 

	Debian GNU/Linux - www.debian.org

--- fvwm2-2.0.46-BETA/fvwm/icons.c	Mon Aug 11 07:39:04 1997
+++ icons.c	Mon Apr 13 13:11:21 1998
@@ -366,6 +366,8 @@
   Bool loc_ok;
   int real_x=10, real_y=10;
   int new_x, new_y;
+  int incr_x, incr_y;  /* we need these to set which direction IconBox
+			  takes when placing icons */
 
   /* New! Put icon in same page as the center of the window */
   /* Not a good idea for StickyIcons */
@@ -384,7 +386,7 @@
     }
   else
     {
-      base_x=((t->frame_x+Scr.Vx+(t->frame_width>>1))/Scr.MyDisplayWidth)*
+      base_x=((t->frame_x + Scr.Vx + (t->frame_width>>1)) /Scr.MyDisplayWidth) *
 	Scr.MyDisplayWidth - Scr.Vx;
       base_y=((t->frame_y+Scr.Vy+(t->frame_height>>1))/Scr.MyDisplayHeight)*
 	Scr.MyDisplayHeight - Scr.Vy;
@@ -409,70 +411,98 @@
       width = t->icon_p_width;
       height = t->icon_w_height + t->icon_p_height;
       loc_ok = False;  
+
       
       /* check all boxes in order */
       /* In each IconBox, start at the upper left, travel right, then
        * down */
-      test_y = t->IconBox[1]+base_y;
-      
+     
       temp_h = height;
       temp_w = width;
-      
+
+
+      /* test_y and test_x determine where we start placing icons  */ 
+
+      if (((t->IconBox[3] + t->IconBox[1]) / 2) > Scr.MyDisplayHeight / 2) { 
+	/* more towards the bottom  */ 
+	test_y = t->IconBox[3] + base_y - temp_h - 5;  /* arbitrary number  */
+	incr_y = -3;
+      } else {
+	/* more towards the top  */ 
+	test_y = t->IconBox[1] + base_y ;  /* arbitrary number  */ 	  
+	incr_y = 3;
+      }
+            
       /* OK second try at this.
        * If the window is taller than the icon box, ignore the icon height
        * when figuring where to put it. Same goes for the width */
       /* This should permit reasonably graceful handling of big icons. */
+      /* l t r b  */ 
+      /* 0 1 2 3  */ 
       if(width >= (t->IconBox[2] - t->IconBox[0]))
-	    temp_w = 0;
-	  if(height >= (t->IconBox[3] - t->IconBox[1]))
-	    temp_h = 0;
+	temp_w = 0;
+      if(height >= (t->IconBox[3] - t->IconBox[1]))
+	temp_h = 0;
+      
+      while(((test_y + temp_h) < (t->IconBox[3]+base_y))&&(!loc_ok) && 
+	    ((test_y + temp_h) > (t->IconBox[1]+base_y)))
+	{
+	  if (((t->IconBox[2] + t->IconBox[0]) / 2) > Scr.MyDisplayWidth / 2)  { 
+	    /* more towards the right  */ 
+	    test_x = t->IconBox[2] + base_x - temp_w - 5;  /* arbitrary number  */
+	    incr_x = -3;
+	  } else {
+	    /* more towards the left  */ 
+	    test_x = t->IconBox[0] + base_x;  /* arbitrary number  */
+	    incr_x = 3;
+	  }
 	  
-	  while(((test_y + temp_h) < (t->IconBox[3]+base_y))&&(!loc_ok))
+	  while(((test_x + temp_w) < (t->IconBox[2]+base_x))&& (!loc_ok) &&	
+		((test_x + temp_w) > (t->IconBox[0]+base_x)))
 	    {
-	      test_x = t->IconBox[0]+base_x;
-	      while(((test_x + temp_w) < (t->IconBox[2]+base_x))&&
-		    (!loc_ok))
+	      real_x = test_x;
+	      real_y = test_y;
+	      
+	      if(test_x + width > (Scr.MyDisplayWidth-2+base_x))
+		real_x = Scr.MyDisplayWidth - width -2 + base_x;
+	      if(test_y + height > (Scr.MyDisplayHeight-2+base_y))
+		real_y = Scr.MyDisplayHeight - height -2+base_y;
+	      if(test_x <base_x)
+		real_x = base_x;
+	      if(test_y < base_y)
+		real_y = base_y;
+	      loc_ok = True;
+	      test_window = Scr.FvwmRoot.next;
+	     
+	      while((test_window != (FvwmWindow *)0) && (loc_ok == True))
 		{
-		  real_x = test_x;
-		  real_y = test_y;
-		  
-		  if(test_x + width > (Scr.MyDisplayWidth-2+base_x))
-		    real_x = Scr.MyDisplayWidth - width -2 + base_x;
-		  if(test_y + height > (Scr.MyDisplayHeight-2+base_y))
-		    real_y = Scr.MyDisplayHeight - height -2+base_y;
-		  if(test_x <base_x)
-		    real_x = base_x;
-		  if(test_y < base_y)
-		    real_y = base_y;
-		  loc_ok = True;
-		  test_window = Scr.FvwmRoot.next;
-		  while((test_window != (FvwmWindow *)0)&&(loc_ok == True))
+		  if(test_window->Desk == t->Desk)
 		    {
-		      if(test_window->Desk == t->Desk)
+		      if((test_window->flags&ICONIFIED)&&
+			 (test_window->icon_w || test_window->icon_pixmap_w)&&
+			 (test_window != t))
 			{
-			  if((test_window->flags&ICONIFIED)&&
-                             (test_window->icon_w||test_window->icon_pixmap_w)&&
-			     (test_window != t))
-			    {
-			      tw=test_window->icon_p_width;
-			      th=test_window->icon_p_height+
-				test_window->icon_w_height;
-			      tx = test_window->icon_x_loc;
-			      ty = test_window->icon_y_loc;
+			  tw=test_window->icon_p_width;
+			  th=test_window->icon_p_height+
+			    test_window->icon_w_height;
+			  tx = test_window->icon_x_loc;
+			  ty = test_window->icon_y_loc;
 			  
-			      if((tx<(real_x+width+3))&&((tx+tw+3) > real_x)&&
-				 (ty<(real_y+height+3))&&((ty+th + 3)>real_y))
-				{
-				  loc_ok = False;
-				}
+			  /* switched out incr_x and incr_y for 3 - davidw */ 
+			  if((tx < (real_x + width + incr_x )) && ((tx + tw + incr_x) > real_x)&&
+			     (ty < (real_y + height + incr_y)) && ((ty + th + incr_y) > real_y))
+			    {
+			      loc_ok = False;
 			    }
 			}
-		      test_window = test_window->next;
 		    }
-		  test_x +=3;
+		  test_window = test_window->next;
 		}
-	      test_y +=3;
+	      test_x += incr_x;   /* we can set this var to + or - to
+				     do the right thing */
 	    }
+	  test_y += incr_y;  
+	}
       if(loc_ok == False)
 	return;
       t->icon_x_loc = real_x;

---

From: Dan Espen <[email-masked]>
Date: Mon, 13 Apr 1998 16:51:16 -0400

> I'm not subscribed to this list, so please CC replies to me.

Ok, just this once.

Take a look at the unofficial patches site, you will find
the "iconboxes patch", including icon gravity.

--
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].