Subject: Re: FVWM: moving windows patch

From: Henrique Martins <[email-masked]>
Date: Wed, 06 Mar 1996 23:22:48 -0800

> I think I haven't tried hacking fvwm's code since way back in 0.9/1.x
> times, pre-modules, so I'm not sure of all the side effects of the
> changes below, specially on the impact on inter-module traffic and module
> behavior, but this patch will make the "window icons" in the pager move,
> while a window is being moved by fvwm, i.e. non-pager initiated moves.

  Either no one tried that patch, or no one noticed that it doesn't work
  very well when moving icons.  As I seldom have icons in my dekstop I
  didn't notice it until today.

  This new patch, implemented somewhat differently, does seem to behave
  properly for moving icons, and windows of course.  To accomplish this,
  and greatly reduce the communications overhead during a move, I created a
  new message type, M_MOVING_WINDOW.

  While I was debugging it, I had to patch FvwmDebug to handle this new
  type of message, as wells as two other messages it was currently
  regarding as unknown.

  The patch below should be applied from the fvwm-2.0.41 directory and to
  the ORIGINAL code, i.e. it is not a patch to my previous patch, but a
  patch to the released code.

  -- Henrique

*** modules/FvwmPager/FvwmPager.h.orig	Wed Mar  6 09:11:06 1996
--- modules/FvwmPager/FvwmPager.h	Wed Mar  6 13:57:36 1996
***************
*** 90,95 ****
--- 90,96 ----
  
  void list_add(unsigned long *body);
  void list_configure(unsigned long *body);
+ void list_moving_window (unsigned long *body);
  void list_destroy(unsigned long *body);
  void list_focus(unsigned long *body);
  void list_toggle(unsigned long *body);
*** modules/FvwmPager/FvwmPager.c.orig	Wed Mar  6 09:09:54 1996
--- modules/FvwmPager/FvwmPager.c	Wed Mar  6 14:49:21 1996
***************
*** 218,223 ****
--- 218,226 ----
      case M_CONFIGURE_WINDOW:
        list_configure(body);
        break;
+     case M_MOVING_WINDOW:
+       list_moving_window (body);
+       break;
      case M_DESTROY_WINDOW:
        list_destroy(body);
        break;
***************
*** 305,310 ****
--- 308,346 ----
    (*prev)->text = body[22];
    (*prev)->back = body[23];
    AddNewWindow(*prev);
+ }
+ 
+ /***********************************************************************
+  *
+  *  Procedure:
+  *	list_moving_window - displays packet contents to stderr
+  *
+  ***********************************************************************/
+ 
+ void list_moving_window (unsigned long *body)
+ {
+   PagerWindow *t;
+   Window target_w;
+   
+   for (target_w = body[0],
+          t = Start;
+        t != NULL && t->w != target_w;
+        t = t->next);
+ 
+   if(t != NULL) {
+     t->x = body[1];
+     t->y = body[2];
+ 
+     if(t->desk != body[3])
+       ChangeDeskForWindow (t, body[3]);
+     else
+       MoveResizePagerView (t);
+ 
+     if (FocusWin == t)
+       Hilight (t, ON);
+     else
+       Hilight (t, OFF);
+   }
  }
  
  /***********************************************************************
*** modules/FvwmDebug/FvwmDebug.h.orig	Wed Mar  6 15:00:09 1996
--- modules/FvwmDebug/FvwmDebug.h	Wed Mar  6 13:53:32 1996
***************
*** 12,17 ****
--- 12,18 ----
  
  void list_add(unsigned long *body);
  void list_configure(unsigned long *body);
+ void list_moving_window(unsigned long *body);
  void list_destroy(unsigned long *body);
  void list_focus(unsigned long *body);
  void list_toggle(unsigned long *body);
***************
*** 29,34 ****
--- 30,37 ----
  void list_class(unsigned long *body);
  void list_res_name(unsigned long *body);
  void list_end(void);
+ void list_def_icon_name(unsigned long *body);
+ void list_icon_file(unsigned long *body);

*** modules/FvwmDebug/FvwmDebug.c.orig	Wed Mar  6 15:00:15 1996
--- modules/FvwmDebug/FvwmDebug.c	Wed Mar  6 23:17:15 1996
***************
*** 107,113 ****
--- 107,115 ----
    fd[0] = atoi(argv[1]);
    fd[1] = atoi(argv[2]);
  
+ #if 0
    spawn_xtee();
+ #endif
    
    /* Data passed in command line */
    fprintf(stderr,"Application Window 0x%s\n",argv[4]);
***************
*** 154,159 ****
--- 156,164 ----
   ***********************************************************************/
  void process_message(unsigned long type,unsigned long *body)
  {
+   int shift;
+   unsigned long dup;
+   
    switch(type)
      {
      case M_ADD_WINDOW:
***************
*** 161,166 ****
--- 166,174 ----
      case M_CONFIGURE_WINDOW:
        list_configure(body);
        break;
+     case M_MOVING_WINDOW:
+       list_moving_window(body);
+       break;
      case M_DESTROY_WINDOW:
        list_destroy(body);
        break;
***************
*** 194,199 ****
--- 202,210 ----
      case M_WINDOW_NAME:
        list_window_name(body);
        break;
+     case M_DEFAULTICON:
+       list_def_icon_name(body);
+       break;
      case M_ICON_NAME:
        list_icon_name(body);
        break;
***************
*** 206,213 ****
      case M_END_WINDOWLIST:
        list_end();
        break;
      default:
!       list_unknown(body);
        break;
      }
  }
--- 217,233 ----
      case M_END_WINDOWLIST:
        list_end();
        break;
+     case M_ICON_FILE:
+       list_icon_file(body);
+       break;
      default:
!       if (type == 0)
!         fprintf (stderr,"Illegal packet type %d\n", type);
!       else {
!         for (shift = 0, dup = type; (dup & 0x1) != 0x1; shift++, dup>>=1);
!         fprintf (stderr,"Unknown packet type %d, bit %d\n", type, shift);
!         list_unknown (body);
!       }
        break;
      }
  }
***************
*** 262,267 ****
--- 282,302 ----
  /***********************************************************************
   *
   *  Procedure:
+  *	list_moving_window - displays packet contents to stderr
+  *
+  ***********************************************************************/
+ void list_moving_window(unsigned long *body)
+ {
+   fprintf(stderr,"Moving Window\n");
+   fprintf(stderr,"\t ID %lx\n",body[0]);
+   fprintf(stderr,"\t x %ld\n",(long)body[1]);
+   fprintf(stderr,"\t y %ld\n",(long)body[2]);
+   fprintf(stderr,"\t desk %ld\n",(long)body[3]);
+ }
+ 
+ /***********************************************************************
+  *
+  *  Procedure:
   *	list_configure - displays packet contents to stderr
   *
   ***********************************************************************/
***************
*** 333,338 ****
--- 368,375 ----
    fprintf(stderr,"\t x %ld\n",(long)body[0]);
    fprintf(stderr,"\t y %ld\n",(long)body[1]);
    fprintf(stderr,"\t desk %ld\n",(long)body[2]);
+   fprintf(stderr,"\t x max %ld\n",(long)body[3]);
+   fprintf(stderr,"\t y max %ld\n",(long)body[4]);
  }
  
  /***********************************************************************
***************
*** 385,391 ****
   ***********************************************************************/
  void list_unknown(unsigned long *body)
  {
!   fprintf(stderr,"Unknown packet type\n");
  }
  
  /***********************************************************************
--- 422,428 ----
   ***********************************************************************/
  void list_unknown(unsigned long *body)
  {
!   /*fprintf(stderr,"Unknown packet type\n");*/
  }
  
  /***********************************************************************
***************
*** 472,477 ****
--- 509,540 ----
    fprintf(stderr,"\t fvwm ptr %lx\n",body[2]);
    fprintf(stderr,"\t window name %s\n",(char *)(&body[3]));
  
+ }
+ 
+ 
+ /***********************************************************************
+  *
+  *  Procedure:
+  *	list_icon_file - displays packet contents to stderr
+  *
+  ***********************************************************************/
+ void list_icon_file(unsigned long *body)
+ {
+   fprintf(stderr,"icon file\n");
+   fprintf(stderr,"\tfile name %s\n",(char *)(&body[3]));
+ }
+ 
+ 
+ /***********************************************************************
+  *
+  *  Procedure:
+  *	list_icon_name - displays packet contents to stderr
+  *
+  ***********************************************************************/
+ void list_def_icon_name(unsigned long *body)
+ {
+   fprintf(stderr,"default icon\n");
+   fprintf(stderr,"\t icon name %s\n",(char *)(&body[3]));
  }

*** fvwm/move.c.orig	Mon Feb 26 19:59:18 1996
--- fvwm/move.c	Wed Mar  6 14:53:09 1996
***************
*** 242,247 ****
--- 242,251 ----
  		XMoveWindow(dpy,tmp_win->frame,xl,yt);
  	    }
  	  DisplayPosition(tmp_win,xl+Scr.Vx,yt+Scr.Vy,False);
+           Broadcast (M_MOVING_WINDOW, 4,
+                      tmp_win->w, xl, yt, tmp_win->Desk,
+                      0, 0, 0);
+           FlushQueues ();
  	  done = TRUE;
  	  break;
  
*** fvwm/module.h.orig	Wed Mar  6 08:55:24 1996
--- fvwm/module.h	Wed Mar  6 13:34:12 1996
***************
*** 16,22 ****
  
  #define START_FLAG 0xffffffff
  
! #define M_NEW_PAGE           (1)
  #define M_NEW_DESK           (1<<1)
  #define M_ADD_WINDOW         (1<<2)
  #define M_RAISE_WINDOW       (1<<3)
--- 16,22 ----
  
  #define START_FLAG 0xffffffff
  
! #define M_NEW_PAGE           (1<<0)
  #define M_NEW_DESK           (1<<1)
  #define M_ADD_WINDOW         (1<<2)
  #define M_RAISE_WINDOW       (1<<3)
***************
*** 38,44 ****
  #define M_END_CONFIG_INFO    (1<<19)
  #define M_ICON_FILE          (1<<20)
  #define M_DEFAULTICON        (1<<21)
! #define MAX_MESSAGES         22
  #define MAX_MASK             ((1<<MAX_MESSAGES)-1)
  
  #define HEADER_SIZE         4
--- 38,45 ----
  #define M_END_CONFIG_INFO    (1<<19)
  #define M_ICON_FILE          (1<<20)
  #define M_DEFAULTICON        (1<<21)
! #define M_MOVING_WINDOW      (1<<22)
! #define MAX_MESSAGES         23
  #define MAX_MASK             ((1<<MAX_MESSAGES)-1)
  
  #define HEADER_SIZE         4
*** fvwm/events.c.orig	Mon Feb 26 19:59:08 1996
--- fvwm/events.c	Wed Mar  6 23:17:36 1996
***************
*** 1444,1446 ****
--- 1444,1481 ----
    return 0;
  }
  
+ void FlushQueues ()
+ {
+   extern int fd_width;
+   fd_set out_fdset;
+   int i;
+   int retval;
+ 
+   FD_ZERO(&out_fdset);
+   for(i=0; i<npipes; i++)
+     {
+       if(pipeQueue[i]!= NULL)
+ 	{
+ 	  FD_SET(writePipes[i], &out_fdset);
+ 	}
+     }
+   
+ #ifdef __hpux
+   retval=select(fd_width, 0, (int *)&out_fdset,0, NULL);
+ #else
+   retval=select(fd_width, 0, &out_fdset, 0, NULL);
+ #endif
+   
+   for(i=0;i<npipes;i++)
+     {
+       if(writePipes[i] >= 0)
+ 	{
+ 	  if((retval>0)&&(FD_ISSET(writePipes[i], &out_fdset)))
+ 	    {
+ 	      FlushQueue(i);
+ 	    }
+ 	}
+     }
+ 
+ }
+ 
--
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].

---

From: Mark Borges <[email-masked]>
Date: 08 Mar 1996 17:05:52 -0700

>> On Wed, 06 Mar 1996 23:22:48 -0800,
>> Henrique Martins(HM) wrote:
HM>   This new patch, implemented somewhat differently, does seem to
HM>   behave properly for moving icons, and windows of course.  To
HM>   accomplish this,

Yes. Very nice. It patched against 2.0.41 cleanly.

It was running fine, then FvwmPager died (i.e., it disappeared from
the screen). I forget precisely what I was doing just before I noticed
it's absence. I then checked my .xsessionlog file and found:

------------------------------------------------------------------------------
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  41231
  Current serial number in output stream:  41266
------------------------------------------------------------------------------

right after it went away (I know, this is probably useless, but on the
off chance it helps...)

No real problem -- one can fire up another pager from the modules
pull-down.

  -mb-

---

From: [email-masked] (Grant McDorman)
Date: Mon, 11 Mar 1996 12:09:10 EDT+4

>  it's absence. I then checked my .xsessionlog file and found:

This is a timing problem in FvwmPager. I posted a patch some time ago,
but either it didn't make it to the list or it has not been applied.

It will happen when you drag a window - in the pager, of course -
from another desk to the current page of the current desk.

Dragging the window *out* of the pager doesn't cause the problem.

Grant McDorman <[email-masked]>

---

From: <[email-masked]> (Charles Hines)
Date: Mon, 11 Mar 1996 13:43:54 -0500

>>>>> "Grant" == Grant McDorman <[email-masked]> writes:

>> Current serial number in output stream:  41266

Grant> This is a timing problem in FvwmPager. I posted a patch some
Grant> time ago, but either it didn't make it to the list or it has
Grant> not been applied.

I have that patch still, but it frightened me somewhat, so I haven't
played with it yet.  It's the sleep that bothers me, actually.  I
understand the sync, but I want to know why the sleep is needed.  I'm
wondering if there isn't a more correct fix (if not, of course I'll
use yours).  I'll look into it when I get a chance.

Mark, I included Grant's patch below so you can give it a try if you'd
like.

Chuck

--------------->8 'FvwmPager-timing-bug.patch' cut here 8<---------------
*** x_pager.c.orig      Wed Nov 15 16:10:31 1995
--- x_pager.c   Tue Feb  6 11:53:39 1996
***************
*** 1427,1432 ****
--- 1427,1435 ----
        }
        if(Scr.CurrentDesk == t->desk)
        {
+         XSync(dpy,0);
+         sleep_a_little(50000);
+         XSync(dpy,0);
          if(t->flags & ICONIFIED)
            XSetInputFocus (dpy, t->icon_w, RevertToParent, Event->xbutton.time)
;
          else
--
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].

---

From: <[email-masked]> (Charles Hines)
Date: Mon, 11 Mar 1996 13:47:46 -0500

Chuck

---

From: Grant McDorman <[email-masked]>
Date: Mon, 11 Mar 1996 13:51:40 -0500 (EST)

>use yours).  I'll look into it when I get a chance.

It seems to me that there is some period of time between sending the
XReparentWindow (a few lines above) and the server actually accomplishing
the reparenting. If the FvwmPager tries to set the focus before the
reparenting is complete, the BadMatch error happens.

Incidentally, I reduced the delay from 50,000 to 5,000 (microsec) when
installing 2.0.41 and it still seems to work fine. I agree, though, that it
would be nice to have something other than a delay. About the only thing I
can think of, though, is to wait for an event, such as ReparentNotify, which
would be a pain (and would also, presumably, have to time out to prevent the
pager from locking up if something goes wrong).

				ISG Technologies, Inc.

---

From: Mark Borges <[email-masked]>
Date: 11 Mar 1996 13:20:43 -0700

>> On Mon, 11 Mar 1996 12:09:10 EDT+4,
>> Grant McDorman(GM) wrote:
>> it's absence. I then checked my .xsessionlog file and found:

GM> This is a timing problem in FvwmPager. I posted a patch some time ago,
GM> but either it didn't make it to the list or it has not been applied.

GM> It will happen when you drag a window - in the pager, of course -
GM> from another desk to the current page of the current desk.

Ah, yes. Now I remember. That is exactly what I was doing at the
time. But, I can't reproduce the bug consistently on my platform
(Solaris-2.3, Sparc10), presumably because it is a timing problem that
only shows up sporadically.

GM> Dragging the window *out* of the pager doesn't cause the problem.

Yes, I've never noticed a problem dragging out.

>> On Mon, 11 Mar 1996 13:51:40 -0500 (EST),
>> Grant McDorman(GM) wrote:

GM> Incidentally, I reduced the delay from 50,000 to 5,000 (microsec)
GM> when installing 2.0.41 and it still seems to work fine. I agree,
GM> though, that it would be nice to have something other than a
GM> delay. About the only thing I can think of, though, is to wait for
GM> an event, such as ReparentNotify, which would be a pain (and would
GM> also, presumably, have to time out to prevent the pager from
GM> locking up if something goes wrong).

That seems like an acceptable delay if it does cure the problem. I
agree, though, that a solution without this sleep delay would be
desireable. Perhaps a compile-time option to enable the work-around if
sites notice the timing problem on a sufficiently regular basis (I've
tried to get FvwmPager to quit pretty hard the last hour or so,
dragging many windows to the current page of the current desk and
changing focus like crazy, and the pager refuses to die again).

  -mb-