Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!cs.utexas.edu!sun-barr!decwrl!chico.pa.dec.com!klee From: klee@chico.pa.dec.com (Ken Lee) Newsgroups: comp.windows.x Subject: Re: Problem with XFlush() after XDraw call Message-ID: <2241@bacchus.dec.com> Date: 7 Dec 89 01:55:00 GMT References: <4262@aplcen.apl.jhu.edu> Sender: news@decwrl.dec.com Reply-To: klee@decwrl.dec.com Distribution: usa Organization: DEC Western Software Laboratory Lines: 32 In article <4262@aplcen.apl.jhu.edu>, grobicki@aplvax.jhuapl.edu (Thomas A. Grobicki) writes: > I've been working on some simple X programming using the book X WINDOW > APPLICATIONS PROGRAMMING by E.F. Johnson and K. Reichard (MIS Press). I've > gotten to chapter 2, test program 2 (main is below) and have found some > curious behaviour. If I don't include the sleep() call after the draw > commands but before the XFlush(), the lines and box do not appear in the > window. To add to the mystery the sleep() call must be at least 3 for a > Sun 3/60 running either MIT-X 11R3 or Sun OpenWindows or at least 1 for a > VaxStation 3100 running DECWindows. This is perhaps the most common user problem in X programming. I'll give the authors of this book the benefit of the doubt and assume they intended these programs to be read, but not executed. Your progam will not run on any system using a window manager (almost all systems). The window manager places new top level windows, sometimes with user positioning. Your problem is that (without the sleep) you are drawing on the window without waiting for this positioning to occur, thus the drawing drops in the bit bucket. Your server will tell you when you the window is ready by sending you an Expose event. You should always request Expose events on your drawing windows and always wait for them before drawing. This is mentioned in Section 1.1 of the MIT Xlib manual. Why does the window manager take 3 seconds under OpenWindows and only 1 second under DECwindows? You can figure that one out. :-) Ken Lee DEC Western Software Laboratory, Palo Alto, Calif. Internet: klee@decwrl.dec.com uucp: uunet!decwrl!klee