Subject: FVWM: Animated WindowShade patch, v1.2

From: Cristian Tibirna <[email-masked]>
Date: Sat, 30 Aug 1997 18:16:06 -0400

Nice to "meet" you again

I finally covered by debts to Morpheus last night and today, when I
came back to my indecentely easy to use computer, I found the problem
with the config of the WindowShadeAnimate. In fact, I finally read
with more attention the man page for bsearch(3).

So, here is the second patch for the WindowShade animation. Now the
WindowShadeAnimate parameter can be tuned from the FvwmTalk for
example. Of course, the normal use would be to put it in your
.fvwm2rc.

I also added the WINDOWSHADE preprocessor flags there where
necessary. This hopefully eliminates possible compile time errors in
case of choosing not to use WINDOWSHADE at all.

The hardcoded default WindowShadeAnimate is off. So you _have_ to add
the command to your .fvwm2rc with a parameter in order to see it at
work.

As a known bug, if you move the title bar of a shaded window, the
window deshades by itself (not wanted) but remains flagged as shaded,
so next time one tries to shade it, it will not do it.

The TODO list contains now: patching the manual and trying to get lower
border stay visible after a shade (you know, having the border all
around the title), as a run-time option.

				Cristian

----------shade_anim-1.2.patch-------cut here---
diff -u fvwm_orig/builtins.c fvwm/builtins.c
--- fvwm_orig/builtins.c	Tue Aug 19 19:41:27 1997
+++ fvwm/builtins.c	Sat Aug 30 17:37:52 1997
@@ -22,6 +22,12 @@
 #include "screen.h"
 #include "module.h"
 
+#ifdef WINDOWSHADE
+/*->CT set shade_anim and shade_anim_steps defaults */
+static int shade_anim_steps=10;
+/*<-CT*/
+#endif
+
 static char *exec_shell_name="/bin/sh";
 /* button state strings must match the enumerated states */
 static char  *button_states[MaxButtonState]={
@@ -34,6 +40,7 @@
 #endif
 };
 
+
 /***********************************************************************
  *
  *  Procedure:
@@ -383,48 +390,91 @@
  *
  *  Args: 1 -- force shade, 2 -- force unshade  No Arg: toggle
  * 
+ ***********************************************************************
+ *
+ *  Animation added. 
+ *     Based on code from AfterStep-1.0 (CT: [email-masked])
+ *
+ *  Builtin function: WindowShadeAnimate <steps>
+ *      <steps> is number of steps in animation. If 0, the
+ *              windowshade animation goes off. Default = 10.
+ *
  ***********************************************************************/
 void WindowShade(XEvent *eventp,Window w,FvwmWindow *tmp_win,
 		 unsigned long context, char *action, int *Module)
-{
+{       
     int n = 0;
+    int f_h, f_w, t_h, tb_h;
+    int h, y, s;
 
     if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease))
-	return;
-
+      return;
+    if ( tmp_win == NULL )
+      return;
     if (!(tmp_win->flags & TITLE) || (tmp_win->flags & MAXIMIZED)) {
-	XBell(dpy, Scr.screen);
-	return;
+      XBell(dpy, Scr.screen);
+      return;
     }
+
+    f_h   = tmp_win->frame_height;
+    f_w   = tmp_win->frame_width;
+    t_h   = tmp_win->title_height; 
+    tb_h  = tmp_win->title_height+tmp_win->boundary_width;
+
+    if(shade_anim_steps) s = f_h/shade_anim_steps;
+    
     while (isspace(*action))++action;
     if (isdigit(*action))
-	sscanf(action,"%d",&n);
-
+      sscanf(action,"%d",&n);
+    
     if (((tmp_win->buttons & WSHADE)||(n==2))&&(n!=1))
-    {
+      {
 	tmp_win->buttons &= ~WSHADE;
-	SetupFrame(tmp_win,
-		   tmp_win->frame_x, 
-		   tmp_win->frame_y, 
-		   tmp_win->orig_wd,
-		   tmp_win->orig_ht,
-		   True);
-        Broadcast(M_DEWINDOWSHADE, 3, tmp_win->w, tmp_win->frame,
-                  (unsigned long)tmp_win, 0, 0, 0, 0);
-    }
+
+	if(shade_anim_steps) {
+	  XMoveWindow(dpy, tmp_win->w, 0, - (f_h - tb_h));
+	  h = tb_h;
+	  y = -(f_h - tb_h);
+	  while (h<f_h - tb_h) {
+	    XResizeWindow(dpy, tmp_win->frame, f_w, h);
+	    XMoveWindow(dpy, tmp_win->w, 0, y);
+	    XSync(dpy, 0);
+	    h+=s;
+	    y+=s;
+	  }
+	  XMoveWindow(dpy, tmp_win->w, 0, 0);	
+	}
+
+        XResizeWindow(dpy, tmp_win->frame, f_w, f_h);
+	Broadcast(M_DEWINDOWSHADE,3,tmp_win->w,tmp_win->frame,
+		  (unsigned long)tmp_win,0,0,0,0);
+      } 
     else
-    {
+      {
 	tmp_win->buttons |= WSHADE;
-	SetupFrame(tmp_win,
-		   tmp_win->frame_x,
-		   tmp_win->frame_y,
-		   tmp_win->frame_width,
-		   tmp_win->title_height + tmp_win->boundary_width,
-		   False);
-        Broadcast(M_WINDOWSHADE, 3, tmp_win->w, tmp_win->frame,
-                  (unsigned long)tmp_win, 0, 0, 0, 0);
-    }
+	
+	if (shade_anim_steps) {
+	  XLowerWindow(dpy, tmp_win->w);
+	  h = f_h;
+	  y = tb_h;
+	  while (h>tb_h) {
+	    XMoveWindow(dpy, tmp_win->w, 0, y);
+	    XResizeWindow(dpy, tmp_win->frame, f_w, h);
+	    XSync(dpy, 0);
+	    h-=s;
+	    y-=s;
+	  }
+	  XMoveWindow(dpy, tmp_win->w, 0, 0);
+	}
+	
+	XResizeWindow(dpy, tmp_win->frame, f_w, tb_h);
+	Broadcast(M_WINDOWSHADE,3,tmp_win->w,tmp_win->frame,
+		  (unsigned long)tmp_win,0,0,0,0);	
+      }
+    
 }
+
+
 #endif /* WINDOWSHADE */
 
 /* For Ultrix 4.2 */
@@ -3329,3 +3379,22 @@
   if (opts) /* should be empty at this point... */
     free(opts);
 }
+
+#ifdef WINDOWSHADE
+/*->CT set shade_anim_steps */
+void setShadeAnim (XEvent *eventp,Window w,FvwmWindow *tmp_win,
+            unsigned long context, char *action,int* Module) 
+{
+  int val,val_unit,n;
+ 
+  n=GetOneArgument(action, &val, &val_unit);
+  if(n != 1) {
+    fvwm_msg(ERR,"setShadeAnim","WindowShadeAnimate requires 1 argument");
+    return;
+  }
+ 
+  shade_anim_steps = val;
+}
+/*<-CT*/
+#endif
+   
diff -u fvwm_orig/functions.c fvwm/functions.c
--- fvwm_orig/functions.c	Mon Aug 11 16:09:29 1997
+++ fvwm/functions.c	Sat Aug 30 17:30:43 1997
@@ -139,6 +139,9 @@
   {"WindowsDesk",  changeWindowsDesk,F_CHANGE_WINDOWS_DESK, FUNC_NEEDS_WINDOW},
 #ifdef WINDOWSHADE
   {"WindowShade",  WindowShade,      F_WINDOW_SHADE,        FUNC_NEEDS_WINDOW},
+  /*->CT for SHADE_ANIMATE*/
+  {"WindowShadeAnimate",setShadeAnim,F_SHADE_ANIMATE,      FUNC_NO_WINDOW},
+  /*<-CT*/
 #endif /* WINDOWSHADE */
   {"XORValue",     SetXOR,           F_XOR,                 FUNC_NO_WINDOW},
   {"",0,0,0}
diff -u fvwm_orig/fvwm.c fvwm/fvwm.c
--- fvwm_orig/fvwm.c	Mon Aug  4 16:53:32 1997
+++ fvwm/fvwm.c	Sat Aug 30 01:11:40 1997
@@ -630,6 +630,7 @@
   char *defaults[] = {
     "HilightColor black grey",
     "XORValue 0",
+    "WindowShadeAnimate 0",
     "MenuStyle black grey slategrey fixed fvwm",
     "TitleStyle Centered -- Raised",
     "IconFont fixed",
diff -u fvwm_orig/misc.h fvwm/misc.h
--- fvwm_orig/misc.h	Mon Aug 11 16:10:19 1997
+++ fvwm/misc.h	Sat Aug 30 17:37:53 1997
@@ -217,7 +217,13 @@
 #ifdef  WINDOWSHADE
 void WindowShade(XEvent *eventp,Window w,FvwmWindow *tmp_win,
 		 unsigned long context, char *action, int *Module);
+
+/*->CT for window shade animation */
+void setShadeAnim(XEvent *eventp,Window w,FvwmWindow *tmp_win,
+		 unsigned long context, char *action, int *Module);
+/*<-CT*/
 #endif
+
 extern void       RaiseWindow(FvwmWindow *t);
 extern void       LowerWindow(FvwmWindow *t);
 extern Bool       GrabEm(int);
diff -u fvwm_orig/parse.h fvwm/parse.h
--- fvwm_orig/parse.h	Mon Aug 11 16:10:39 1997
+++ fvwm/parse.h	Sat Aug 30 00:46:25 1997
@@ -75,6 +75,9 @@
 #define F_EXEC_SETUP            57
 #define F_CURSOR_STYLE          58
 #define F_CURRENT               59
+/*->CT*/
+#define F_SHADE_ANIMATE         60
+/*<-CT*/
 
 /* Functions which require a target window */
 #define F_RESIZE		100
@@ -104,6 +107,7 @@
 #define F_DESTROY_DECOR         124
 #define F_UPDATE_DECOR          125
 #define F_WINDOW_SHADE          126
+
 
 /* Functions for use by modules only! */
 #define F_SEND_WINDOW_LIST     1000
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].