Re: FVWM: PeriodicTasks bug?

From: Bjoern Steinbrink <B.Steinbrink_at_gmx.de>
Date: Sat, 5 Feb 2005 03:52:59 +0100

Hello,

On 2005.02.04 14:38:59 -0800, fvwm.org_at_rainstick.net wrote:
> While I was playing around with some ideas for FvwmScript, I noticed an
> odd behavior that I was unable to explain by reading the man pages. I
> suspect its a bug tickled by improper usage, but I'll leave that up to
> you folks to decide. I've written and attached a small test script that
> shows the problem.
>
> Basically by my understanding, the attached script should advance the
> red background one button every 5 seconds. However what actually happens
> is that for one second out of 5 the red background cycles as fast as my
> machine can make it go.
>
> If I add a "Title" line to each widget, the script works predictably and
> only advances once every 5 seconds. Seems like the interpreter doesn't
> like empty buttons too well.

FvwmScript contains a bug that executes the periodic tasks too often
when there are pending events. The following patch fixes this.

I'm only subscribed to the fvwm list, so please CC me if you're replying
to fvwm-workers only.

Bjoern

Index: modules/ChangeLog
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/ChangeLog,v
retrieving revision 1.1148
diff -u -u -r1.1148 ChangeLog
--- modules/ChangeLog 10 Jan 2005 14:59:24 -0000 1.1148
+++ modules/ChangeLog 5 Feb 2005 02:47:19 -0000
_at_@ -1,3 +1,9 @@
+2005-02-05 Bjoern Steinbrink <b.steinbrink_at_gmx.de>
+
+ * FvwmScript/FvwmScript.c (MainLoop):
+ Fixed periodic tasks being executed too often when there are pending
+ events.
+
 2005-01-10 Olivier Chapuis <olivier.chapuis_at_free.fr>
 
         * FvwmIconMan/xmanager.c (set_win_displaystring):
Index: modules/FvwmScript/FvwmScript.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmScript/FvwmScript.c,v
retrieving revision 1.71
diff -u -u -r1.71 FvwmScript.c
--- modules/FvwmScript/FvwmScript.c 7 Jun 2004 13:53:50 -0000 1.71
+++ modules/FvwmScript/FvwmScript.c 5 Feb 2005 02:47:22 -0000
_at_@ -1092,6 +1092,8 @@
   int i;
   struct timeval tv;
   struct timeval *ptv;
+ struct timeval now, last_periodic;
+ long delta;
   fd_set_size_t fd_width = fd[1];
   Bool fsm_pending = False;
 
_at_@ -1102,7 +1104,10 @@
   tv.tv_usec = 0;
   ptv = NULL;
   if (x11base->periodictasks != NULL)
+ {
+ gettimeofday(&last_periodic, NULL);
     ptv = &tv;
+ }
 
   while ( !isTerminated )
   {
_at_@ -1114,6 +1119,10 @@
     FD_SET(fd[1],&in_fdset);
     fsm_fdset(&in_fdset);
 
+ gettimeofday(&now, NULL);
+ delta = (now.tv_sec - last_periodic.tv_sec) * 1000000;
+ delta += now.tv_usec - last_periodic.tv_usec;
+
     if (fsm_pending)
     {
             tv.tv_sec = 0;
_at_@ -1121,8 +1130,10 @@
     }
     else
     {
- tv.tv_sec = 1;
- tv.tv_usec = 0;
+ tv.tv_usec = 1000000 - delta;
+ if (tv.tv_usec < 0)
+ tv.tv_usec = 0;
+ tv.tv_sec = delta ? 0 : 1;
     }
 
     if (fvwmSelect(fd_width, &in_fdset, NULL, NULL, ptv) > 0)
_at_@ -1245,9 +1256,11 @@
       fsm_pending = fsm_process(&in_fdset);
     }
 
- if (!isTerminated && x11base->periodictasks!=NULL)
+ if (!isTerminated && x11base->periodictasks!=NULL && delta >= 1000000)
     {
       /* Execution des taches periodics */
+ last_periodic.tv_sec = now.tv_sec;
+ last_periodic.tv_usec = now.tv_usec;
       ExecBloc(x11base->periodictasks);
       usleep(10000);
     }

>
> I have tested this with the most current build:
>
> fvwm 2.5.13 (snap-20050204) compiled on Feb 4 2005 at 13:33:45
> with support for: ReadLine, XPM, PNG, Shape, XShm, SM, Xinerama,
> XRender, XFT, NLS
>
> Regards,
> Fred.
>
> P.S.: There is a typo in the man page for FvwmScript where
> "PeriodicTasks" is spelled "Periodic Task" in the example.
>
> --- Begin script ---
>
> WindowTitle {ScriptSilon}
> WindowSize 150 50
> WindowPosition 300 300
> Font "Shadow=1:xft:Verdana:style=Regular:pixelsize=12:minspace=true"
> BackColor {rgb:77/77/77}
>
> Init
> Begin
> Set $NewLight=1
> End
>
> PeriodicTasks
> Begin
> If (RemainderOfDiv (GetTime) 5)==0 Then
> Begin
> Set $OldLight=$NewLight
> Set $NewLight=(Add $NewLight 1)
> If $NewLight==4 Then
> Set $NewLight=1
> ChangeTitle 4 $NewLight
> ChangeBackColor $OldLight {white}
> ChangeBackColor $NewLight {red}
> End
> End
>
> Widget 1
> Property
> Size 10 18
> Position 0 0
> Type PushButton
> BackColor {White}
> Main
> Case message of
> SingleClic :
> Begin
> ChangeBackColor 1 {rgb:00/00/ff}
> End
> End
>
> Widget 2
> Property
> Size 10 18
> Position 30 0
> Type PushButton
> BackColor {white}
> Main
> Case message of
> SingleClic :
> Begin
> ChangeBackColor 2 {rgb:00/00/ff}
> End
> End
>
> Widget 3
> Property
> Size 10 18
> Position 60 0
> Type PushButton
> BackColor {white}
> Main
> Case message of
> SingleClic :
> Begin
> ChangeBackColor 3 {rgb:00/00/ff}
> End
> End
>
> Widget 4
> Property
> Size 10 18
> Position 90 0
> Type PushButton
> Title {1}
> BackColor {white}
> Main
> End
>
> --
> Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
> To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
> message to majordomo_at_fvwm.org.
> To report problems, send mail to fvwm-owner_at_fvwm.org.
>
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to majordomo_at_fvwm.org.
To report problems, send mail to fvwm-owner_at_fvwm.org.
Received on Fri Feb 04 2005 - 20:54:28 GMT

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:37:57 BST