home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / windows / x / 16245 < prev    next >
Encoding:
Text File  |  1992-09-08  |  3.4 KB  |  86 lines

  1. Newsgroups: comp.windows.x
  2. Path: sparky!uunet!snorkelwacker.mit.edu!thunder.mcrcim.mcgill.edu!mouse
  3. From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
  4. Subject: Re: HELP! XSetWindowAttributes and XSetWMHints
  5. Message-ID: <1992Sep6.081609.18966@thunder.mcrcim.mcgill.edu>
  6. Organization: McGill Research Centre for Intelligent Machines
  7. References: <1992Sep4.015632.947@mailhost.ocs.mq.edu.au>
  8. Date: Sun, 6 Sep 92 08:16:09 GMT
  9. Lines: 76
  10.  
  11. In article <1992Sep4.015632.947@mailhost.ocs.mq.edu.au>, s8923098@macnab.mqcs.mq.oz.au (Josef WIDJAJA) writes:
  12.  
  13. > I am trying to put an image (using XPutImage) or a drawing (eg. using
  14. > XFillRectangle) into a Window. So far, the image/drawing can be
  15. > displayed if I set the override_redirect field in the
  16. > XSetWindowAttributes structure for my window to True.  [...this
  17. > disables WM decorations...]
  18.  
  19. > When I set the override_redirect to False, [...] the image/drawing is
  20. > not displayed.
  21.  
  22. You don't give enough detail to be certain, but I suspect your problem
  23. is the one addressed by FAQ item 129:
  24.  
  25. ----------------------------------------------------------------------
  26. Subject: 129)  Why doesn't anything appear when I run this simple program?
  27.  
  28. > ...
  29. > the_window = XCreateSimpleWindow(the_display,
  30. >      root_window,size_hints.x,size_hints.y,
  31. >      size_hints.width,size_hints.height,BORDER_WIDTH,
  32. >      BlackPixel(the_display,the_screen),
  33. >      WhitePixel(the_display,the_screen));
  34. > ...
  35. > XSelectInput(the_display,the_window,ExposureMask|ButtonPressMask|
  36. >     ButtonReleaseMask);
  37. > XMapWindow(the_display,the_window);
  38. > ...
  39. > XDrawLine(the_display,the_window,the_GC,5,5,100,100);
  40. > ...
  41.  
  42.     You are right to map the window before drawing into it. However, the 
  43. window is not ready to be drawn into until it actually appears on the screen --
  44. until your application receives an Expose event. Drawing done before that will 
  45. generally not appear. You'll see code like this in many programs; this code 
  46. would appear after window was created and mapped:
  47.   while (!done)
  48.     {
  49.       XNextEvent(the_display,&the_event);
  50.       switch (the_event.type) {
  51.     case Expose:     /* On expose events, redraw */
  52.         XDrawLine(the_display,the_window,the_GC,5,5,100,100);
  53.         break;
  54.     ...
  55.     }
  56.     }
  57.  
  58.     Note that there is a second problem: some Xlib implementations don't 
  59. set up the default graphics context to have correct foreground/background 
  60. colors, so this program could previously include this code:
  61.   ...
  62.   the_GC_values.foreground=BlackPixel(the_display,the_screen);    /* e.g. */
  63.   the_GC_values.background=WhitePixel(the_display,the_screen);    /* e.g. */
  64.   the_GC = XCreateGC(the_display,the_window,
  65.                 GCForeground|GCBackground,&the_GC_values);
  66.   ...
  67.  
  68. Note: the code uses BlackPixel and WhitePixel to avoid assuming that 1 is 
  69. black and 0 is white or vice-versa.  The relationship between pixels 0 and 1 
  70. and the colors black and white is implementation-dependent.  They may be 
  71. reversed, or they may not even correspond to black and white at all.
  72.  
  73. Also note that actually using BlackPixel and WhitePixel is usually the wrong 
  74. thing to do in a finished program, as it ignores the user's preference for 
  75. foreground and background.
  76.  
  77. And also note that you can run into the same situation in an Xt-based program
  78. if you draw into the XtWindow(w) right after it has been realized; it may
  79. not yet have appeared.
  80.  
  81. ----------------------------------------------------------------------
  82.  
  83.                     der Mouse
  84.  
  85.                 mouse@larry.mcrcim.mcgill.edu
  86.