pickel@mcnc.org (Lisa C. Pickel) (03/15/89)
In the days of X10, I used XCreate to start a window. This function apparently paused while the window manager allowed to user to size the window. I then called XQueryWindow to get the size of the window. Unfortunately, I cannot seem to mimic this behavior with X11. 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. Thus, the values I get back are quite possibly garbage since they refer to the default values for my window. How do I fix this? I've tried doing XFlush-es, XSync-s, even XMapRaised. I've tried messing with override-retry or some such thing. My apologies for this question as I bet it's been asked before. Lisa. pickel@mcnc.org decvax!mcnc!pickel
converse@EXPO.LCS.MIT.EDU (Donna Converse) (03/16/89)
> 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 <stdio.h> #include <X11/Xlib.h> 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); } } } }
klee@daisy.UUCP (Ken Lee) (03/16/89)
In article <4188@alvin.mcnc.org> pickel@mcnc.org (Lisa C. Pickel) writes: >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. Try waiting (XNextEvent) for a MapNotify event (StructureNotifyMask). That will tell you when you're mapped. You should probably also wait for ConfigureNotify events, since your window manager might change your window attributes at any time. Ken Lee -- klee@daisy.uucp Daisy Systems Corp., Interactive Graphics Tools Dept.
davidl@intelob.intel.com (David Levine) (03/16/89)
In article <8903151703.AA16114@expo.lcs.mit.edu> converse@EXPO.LCS.MIT.EDU (Donna Converse) writes: > 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. What makes this code rude to the WM? Looks polite enough to me... David D. Levine BBBBBBBBB IIII IIII NNN NNNN TM Senior Technical Writer BBBB BBBB iiii iiii NNNN NNNN BBBBBBBBB IIII IIII NNNNNNNNN UUCP: ...[!uunet]!tektronix!biin!davidl BBBB BBBB IIII IIII NNNN NNNN MX-Internet: <davidl@intelob.intel.com> BBBBBBBBB IIII IIII NNNN NNN ARPA: <@iwarp.intel.com:davidl@intelob.intel.com>