[comp.windows.x] Why aren't XFlush/XSync working for me?

daven@maxine.wpi.edu (Dave Nedde) (01/17/91)

I have a tight loop that performs many X requests.  However, I want to
display changing status information during the processing.  So, periodically,
I will do an XSetValues to a label widget to update some information.  I 
realize that my request will be ignored until the client has time to process it,
but can't I use XFlush or XSync to tell the client to process all waiting events
before taking any others?  I tried using XFlush and XSync, inside the loop but 
they don't work and the status information is only displayed after I get out of
the loop.

Thanks for any help.  

  -DaveN
---
David Nedde, Computer Science Dept.	daven@maxine.wpi.edu or @wpi.wpi.edu
Worcester Polytechnic Institute		(508) 831-5117/5668
Worcester, MA 01609			:^| HAVE A DAY.

rlh2@ukc.ac.uk (R.L.Hesketh) (01/17/91)

In article <1991Jan16.190159.6004@wpi.WPI.EDU> daven@maxine.wpi.edu (Dave Nedde) writes:
>I have a tight loop that performs many X requests.  However, I want to
>display changing status information during the processing.  So, periodically,
>I will do an XSetValues to a label widget to update some information.  I 
>realize that my request will be ignored until the client has time to process it,
>but can't I use XFlush or XSync to tell the client to process all waiting events
>before taking any others?

When XtSetValues() is used an expose event is generated if the widget's
window needs updating.  This expose event is generated by the server and
therefore must be processed by an Xt event processing loop (such as
XtMainLoop()).

XFlush() and XSync() operate on requests *to* the server.  XFlush() flushes
the requests to the server.  XSync() blocks until all events and errors have
been processed by the server.  They do not directly affect the clients
processing of events from the server.

Therefore whilst the client is doing some processing it is not examining the
incoming events queue and as such does not process the expose event caused by
the SetValues() call.

You therefore have to do one of two things to see the label updated:

1) Periodically process the incoming event queue.  Either processing a
   small number of events at a time or process all waiting events until the
   next period.  An example processing loop might be:

	process_waiting_events(dpy)
	Display *dpy;
	{
		XtAppContext app = XtDisplayToApplicationContext(dpy);

		while (XtAppPending(app)) {
			XEvent ev;

			XtAppNextEvent(app, &ev);
			XtDispatchEvent(&ev);
		};
	}

   You should only use this method if your user interface will not cause
   your processing sequence to be upset .. such as the user pressing a
   pushbutton again and invoking a callback.  Your interface can be designed
   as such by turning off the function of buttons (using XtSetSensitive()).
   Using this method keeps the user interface "alive" and does not
   cause the queued up events to be suddenly processed when the processing
   finishes and interface becomes alive again.

2) The second method is to fake an expose event and process this event by
   hand.  An event structure is filled in with appropriate details for the
   exposure and then dispatched by hand by calling XtDispatchEvent(),
   followed by something like an XFlush() which will flush all the text and
   other drawing requests off to the server.  I have code to do this if you
   require it, I prefer the first method though.

Richard Hesketh   :   rlh2@ukc.ac.uk
Computing Officer, Computing Lab., University of Kent at Canterbury,
Canterbury, Kent, CT2 7NF, United Kingdom.
        Tel: +44 227 764000 ext 7620/7590      Fax: +44 227 762811

etaylor@wilkins.iaims.bcm.tmc.edu (Eric Taylor) (01/22/91)

XFlush and XSync are not enough.  You must get and dispatch
events.  That is when your widget will get redrawn.
-- 
					Eric Taylor
					Baylor College of Medicine
					etaylor@wilkins.bcm.tmc.edu
					(713) 798-3776