From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Subject: Re: HELP! XSetWindowAttributes and XSetWMHints
Organization: McGill Research Centre for Intelligent Machines
Date: Sun, 6 Sep 92 08:16:09 GMT

In article <1992Sep4.015632.947@mailhost.ocs.mq.edu.au>, s8923098@macnab.mqcs.mq.oz.au (Josef WIDJAJA) writes:

> I am trying to put an image (using XPutImage) or a drawing (eg. using
> XFillRectangle) into a Window. So far, the image/drawing can be
> displayed if I set the override_redirect field in the
> XSetWindowAttributes structure for my window to True.  [...this
> disables WM decorations...]

> When I set the override_redirect to False, [...] the image/drawing is
> not displayed.

You don't give enough detail to be certain, but I suspect your problem
is the one addressed by FAQ item 129:

----------------------------------------------------------------------
Subject: 129)  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 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.

----------------------------------------------------------------------

					der Mouse

			    mouse@larry.mcrcim.mcgill.edu