Subject: FVWM: animated windowshade patch

From: Cristian Tibirna <[email-masked]>
Date: Sat, 30 Aug 1997 01:48:47 -0400

Hi everybody

Below I included the quick and dirty patch (against official
fvwm-2.0.46 source tree) which will allow us to have the long asked
;-) windowshade animation.

As this friday evening is for me a big event (my first X Window
micro-hack), I was too excited by the result not to post it. In fact
the functionality is hardwired and my attempt to program some config
avail was unsuccessful. Even if I think I understood how the builtin
functions mechanism works, the RC parsing routine stubborns to pass
over my WindowShadeAnimate command until the "desperate" Module call.

As a consequence, there isn't (for the moment) a possibility to take
the animation out at run time.

In the next phase (after I'll get also some sleep in the account of
the before past week :-) I'll rip the window manager off my X session
and I'll start it through gdb. 

The patch is really simple and hopefully it will not break anything
(at least over here it doesn't :-).

All the credits for this patch must go to the guys from the AfterStep
team :-), to the author of the first version of WindowShade and to
Chuck and all the others, for their crystal-clear code (even a zero
skilled novice as I am understands it (if he gets some rest before -
now you know why I didn't figure out how to program the
config part)).

					Cristian

Have fun with it. Here it is. Patch it in the root directory of your
fvwm-2.0.46 source tree.

-----------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 00:22:56 1997
@@ -22,6 +22,10 @@
 #include "screen.h"
 #include "module.h"
 
+/*->CT set shade_anim and shade_anim_steps defaults */
+static int shade_anim=1,shade_anim_steps=10;
+/*<-CT*/
+
 static char *exec_shell_name="/bin/sh";
 /* button state strings must match the enumerated states */
 static char  *button_states[MaxButtonState]={
@@ -34,6 +38,7 @@
 #endif
 };
 
+
 /***********************************************************************
  *
  *  Procedure:
@@ -383,48 +388,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) 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) {
+	  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) {
+	  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 +3377,28 @@
   if (opts) /* should be empty at this point... */
     free(opts);
 }
+
+/*->CT set shade_anim and 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;
+  }
+ 
+  if(val) {
+    shade_anim = 1;
+    shade_anim_steps = val;
+  }
+  else
+    shade_anim = 0;
+}
+/*<-CT*/
+
+
+   
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 00:31:01 1997
@@ -141,6 +141,9 @@
   {"WindowShade",  WindowShade,      F_WINDOW_SHADE,        FUNC_NEEDS_WINDOW},
 #endif /* WINDOWSHADE */
   {"XORValue",     SetXOR,           F_XOR,                 FUNC_NO_WINDOW},
+  /*->CT for SHADE_ANIMATE*/
+  {"WindowShadeAnimate",setShadeAnim,F_SHADE_ANIMATE,      FUNC_NO_WINDOW},
+  /*<-CT*/
   {"",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 00:27:55 1997
@@ -218,6 +218,12 @@
 void WindowShade(XEvent *eventp,Window w,FvwmWindow *tmp_win,
 		 unsigned long context, char *action, int *Module);
 #endif
+
+/*->CT for window shade animation */
+void setShadeAnim(XEvent *eventp,Window w,FvwmWindow *tmp_win,
+		 unsigned long context, char *action, int *Module);
+/*<-CT*/
+
 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].