Autogrowing FvwmIconBox

Dear FVWM-developers!
I have a small patch for FvwmIconBox.c file which makes this module autogrowing to fit in all the icons. This feature is activated when both scrollbars are hidden that is there are two lines in configuration file :

*FvwmIconBox:HideSC Horizontal
*FvwmIconBox:HideSC Vertical

The patch is below

--- modules/FvwmIconBox/FvwmIconBox.c	2007-10-23 14:14:36.000000000 +0400
+++ ../../fvwm-2.5.26/modules/FvwmIconBox/FvwmIconBox.c	2008-06-06 03:56:43.000000000 +0400
@@ -433,6 +433,7 @@
 		if (!(local_flags & HIDE_V))
 		  XResizeWindow(dpy ,v_scroll_bar,
 				bar_width, Height - bar_width*2);
+		if ( (local_flags & (HIDE_V|HIDE_H)) !=3) {
 		GetIconwinSize(&diffx, &diffy);
 		if (primary == BOTTOM || secondary == BOTTOM)
 		  icon_win_y -= Height - oldh;
@@ -456,6 +457,7 @@
 		  XClearWindow(dpy,main_win);
 		  RedrawWindow(NULL);
 		}
+		}
 	      }
 	      else if (ready && CSET_IS_TRANSPARENT(colorset) &&
 		       (Event.xconfigure.send_event ||
@@ -1600,6 +1602,7 @@
     SetWindowBackground(
       dpy, icon_win, icon_win_width, icon_win_height, &Colorset[(colorset)],
       Pdepth, NormalGC, True);
+    if ((local_flags & (HIDE_V|HIDE_H))!=3){
     SetWindowBackground(dpy, holder_win, main_width - h_margin,
       main_height - v_margin, &Colorset[(colorset)], Pdepth, NormalGC, True);
     XSetWindowBackground(dpy, h_scroll_bar, back_pix);
@@ -1607,10 +1610,12 @@
     XSetWindowBackground(dpy, l_button, back_pix);
     XSetWindowBackground(dpy, r_button, back_pix);
     XSetWindowBackground(dpy, t_button, back_pix);
+    }
     XSetWindowBackground(dpy, b_button, back_pix);
     XSetForeground(dpy, ReliefGC, hilite_pix);
     XSetBackground(dpy, ReliefGC, back_pix);
     XSetForeground(dpy, ShadowGC, shadow_pix);
+      if ((local_flags & (HIDE_V|HIDE_H))!=3){
     XSetBackground(dpy, ShadowGC, back_pix);
     XClearWindow(dpy, main_win);
     XClearWindow(dpy, holder_win);
@@ -1620,6 +1625,7 @@
     XClearWindow(dpy, l_button);
     XClearWindow(dpy, r_button);
     XClearWindow(dpy, t_button);
+    }
     XClearWindow(dpy, b_button);
   }
   if (color == Iconcolorset) {
@@ -1679,16 +1685,26 @@
 {
   *dx = icon_win_width;
   *dy = icon_win_height;
-
   if (primary == LEFT || primary == RIGHT){
-    icon_win_width = max(Width, UWidth * Lines + interval - 1);
-    icon_win_height = max(Height, UHeight * (max(0,
+    if ((local_flags & (HIDE_V|HIDE_H)) ==3){
+      //setting HIDE_B makes IconBox autogrowing
+      icon_win_width = UWidth*(min(Lines,num_icons)+1)+interval-1;
+      icon_win_height = UHeight * ((num_icons-1)/Lines + 2)+interval-1;
+    } else {
+      icon_win_width = max(Width, UWidth * Lines + interval - 1);
+      icon_win_height = max(Height, UHeight * (max(0,
 						 (num_icons-1))/Lines
-					     + 1) - 1 + interval);
-  }else{
-    icon_win_width = max(Width, UWidth * (max(0,num_icons-1) / Lines +
+     				     + 1) - 1 + interval);
+    }
+  } else {
+    if ((local_flags & (HIDE_V|HIDE_H)) ==3){
+          icon_win_height = UHeight*(min(Lines,num_icons)+1)+interval-1;
+	  icon_win_width = UWidth * ((num_icons-1)/Lines + 2)+interval-1;
+    } else {
+      icon_win_width = max(Width, UWidth * (max(0,num_icons-1) / Lines +
 					  1) + interval - 1);
-    icon_win_height = max(Height, UHeight * Lines - 1 + interval);
+      icon_win_height = max(Height, UHeight * Lines - 1 + interval);
+    }
   }
   *dx = icon_win_width - *dx;
   *dy = icon_win_height - *dy;
@@ -2223,7 +2239,7 @@
 	  tmp++;
 	if (strncasecmp(tmp, "Horizontal", 10) == 0)
 	  local_flags |= HIDE_H;
-	else if (strncasecmp(tmp, "Vertical", 8) == 0)
+	if (strncasecmp(tmp, "Vertical", 8) == 0)
 	  local_flags |= HIDE_V;
       }
       else if (strncasecmp(tline,CatString3("*",MyName,
@@ -2641,11 +2657,23 @@
   case M_ADD_WINDOW:
     if (AddItem(cfgpacket) == True && ready){
       GetIconwinSize(&diffx, &diffy);
+      if ((local_flags&(HIDE_V|HIDE_H))==3){
+	icon_win_x=0;
+	icon_win_y=0;
+	if (primary == BOTTOM || secondary == BOTTOM)
+	icon_win_y = UHeight;
+	if (primary == RIGHT || secondary == RIGHT)
+	icon_win_x = UWidth;
+	      XResizeWindow(dpy, main_win,
+			icon_win_width, icon_win_height);
+      } else {
       if (diffy && (primary == BOTTOM || secondary == BOTTOM))
 	icon_win_y += diffy;
       if (diffx && (primary == RIGHT || secondary == RIGHT))
 	icon_win_x += diffx;
+      }
       XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y,
+
 			icon_win_width, icon_win_height);
       if ((diffx || diffy) && (colorset >= 0))
 	SetWindowBackground(dpy, icon_win, icon_win_width,
@@ -2656,6 +2684,16 @@
   case M_DESTROY_WINDOW:
     if (DeleteItem(body[0]) && ready){
       GetIconwinSize(&diffx, &diffy);
+      if ( (local_flags & (HIDE_V|HIDE_H)) == 3) {
+	icon_win_x=0;
+	icon_win_y=0;
+	if (primary == BOTTOM || secondary == BOTTOM)
+	icon_win_y = UHeight;
+	if (primary == RIGHT || secondary == RIGHT)
+	icon_win_x = UWidth;
+	XResizeWindow(dpy, main_win,
+			icon_win_width, icon_win_height);
+      } else {
       if (diffy && (primary == BOTTOM || secondary == BOTTOM))
 	icon_win_y += diffy;
       if (diffx && (primary == RIGHT || secondary == RIGHT))
@@ -2668,6 +2706,7 @@
 	icon_win_x = icon_win_width - Width;
       if (icon_win_y + Height > icon_win_height)
 	icon_win_y = icon_win_height - Height;
+      }
       XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y,
 			icon_win_width, icon_win_height);
       if ((diffx || diffy) && (colorset >= 0))

Thanks.

You’ve got some whitespace corruption, and you’re using C99 comments which is not consistent with the rest of the code – please use: /* … */ instead.

Resubmit it here, and I’ll take a better look. Note that you’re about the third person ever to actually use FvwmIconBox. I personally hope it dies a horrible death.

– Thomas Adam

Here is improved version:

--- modules/FvwmIconBox/FvwmIconBox.c    2007-10-23 14:14:36.000000000 +0400
+++ ../../fvwm-2.5.26/modules/FvwmIconBox/FvwmIconBox.c    2008-06-10 10:16:13.000000000 +0400
@@ -433,28 +433,30 @@
         if (!(local_flags & HIDE_V))
           XResizeWindow(dpy ,v_scroll_bar,
                 bar_width, Height - bar_width*2);
-        GetIconwinSize(&diffx, &diffy);
-        if (primary == BOTTOM || secondary == BOTTOM)
-          icon_win_y -= Height - oldh;
-        if (primary == RIGHT || secondary == RIGHT)
-          icon_win_x -= Width - oldw;
-        if (icon_win_x < 0)
-          icon_win_x = 0;
-        if (icon_win_y < 0)
-          icon_win_y = 0;
-        if (icon_win_x + Width > icon_win_width)
-          icon_win_x = icon_win_width - Width;
-        if (icon_win_y + Height > icon_win_height)
-          icon_win_y = icon_win_height - Height;
-        XMoveResizeWindow(dpy, icon_win, -icon_win_x,
+        if ( (local_flags & (HIDE_V|HIDE_H)) !=3) {
+          GetIconwinSize(&diffx, &diffy);
+          if (primary == BOTTOM || secondary == BOTTOM)
+            icon_win_y -= Height - oldh;
+          if (primary == RIGHT || secondary == RIGHT)
+            icon_win_x -= Width - oldw;
+          if (icon_win_x < 0)
+            icon_win_x = 0;
+          if (icon_win_y < 0)
+            icon_win_y = 0;
+          if (icon_win_x + Width > icon_win_width)
+            icon_win_x = icon_win_width - Width;
+          if (icon_win_y + Height > icon_win_height)
+            icon_win_y = icon_win_height - Height;
+          XMoveResizeWindow(dpy, icon_win, -icon_win_x,
                   -icon_win_y, icon_win_width,
                   icon_win_height);
-        AdjustIconWindows();
-        if (colorset >= 0)
-          change_colorset(colorset);
-        else {
-          XClearWindow(dpy,main_win);
-          RedrawWindow(NULL);
+          AdjustIconWindows();
+          if (colorset >= 0)
+            change_colorset(colorset);
+          else {
+            XClearWindow(dpy,main_win);
+            RedrawWindow(NULL);
+          }
         }
           }
           else if (ready && CSET_IS_TRANSPARENT(colorset) &&
@@ -1600,26 +1602,30 @@
     SetWindowBackground(
       dpy, icon_win, icon_win_width, icon_win_height, &Colorset[(colorset)],
       Pdepth, NormalGC, True);
-    SetWindowBackground(dpy, holder_win, main_width - h_margin,
-      main_height - v_margin, &Colorset[(colorset)], Pdepth, NormalGC, True);
-    XSetWindowBackground(dpy, h_scroll_bar, back_pix);
-    XSetWindowBackground(dpy, v_scroll_bar, back_pix);
-    XSetWindowBackground(dpy, l_button, back_pix);
-    XSetWindowBackground(dpy, r_button, back_pix);
-    XSetWindowBackground(dpy, t_button, back_pix);
+    if ((local_flags & (HIDE_V|HIDE_H))!=3){
+      SetWindowBackground(dpy, holder_win, main_width - h_margin,
+              main_height - v_margin, &Colorset[(colorset)], Pdepth, NormalGC, True);
+      XSetWindowBackground(dpy, h_scroll_bar, back_pix);
+      XSetWindowBackground(dpy, v_scroll_bar, back_pix);
+      XSetWindowBackground(dpy, l_button, back_pix);
+      XSetWindowBackground(dpy, r_button, back_pix);
+      XSetWindowBackground(dpy, t_button, back_pix);
+    }
     XSetWindowBackground(dpy, b_button, back_pix);
     XSetForeground(dpy, ReliefGC, hilite_pix);
     XSetBackground(dpy, ReliefGC, back_pix);
     XSetForeground(dpy, ShadowGC, shadow_pix);
-    XSetBackground(dpy, ShadowGC, back_pix);
-    XClearWindow(dpy, main_win);
-    XClearWindow(dpy, holder_win);
-    XClearWindow(dpy, icon_win);
-    XClearWindow(dpy, h_scroll_bar);
-    XClearWindow(dpy, v_scroll_bar);
-    XClearWindow(dpy, l_button);
-    XClearWindow(dpy, r_button);
-    XClearWindow(dpy, t_button);
+    if ((local_flags & (HIDE_V|HIDE_H))!=3){
+      XSetBackground(dpy, ShadowGC, back_pix);
+      XClearWindow(dpy, main_win);
+      XClearWindow(dpy, holder_win);
+      XClearWindow(dpy, icon_win);
+      XClearWindow(dpy, h_scroll_bar);
+      XClearWindow(dpy, v_scroll_bar);
+      XClearWindow(dpy, l_button);
+      XClearWindow(dpy, r_button);
+      XClearWindow(dpy, t_button);
+    }
     XClearWindow(dpy, b_button);
   }
   if (color == Iconcolorset) {
@@ -1679,16 +1685,26 @@
 {
   *dx = icon_win_width;
   *dy = icon_win_height;
-
   if (primary == LEFT || primary == RIGHT){
-    icon_win_width = max(Width, UWidth * Lines + interval - 1);
-    icon_win_height = max(Height, UHeight * (max(0,
+    if ((local_flags & (HIDE_V|HIDE_H)) ==3){
+      /*setting HIDE_V and HIDE_B makes IconBox autogrowing*/
+      icon_win_width = UWidth*(min(Lines,num_icons)+1)+interval-1;
+      icon_win_height = UHeight * ((num_icons-1)/Lines + 2)+interval-1;
+    } else {
+      icon_win_width = max(Width, UWidth * Lines + interval - 1);
+      icon_win_height = max(Height, UHeight * (max(0,
                          (num_icons-1))/Lines
-                         + 1) - 1 + interval);
-  }else{
-    icon_win_width = max(Width, UWidth * (max(0,num_icons-1) / Lines +
+                          + 1) - 1 + interval);
+    }
+  } else {
+    if ((local_flags & (HIDE_V|HIDE_H)) ==3){
+          icon_win_height = UHeight*(min(Lines,num_icons)+1)+interval-1;
+      icon_win_width = UWidth * ((num_icons-1)/Lines + 2)+interval-1;
+    } else {
+      icon_win_width = max(Width, UWidth * (max(0,num_icons-1) / Lines +
                       1) + interval - 1);
-    icon_win_height = max(Height, UHeight * Lines - 1 + interval);
+      icon_win_height = max(Height, UHeight * Lines - 1 + interval);
+    }
   }
   *dx = icon_win_width - *dx;
   *dy = icon_win_height - *dy;
@@ -2223,7 +2239,7 @@
       tmp++;
     if (strncasecmp(tmp, "Horizontal", 10) == 0)
       local_flags |= HIDE_H;
-    else if (strncasecmp(tmp, "Vertical", 8) == 0)
+    if (strncasecmp(tmp, "Vertical", 8) == 0)
       local_flags |= HIDE_V;
       }
       else if (strncasecmp(tline,CatString3("*",MyName,
@@ -2641,10 +2657,21 @@
   case M_ADD_WINDOW:
     if (AddItem(cfgpacket) == True && ready){
       GetIconwinSize(&diffx, &diffy);
-      if (diffy && (primary == BOTTOM || secondary == BOTTOM))
-    icon_win_y += diffy;
-      if (diffx && (primary == RIGHT || secondary == RIGHT))
-    icon_win_x += diffx;
+      if ((local_flags&(HIDE_V|HIDE_H))==3){
+    icon_win_x=0;
+    icon_win_y=0;
+    if (primary == BOTTOM || secondary == BOTTOM)
+      icon_win_y = UHeight;
+    if (primary == RIGHT || secondary == RIGHT)
+      icon_win_x = UWidth;
+    XResizeWindow(dpy, main_win,
+            icon_win_width, icon_win_height);
+      } else {
+    if (diffy && (primary == BOTTOM || secondary == BOTTOM))
+      icon_win_y += diffy;
+    if (diffx && (primary == RIGHT || secondary == RIGHT))
+      icon_win_x += diffx;
+      }
       XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y,
             icon_win_width, icon_win_height);
       if ((diffx || diffy) && (colorset >= 0))
@@ -2656,18 +2683,29 @@
   case M_DESTROY_WINDOW:
     if (DeleteItem(body[0]) && ready){
       GetIconwinSize(&diffx, &diffy);
-      if (diffy && (primary == BOTTOM || secondary == BOTTOM))
-    icon_win_y += diffy;
-      if (diffx && (primary == RIGHT || secondary == RIGHT))
-    icon_win_x += diffx;
-      if (icon_win_y < 0)
-    icon_win_y = 0;
-      if (icon_win_x < 0)
-    icon_win_x = 0;
-      if (icon_win_x + Width > icon_win_width)
-    icon_win_x = icon_win_width - Width;
-      if (icon_win_y + Height > icon_win_height)
-    icon_win_y = icon_win_height - Height;
+      if ( (local_flags & (HIDE_V|HIDE_H)) == 3) {
+    icon_win_x=0;
+    icon_win_y=0;
+    if (primary == BOTTOM || secondary == BOTTOM)
+      icon_win_y = UHeight;
+    if (primary == RIGHT || secondary == RIGHT)
+      icon_win_x = UWidth;
+    XResizeWindow(dpy, main_win,
+            icon_win_width, icon_win_height);
+      } else {
+    if (diffy && (primary == BOTTOM || secondary == BOTTOM))
+      icon_win_y += diffy;
+    if (diffx && (primary == RIGHT || secondary == RIGHT))
+      icon_win_x += diffx;
+    if (icon_win_y < 0)
+      icon_win_y = 0;
+    if (icon_win_x < 0)
+      icon_win_x = 0;
+    if (icon_win_x + Width > icon_win_width)
+      icon_win_x = icon_win_width - Width;
+    if (icon_win_y + Height > icon_win_height)
+      icon_win_y = icon_win_height - Height;
+      }
       XMoveResizeWindow(dpy, icon_win, -icon_win_x, -icon_win_y,
             icon_win_width, icon_win_height);
       if ((diffx || diffy) && (colorset >= 0))

Sounds strange. Personally I always use this module instead of taskbar and found it very easy to handle. But I always apply this patch. Scrollbars indeed are not comfortable.

I have been using FvwmIconBox and I wonder why should it have such a horrible death. It can be argued that FvwmIconMan can be used instead and, actually, I have found this thread when looking for the differences between both modules. At the same time, “horrible death” looks a bit too much. :wink:

Cheers!