[ Usenet FAQs | Web FAQs | Documents | RFC Index ]
Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page
Top Document: comp.windows.x Frequently Asked Questions (FAQ) 7/7
Previous Document: 171) How do I fork without hanging my parent X program?
Next Document: 173) What is the difference between a Screen and a screen?
-
Search the FAQ Archives
Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page
Top Document: comp.windows.x Frequently Asked Questions (FAQ) 7/7
Previous Document: 171) How do I fork without hanging my parent X program?
Next Document: 173) What is the difference between a Screen and a screen?
172) Why doesn't anything appear when I run this simple program?
> ...
> the_window = XCreateSimpleWindow(the_display,
> root_window,size_hints.x,size_hints.y,
> size_hints.width,size_hints.height,BORDER_WIDTH,
> BlackPixel(the_display,the_screen),
> WhitePixel(the_display,the_screen));
> ...
> XSelectInput(the_display,the_window,ExposureMask|ButtonPressMask|
> ButtonReleaseMask);
> XMapWindow(the_display,the_window);
> ...
> XDrawLine(the_display,the_window,the_GC,5,5,100,100);
> ...
You are right to map the window before drawing into it. However, the
window is not ready to be drawn into until it actually appears on the screen --
until your application receives an Expose event. Drawing done before that will
generally not appear. You'll see code like this in many programs; this code
would appear after the window was created and mapped:
while (!done)
{
XNextEvent(the_display,&the_event);
switch (the_event.type) {
case Expose: /* On expose events, redraw */
XDrawLine(the_display,the_window,the_GC,5,5,100,100);
break;
...
}
}
Note that there is a second problem: some Xlib implementations don't
set up the default graphics context to have correct foreground/background
colors, so this program could previously include this code:
...
the_GC_values.foreground=BlackPixel(the_display,the_screen); /* e.g. */
the_GC_values.background=WhitePixel(the_display,the_screen); /* e.g. */
the_GC = XCreateGC(the_display,the_window,
GCForeground|GCBackground,&the_GC_values);
...
Note: the code uses BlackPixel and WhitePixel to avoid assuming that 1 is
black and 0 is white or vice-versa. The relationship between pixels 0 and 1
and the colors black and white is implementation-dependent. They may be
reversed, or they may not even correspond to black and white at all.
Also note that actually using BlackPixel and WhitePixel is usually the wrong
thing to do in a finished program, as it ignores the user's preference for
foreground and background.
And also note that you can run into the same situation in an Xt-based program
if you draw into the XtWindow(w) right after it has been realized; it may
not yet have appeared.
Top Document: comp.windows.x Frequently Asked Questions (FAQ) 7/7
Previous Document: 171) How do I fork without hanging my parent X program?
Next Document: 173) What is the difference between a Screen and a screen?
Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page
[ Usenet FAQs | Web FAQs | Documents | RFC Index ]
Send corrections/additions to the FAQ Maintainer:
faq%craft@uunet.uu.net (X FAQ maintenance address)
Last Update October 22 2009 @ 05:36 AM