[comp.windows.x] Timer Interrupt

yu@unisql.UUCP (Yeong-Ho Yu) (01/24/91)

 I am trying to make a main event handler which will run for at least
the given time, and returns the control back to the program.
That is, it should be a temparary XtAppMainLoop.

 I made up the following function:

void TempEventH(XtAppContext app, unsigned int time)
{
  XEvent event;

  XtAppAddTimeOut(app, time, NULL, NULL);  /* put up a timer event */
  while(!(XtAppPending(app) & XtIMTimer)){ /* until it arrives */
    XtAppNextEvent(app, &event);           /* do the event  processing */
    XtDispatchEvent(&event);
  }
}  

 Of course, it does not work.  But, I don't know why.
Any suggestions?  Many thanks in advance.



-- 
Yeong-Ho Yu

  Internet: execu!sequoia!unisql!yu@cs.utexas.edu
      UUCP: {uunet, cs.utexas.edu!execu}!sequoia!unisql!yu

asente@adobe.com (Paul Asente) (01/25/91)

In article <1100@unisql.UUCP> yu@unisql.UUCP (Yeong-Ho Yu) writes:
< I am trying to make a main event handler which will run for at least
<the given time, and returns the control back to the program.
<That is, it should be a temparary XtAppMainLoop.
<
< I made up the following function:
<
<void TempEventH(XtAppContext app, unsigned int time)
<{
<  XEvent event;
<
<  XtAppAddTimeOut(app, time, NULL, NULL);  /* put up a timer event */
<  while(!(XtAppPending(app) & XtIMTimer)){ /* until it arrives */
<    XtAppNextEvent(app, &event);           /* do the event  processing */
<    XtDispatchEvent(&event);
<  }
<}  
<
<Of course, it does not work.  But, I don't know why.
<Any suggestions?  Many thanks in advance.

From section 7.4 of the Xt spec, discussing XtAppNextEvent:

If the X event queue is empty, XtAppNextEvent flushes the X output buffers of
each Display in the application context and waits for an X event **while
looking at the other input sources and timeout values and calling any
callback procedures triggered by them.** [emphasis added]

In other words, your timer is getting triggered in XtAppNextEvent.  You need
to use use XtAppProcessEvent to get the degree of control over event
dispatching that you want here.

	-paul asente
		asente@adobe.com	...decwrl!adobe!asente

asente@adobe.COM (01/25/91)

In article <1100@unisql.UUCP> yu@unisql.UUCP (Yeong-Ho Yu) writes:
> I am trying to make a main event handler which will run for at least
>the given time, and returns the control back to the program.
>That is, it should be a temparary XtAppMainLoop.
>
> I made up the following function:
>
>void TempEventH(XtAppContext app, unsigned int time)
>{
>  XEvent event;
>
>  XtAppAddTimeOut(app, time, NULL, NULL);  /* put up a timer event */
>  while(!(XtAppPending(app) & XtIMTimer)){ /* until it arrives */
>    XtAppNextEvent(app, &event);           /* do the event  processing */
>    XtDispatchEvent(&event);
>  }
>}  
>
>Of course, it does not work.  But, I don't know why.
>Any suggestions?  Many thanks in advance.

From section 7.4 of the Xt spec, discussing XtAppNextEvent:

If the X event queue is empty, XtAppNextEvent flushes the X output buffers of
each Display in the application context and waits for an X event **while
looking at the other input sources and timeout values and calling any
callback procedures triggered by them.** [emphasis added]

In other words, your timer is getting triggered in XtAppNextEvent.  You need
to use use XtAppProcessEvent to get the degree of control over event
dispatching that you want here.

	-paul asente
		asente@adobe.com	...decwrl!adobe!asente