Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!amdcad!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!EXPO.LCS.MIT.EDU!converse From: converse@EXPO.LCS.MIT.EDU (Donna Converse) Newsgroups: comp.windows.x Subject: Re: How to Pause After XCreateWindow? Message-ID: <8903151703.AA16114@expo.lcs.mit.edu> Date: 15 Mar 89 17:03:10 GMT References: <4188@alvin.mcnc.org> Sender: daemon@bloom-beacon.MIT.EDU Organization: X Consortium, MIT Laboratory for Computer Science Lines: 64 > The problem is that I call XCreateWindow, but it doesn't pause. My > application speeds right along, eventually calling XGetWindowAttributes > BEFORE I've placed and sized the new window. Wait for the first expose event before determining the size of the window, or drawing in the window. XNextEvent blocks on the event queue. This code is rude to the window manager; see David Rosenthal's "Hello World" for a proper version; but you should read it & get the right idea. #include #include main(argc, argv) int argc; char **argv; { Display *dpy; int screen; unsigned int width, height; XSetWindowAttributes xswa; unsigned long valuemask; Window window; XEvent event; XExposeEvent *expose_event; XWindowAttributes xwa; if ((dpy = XOpenDisplay((char *) NULL)) == NULL) { (void) fprintf(stderr, "%s: cannot open display \"%s\".\n", argv, XDisplayName((char *) NULL)); exit(1); } screen = DefaultScreen(dpy); xswa.background_pixel = WhitePixel(dpy, screen); xswa.border_pixel = BlackPixel(dpy, screen); xswa.event_mask = ExposureMask; valuemask = CWBackPixel | CWBorderPixel | CWEventMask; window = XCreateWindow(dpy, RootWindow(dpy, screen), 10, 10, 100, 100, 2, CopyFromParent, InputOutput, CopyFromParent, valuemask, &xswa); XStoreName(dpy, window, "Demo"); XMapWindow(dpy, window); width = height = 0; expose_event = (XExposeEvent *) &event; while (1) { XNextEvent(dpy, &event); if (event.type == Expose && expose_event->count == 0) { if (XGetWindowAttributes(dpy, window, &xwa) == 0) break; if (width != xwa.width || height != xwa.height) { width = xwa.width; height = xwa.height; printf("The current window size is %d by %d.\n", width, height); } } } }