home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / fj / maillis / xwindow / 17614 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  54.8 KB

  1. Path: sparky!uunet!stanford.edu!sun-barr!sh.wide!wnoc-tyo-news!scslwide!wsgw!wsservra!daemon
  2. From: dbl@visual.com (David B. Lewis)
  3. Newsgroups: fj.mail-lists.x-window
  4. Subject: comp.windows.x Frequently Asked Questions (FAQ) 4/4
  5. Message-ID: <1992Nov19.010130.20143@sm.sony.co.jp>
  6. Date: 19 Nov 92 01:01:30 GMT
  7. Sender: daemon@sm.sony.co.jp (The devil himself)
  8. Distribution: fj
  9. Organization: Visual
  10. Lines: 1137
  11. Approved: michael@sm.sony.co.jp
  12.  
  13. Date: Tue, 17 Nov 92 22:10:19 GMT
  14. Message-Id: <1992Nov17.221019.9763@visual.com>
  15. Newsgroups: comp.windows.x,news.answers
  16. Sender: xpert-request@expo.lcs.mit.edu
  17.  
  18. Archive-name: x-faq/part4
  19. Last-modified: 1992/11/16
  20.  
  21.  
  22. ----------------------------------------------------------------------
  23. Subject: 102)  TOPIC: BUILDING X PROGRAMS 
  24. ----------------------------------------------------------------------
  25. Subject: 103)  What is Imake?
  26.  
  27.     Imake is not a replacement for the make program; instead, it is a
  28. makefile-generator that takes advantages of the include-file and macro-
  29. processing capabilities of the C preprocessor cpp to generate makefiles 
  30. suitable for building software on a particular system. Although it is not 
  31. specific to X, the X release uses it to help solve a number of the 
  32. configuration issues that arise in making such a large system widely portable.
  33.     Imake has a fairly steep learning curve, in part because the process by
  34. which the system-specific configuration files, system-independent configuration
  35. files, and individual Imakefiles are melded to produce a Makefile is not 
  36. obvious.
  37.     There have been several different versions of imake; the R3, R4, and
  38. R5 versions are different.
  39.  
  40.     You can obtain information on imake from these sources:
  41.     - the R4 and R5 release notes and imake man page include information on
  42. using Imake to build X
  43.     - the R4 and R5 file mit/config/README also contains useful information
  44.     - on the R4 tapes, contrib/doc/imake/imake.tex is Mark Moraes' R3/R4
  45. guide to imake.
  46.     - the R5 mit/doc/config/usenixws/paper.ms contains a paper by Jim
  47. Fulton on an early version of Imake
  48.     - Paul Dubois (dubois@primate.wisc.edu) has written a useful 
  49. explanation of how Imake works and how to use it in configuring X for non-
  50. supported systems; the document is available from ftp.primate.wisc.edu
  51. in the directory ~ftp/pub/imake-stuff; look for config-X11R4.ms (troff) and 
  52. config-X11R4.ps (PostScript). Some supplemental appendices are nearby. 
  53. [7/91: document version is now 1.06]
  54.     - see "System Administration - Imake: Friend of Foe?" by Dinah McNutt
  55. in the November 1991 issue of SunExpert.
  56.     - German readers should expect in June 1992 an article "Das Meta-Make 
  57. / I make, you make / Schwerelos" by Rainer Klute in "iX 
  58. Multiuser-Multitasking-Magazin", directed at application programmers needing to 
  59. write Imakefiles. An English-language derivative of this article is in The
  60. X Journal, issue 2:1.
  61.     - The O'Reilly X Resource issue #2 contains Paul Davey's article on
  62. demystifying Imake.
  63.     - Alain Brossard's working document full of tips on Imake is in 
  64. sasun1.epfl.ch:pub/imakefile.1.Z.
  65.  
  66. [1/91;12/91;5/92;8/92]
  67.  
  68. ----------------------------------------------------------------------
  69. Subject: 104)  Where can I get imake?
  70.  
  71.     Versions are distributed with the R4 and R5 releases. An earlier 
  72. version is distributed with the X11R3 release; some third-party toolkits 
  73. redistribute versions of imake along with their own implementations of the 
  74. template and configuration files. There are no real standards for such 
  75. configuration files, although most *current* contributed software expects the 
  76. templates distributed with X11R5.
  77.     export contains the R5 distribution unpacked, so you can pick up imake
  78. without picking up the entire distribution.
  79.     A stand-alone version of Imake, but one stemming from X11R5, is in
  80. ftp.germany.eu.net:pub/X11/misc/imake/imake-pure.tar.Z (192.76.144.75).
  81.  
  82. ----------------------------------------------------------------------
  83. Subject: 105)  I have a program with an Imakefile but no Makefile. What to do?
  84.  
  85.     If you have R4 or R5 installed on your system, run "xmkmf". This is a 
  86. script which runs imake for you with the correct arguments. The output is a 
  87. Makefile configured for your system and based on the Imakefile. Then run make, 
  88. which will use that new Makefile to compile the program.
  89.  
  90. ----------------------------------------------------------------------
  91. Subject: 106)  Why can't I link to the Xlib shape routines?
  92. When I try to compile certain programs, I get the following link error:
  93.     Undefined:
  94.     _XShapeQueryExtension
  95.     _XShapeCombineMask
  96.  
  97.     These routines are actually part of the Shape Extension to X (SHAPE)
  98. which was introduced in the MIT X11R4 distribution and allows non-rectangular
  99. windows.  Like the other sample server extensions, the shape extension will 
  100. only run on a server which supports it.  Pre-X11R4 servers, as well as many 
  101. vendor-supplied servers, do not support the shape extension, in which case 
  102. they will display rectangular windows anyway.
  103.  
  104.     In order to use the shape extension, you must link to the library 
  105. libXext.a.  In the X11R4 distribution, this library and the associated includes
  106. will be in the mit/extensions directory.  If you do not have these files, do 
  107. not despair:  many freeware programs which use the shape extension can also be 
  108. compiled without it by removing the -DSHAPE define from the Makefile; you can
  109. probably do this and compile successfully against your older vendor-supplied X 
  110. libraries.
  111.  
  112. [from John B. Melby, melby%yk.fujitsu.co.jp@uunet.uu.net, 3/91]
  113.  
  114. ----------------------------------------------------------------------
  115. Subject: 107)  What are these problems with "_XtInherit not found" on the Sun?
  116. When I run a X program that I wrote on a SunOS 4.0.3 or 4.1 machine I get the 
  117. error "ld.so: symbol not found _XtInherit".
  118.  
  119.     What you are seeing is a side-effect of a kludge in the R4 libXt.a to 
  120. get Sun shared libraries working.  Apparently, you can't share a function that 
  121. is both called and compared, as _XtInherit is. This was handled by putting 
  122. _XtInherit in the same file as a function that is always used, thereby 
  123. guaranteeing that it would be loaded -- that is, in Initialize.c, where 
  124. XtToolkitInitialize() and XtInitialize() reside. These routines would normally
  125. be called.
  126.  
  127.     You are probably seeing this error because your program is not a normal
  128. Xt-based program and does not call XtToolkitInitialize() anywhere. 
  129.     1) it may be a program that uses Xt functions but never opens a 
  130. connection to the X server.  [OSF/Motif's 1.1.0 UIL had this problem; it called
  131. XtMalloc() and other Xt functions.] The solution is to add the call to your 
  132. program; the function does not have to be executed, just linked in.
  133.     2) alternatively, your program doesn't need any Xt functions and is
  134. correct in not calling XtToolkitInitialize() -- it may be an Xlib or XView 
  135. program. In this case, you can remove -lXt from your link command. 
  136.  
  137.     It should not be necessary to link the shared libraries statically,
  138. although this will certainly solve the problem.
  139.     
  140. [from Jordan Hayes (now jordan@MooreNet.COM) and Danny Backx (db@sunbim.be); 
  141. 11/90]
  142.  
  143. ----------------------------------------------------------------------
  144. Subject: 108)  Why can't I compile my R3 Xaw contrib programs under the new X?
  145. I have a program that worked well under X11R3. When I try to link it under 
  146. the current version of X, I get this message:
  147.     Undefined:
  148.     _XtScrollBarSetThumb
  149.     _XtTextSetInsertionPoint
  150.     _XtTextReplace
  151.  
  152.     There were several name changes in the Athena widget set (in addition
  153. to the header files moving into <X11/Xaw/>); these are mentioned in the R4
  154. release notes. In this case, these functions are not really Xt functions but
  155. are part of the Xaw text widget and so have been renamed from Xt* to Xaw*.
  156. [10/90]
  157.  
  158. ----------------------------------------------------------------------
  159. Subject: 109)  TOPIC: PROGRAMMING PROBLEMS AND PUZZLES
  160. ----------------------------------------------------------------------
  161. Subject: 110)  Why doesn't my program get the keystrokes I select for (sic)?
  162.  
  163.     The window manager controls how the input focus is transferred from one
  164. window to another.  In order to get keystrokes, your program must ask the
  165. window manager for the input focus.  To do this, you must set up what are
  166. called "hints" for the window manager.  If your applications is Xlib-based, you
  167. can use something like the following:
  168.  
  169.         XWMHints wmhints;
  170.         ...
  171.         wmhints.flags = InputHint;
  172.         wmhints.input = True;
  173.         XSetWMHints(dpy, window, &wmhints)
  174.  
  175. If your application is based on the Xt Intrinsics, you can set the XtNinput 
  176. resource to be True (as you probably want to in any case); if you don't have
  177. source, you can start up the application with the resource '*input:True'.
  178.  
  179. Certain window managers, notably dxwm and olwm, are very picky about having 
  180. this done. 
  181.  
  182.     If you are using Sun's OpenWindows olwm, you can also add this resource
  183. to your defaults file to use clients that aren't ICCCM-compliant.
  184.     OpenWindows.FocusLenience:       true
  185.  
  186. [mostly courtesy Dave Lemke of NCD and Stuart Marks of Sun]
  187.  
  188. ----------------------------------------------------------------------
  189. Subject: 111)  How do I figure out what window manager is running?
  190.  
  191.     You can't reliably tell; whatever mechanism you could use could be
  192. spoofed in any case. 
  193.     For most cases, you shouldn't care which window manager is running, so 
  194. long as you do things in an ICCCM-conformant manner. There are some cases in 
  195. which particular window managers are known to do things wrong; checking for
  196. particular hints placed on the window by the window manager so that you can 
  197. sidestep the problem may be appropriate in these cases. Alternatively, it may 
  198. be appropriate to determine which window manager is running in order to take
  199. advantage of specific *added* features (such as olwm's push-pin menus) in order
  200. to give your program *added* functionality. Beware of usurping the window 
  201. manager's functions by providing that functionality even when it is missing;
  202. this surely leads to future compatibility problems.
  203.  
  204. ----------------------------------------------------------------------
  205. Subject: 112)  Is there a skeleton X program available?
  206.     
  207.     There is no general framework such as the TransSkel program for the 
  208. Macintosh which handles lots of the odds and ends and overhead of development 
  209. under a window system and which can be used as a platform for additional 
  210. development. In X, the problem is typically solved by using an interactive 
  211. application builder tool or by using cut&paste on existing X applications. Good
  212. applications which you might look to manipulate when you want to "test just 
  213. this one little thing" include contrib/clients/xskel, a simple R4 program that 
  214. puts up a window and allows sketching in it and offers a starting point for
  215. quick hacks, the Xaw examples in the examples/ directory in the R3 and R4 
  216. distributions, and the Xlib "Hello World" example in the R3 doc/HelloWorld and 
  217. R4 doc/tutorials/HelloWorld; an updated version of this program which uses R4 
  218. Xlib calls and current ICCCM conventions was posted in 2/90 to comp.windows.x  
  219. by Glenn Widener of Tektronix.     [3/90]
  220.  
  221.     In addition, a sample Xt program (for Xaw or Xm) by Rainer Klute 
  222. showing how to open multiple displays and how to catch a broken display 
  223. connection is available on export.lcs.mit.edu in contrib/mdisp.tar.Z. [4/92]
  224.  
  225. ----------------------------------------------------------------------
  226. Subject: 113)  Why does XtGetValues not work for me (sic)?
  227.  
  228.     The XtGetValues interface for retrieving resources from a widget is
  229. sensitive to the type of variable. Your code may be doing something like this:
  230.     {
  231.     Arg args[3];
  232.     int i;
  233.     int sensitive;        /* oops; wrong data type */
  234.     i=0;
  235.     XtSetArg (args[i], XtNsensitive, &sensitive); i++;
  236.     XtGetValues(widget, args, i );
  237.     ...
  238.     }
  239.  
  240. But XtNsensitive is a Boolean, which on most machines is a single byte; 
  241. declaring the variable "sensitive" as Boolean works properly. This problem 
  242. comes up often when using particular toolkits that redefine the Xt types 
  243. Dimension and Position; code that assumes they are int will have similar 
  244. problems if those types are actually short. In general: you are safe if you
  245. use the actual type of the resource, as it appears in the widget's man page.
  246. [11/90]
  247.  
  248. ----------------------------------------------------------------------
  249. Subject: 114)  Why don't XtConfigureWidget/XtResizeWidget/XtMoveWidget work?
  250.  
  251.     You're probably trying to use these functions from application code.
  252. They should be used only internally to widgets; these functions are for a 
  253. parent widget to change the geometry of its children. Other promising 
  254. functions, XtMakeGeometryRequest() and XtMakeResizeRequest(), are also for use 
  255. only by widgets, in this case by a child to request a change from its parent.
  256.     The only way for your application to request a geometry change for a
  257. widget is to issue an XtSetValues call setting some of the geometry resources.
  258. Although this will result in the widget-internal functions' being called, your
  259. application code must use the standard XtSetValues interface or risk the 
  260. widgets' data becoming corrupted.
  261.     [The Xlib calls XMoveWindow() and XResizeWindow() should similarly be 
  262. avoided; they shouldn't be used to change XtNx, XtNy, XtNwidth, or XtNheight.]
  263.  
  264. ----------------------------------------------------------------------
  265. Subject: 115)  Why isn't there an XtReparentWidget call like XReparentWindow?
  266.  
  267.     Although there are various details of the current implementation of
  268. the Xt internals which make reparenting difficult, the major reason that no
  269. such call exists is that it remains undefined what the set of resources for
  270. the "new" widget should be. Resources are typically set based on the location
  271. in the instance hierarchy; what resources should change if the instance moves?
  272. What should happen to the widget's children? And by the time such semantics are
  273. defined, there would probably be little advantage over destroying the old 
  274. widget and creating a new widget in the correct location with the desired 
  275. resources, as setting the resources correctly is the majority of work in 
  276. creating a new widget.
  277.  
  278.     Note that reparenting is possible in the OI toolkit.
  279.  
  280. ----------------------------------------------------------------------
  281. Subject: 116)  I'm writing a widget and can't use a float as a resource value.
  282.  
  283. Float resources are not portable; the size of the value may be larger than
  284. the size of an XtPointer. Try using a pointer to a float instead; the Xaw
  285. Scrollbar float resources are handled in this way. 
  286.  
  287. ----------------------------------------------------------------------
  288. Subject: 117)  Is this a memory leak in the X11R4 XtDestroyWidget()?!
  289.  
  290. Yes. This is the "unofficial" fix-19 for the X11R4 Destroy.c:
  291.  
  292. *** Destroy.c.1.37    Thu Jul 11 15:41:25 1991
  293. --- lib/Xt/Destroy.c    Thu Jul 11 15:42:23 1991
  294. ***************
  295. *** 1,4 ****
  296. --- 1,5 ----
  297.   /* $XConsortium: Destroy.c,v 1.37 90/09/28 10:21:32 swick Exp $ */
  298. + /* Plus unofficial patches in revisions 1.40 and 1.41 */
  299.   
  300.   /***********************************************************
  301.   Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  302. ***************
  303. *** 221,239 ****
  304.        */
  305.   
  306.       int i = 0;
  307. !     DestroyRec* dr = app->destroy_list;
  308.       while (i < app->destroy_count) {
  309.       if (dr->dispatch_level >= dispatch_level)  {
  310.           Widget w = dr->widget;
  311.           if (--app->destroy_count)
  312.           bcopy( (char*)(dr+1), (char*)dr,
  313. !                app->destroy_count*sizeof(DestroyRec)
  314.                 );
  315.           XtPhase2Destroy(w);
  316.       }
  317.       else {
  318.           i++;
  319. -         dr++;
  320.       }
  321.       }
  322.   }
  323. --- 222,245 ----
  324.        */
  325.   
  326.       int i = 0;
  327. !     DestroyRec* dr;
  328.       while (i < app->destroy_count) {
  329. +     /* XtPhase2Destroy can result in calls to XtDestroyWidget,
  330. +      * and these could cause app->destroy_list to be reallocated.
  331. +      */
  332. +     dr = app->destroy_list + i;
  333.       if (dr->dispatch_level >= dispatch_level)  {
  334.           Widget w = dr->widget;
  335.           if (--app->destroy_count)
  336.           bcopy( (char*)(dr+1), (char*)dr,
  337. !                (app->destroy_count - i) * sizeof(DestroyRec)
  338.                 );
  339.           XtPhase2Destroy(w);
  340.       }
  341.       else {
  342.           i++;
  343.       }
  344.       }
  345.   }
  346.  
  347. [from Donna Converse, converse@expo.lcs.mit.EDU]
  348.  
  349. ----------------------------------------------------------------------
  350. Subject: 118)  Are callbacks guaranteed to be called in the order registered?
  351.  
  352.     Although some books demonstrate that the current implementation of Xt
  353. happens to call callback procedures in the order in which they are registered, 
  354. the specification does not guarantee such a sequence, and supplemental 
  355. authoritative documents (i.e. the Asente/Swick volume) do say that the order is
  356. undefined.  Because the callback list can be manipulated by both the widget and
  357. the application, Xt cannot guarantee the order of execution.
  358.     In general, the callback procedures should be thought of as operating 
  359. independently of one another and should not depend on side-effects of other
  360. callbacks operating; if a seqence is needed, then the single callback to be 
  361. registered can explicitly call other functions necessary.
  362.  
  363. [4/92; thanks to converse@expo.lcs.mit.edu]
  364.  
  365. ----------------------------------------------------------------------
  366. Subject: 119)  Why doesn't XtDestroyWidget() actually destroy the widget?
  367.  
  368.     XtDestroyWidget() operates in two passes, in order to avoid leaving
  369. dangling data structures; the function-call marks the widget, which is not 
  370. actually destroyed until your program returns to its event-loop. 
  371.  
  372. ----------------------------------------------------------------------
  373. Subject: 120)  How do I query the user synchronously using Xt?
  374.     
  375.     It is possible to have code which looks like this trivial callback,
  376. which has a clear flow of control. The calls to AskUser() block until answer
  377. is set to one of the valid values. If it is not a "yes" answer, the code drops
  378. out of the callback and back to an event-processing loop: 
  379.  
  380.     void quit(Widget w, XtPointer client, XtPointer call)
  381.     {
  382.         int             answer;
  383.         answer = AskUser(w, "Really Quit?");
  384.         if (RET_YES == answer)
  385.             {
  386.             answer = AskUser(w, "Are You Really Positive?");
  387.             if (RET_YES == answer)
  388.                 exit(0);
  389.                 }
  390.     }
  391.  
  392.     A more realistic example might ask whether to create a file or whether 
  393. to overwrite it.
  394.     This is accomplished by entering a second event-processing loop and
  395. waiting until the user answers the question; the answer is returned to the
  396. calling function. That function AskUser() looks something like this, where the 
  397. Motif can be replaced with widget-set-specific code to create some sort of 
  398. dialog-box displaying the question string and buttons for "OK", "Cancel" and 
  399. "Help" or equivalents:
  400.  
  401.   int AskUser(w, string)
  402.         Widget          w;
  403.         char           *string;
  404.   {
  405.         int             answer=RET_NONE;    /* some not-used marker */
  406.         Widget          dialog;            /* could cache&carry, but ...*/
  407.         Arg             args[3];
  408.         int             n = 0;
  409.         XtAppContext    context;
  410.  
  411.         n=0;
  412.         XtSetArg(args[n], XmNmessageString, XmStringCreateLtoR(string,
  413.                 XmSTRING_DEFAULT_CHARSET)); n++;
  414.         XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); n++;
  415.         dialog = XmCreateQuestionDialog(XtParent(w), string, args, n);
  416.         XtAddCallback(dialog, XmNokCallback, response, &answer);
  417.         XtAddCallback(dialog, XmNcancelCallback, response, &answer);
  418.         XtAddCallback(dialog, XmNhelpCallback, response, &answer);
  419.         XtManageChild(dialog);
  420.  
  421.         context = XtWidgetToApplicationContext (w);
  422.         while (answer == RET_NONE || XtAppPending(context)) {
  423.                 XtAppProcessEvent (context, XtIMAll);
  424.         }
  425.         XtDestroyWidget(dialog);  /* blow away the dialog box and shell */
  426.         return answer;
  427.   }
  428.  
  429.     The dialog supports three buttons, which are set to call the same 
  430. function when tickled by the user.  The variable answer is set when the user 
  431. finally selects one of those choices:
  432.  
  433.   void response(w, client, call)
  434.         Widget          w;
  435.         XtPointer client;
  436.         XtPointer call;
  437.   {
  438.   int *answer = (int *) client;
  439.   XmAnyCallbackStruct *reason = (XmAnyCallbackStruct *) call;
  440.         switch (reason->reason) {
  441.         case XmCR_OK:
  442.                 *answer = RET_YES;    /* some #define value */
  443.                 break;
  444.         case XmCR_CANCEL:
  445.                 *answer = RET_NO; 
  446.         break;
  447.         case XmCR_HELP:
  448.                 *answer = RET_HELP;
  449.                 break;
  450.         default:
  451.                 return;
  452.         }
  453. }
  454.  
  455. and the code unwraps back to the point at which an answer was needed and
  456. continues from there.
  457.  
  458. [Thanks to Dan Heller (argv@sun.com); further code is in Dan's R3/contrib
  459. WidgetWrap library. 2/91]
  460.  
  461. ----------------------------------------------------------------------
  462. Subject: 121)  How do I determine the name of an existing widget?
  463. I have a widget ID and need to know what the name of that widget is.
  464.  
  465.     Users of R4 and later are best off using the XtName() function, which 
  466. will work on both widgets and non-widget objects.
  467.  
  468.     If you are still using R3, you can use this simple bit of code to do 
  469. what you want. Note that it depends on the widget's internal data structures 
  470. and is not necessarily portable to future versions of Xt, including R4.
  471.  
  472.     #include <X11/CoreP.h>
  473.     #include <X11/Xresource.h>
  474.     String XtName (widget)
  475.     Widget widget;    /* WILL work with non-widget objects */
  476.     {
  477.     return XrmNameToString(widget->core.xrm_name);
  478.     }
  479.  
  480. [7/90; modified with suggestion by Larry Rogers (larry@boris.webo.dg.com) 9/91]
  481.  
  482. ----------------------------------------------------------------------
  483. Subject: 122)  What widget is appropriate to use as a drawing canvas?
  484.  
  485.     Some widget sets have a widget particularly for this purpose -- a
  486. WorkSpace or DrawingArea which doesn't display anything but lets your Xt 
  487. application know when it has been re-exposed, resized, and when it has received
  488. user key and mouse input. 
  489.     The best thing to do for other widget sets -- including the Athena set 
  490. -- is to create or obtain such a widget; this is preferable to drawing into a 
  491. core widget and grabbing events with XtAddEventHandler(), which loses a number 
  492. of benefits of Xt and encapsulation of the functionality .  At least one 
  493. version has been posted to comp.sources.x (name???). The publicly-available 
  494. programs xball and xpic include other versions. And the Athena Widget manual 
  495. (mit/doc/Xaw/Template in the R5 distribution) includes a tutorial and source 
  496. code to a simple widget which is suitable for use.
  497.  
  498. ----------------------------------------------------------------------
  499. Subject: 123)  Why do I get a BadDrawable error drawing to XtWindow(widget)?
  500. I'm doing this in order to get a window into which I can do Xlib graphics
  501. within my Xt-based program:
  502.  
  503. > canvas = XtCreateManagedWidget ( ...,widgetClass,...) /* drawing area */
  504. > ...
  505. > window = XtWindow(canvas);    /* get the window associated with the widget */
  506. > ...
  507. > XDrawLine (...,window,...);    /* produces error */
  508.  
  509.     The window associated with the widget is created as a part of the 
  510. realization of the widget.  Using a window id of NULL ("no window") could 
  511. create the error that you describe.  It is necessary to call XtRealizeWidget() 
  512. before attempting to use the window associated with a widget. 
  513.     Note that the window will be created after the XtRealizeWidget() call, 
  514. but that the server may not have actually mapped it yet, so you should also 
  515. wait for an Expose event on the window before drawing into it.
  516.  
  517. ----------------------------------------------------------------------
  518. Subject: 124)  Why do I get a BadMatch error when calling XGetImage?
  519.  
  520. The BadMatch error can occur if the specified rectangle goes off the edge of 
  521. the screen. If you don't want to catch the error and deal with it, you can take
  522. the following steps to avoid the error:
  523.  
  524. 1) Make a pixmap the same size as the rectangle you want to capture.
  525. 2) Clear the pixmap to background using XFillRectangle.
  526. 3) Use XCopyArea to copy the window to the pixmap.
  527. 4) If you get a NoExpose event, the copy was clean. Use XGetImage to grab the
  528. image from the pixmap.
  529. 5) If you get one or more GraphicsExpose events, the copy wasn't clean, and 
  530. the x/y/width/height members of the GraphicsExpose event structures tell you 
  531. the parts of the pixmap which aren't good.
  532. 6) Get rid of the pixmap; it probably takes a lot of memory.
  533.  
  534. [10/92; thanks to Oliver Jones (oj@pictel.com)]
  535.  
  536. ----------------------------------------------------------------------
  537. Subject: 125)  How can my application tell if it is being run under X?
  538.  
  539.     A number of programs offer X modes but otherwise run in a straight
  540. character-only mode. The easiest way for an application to determine that it is
  541. running on an X display is to attempt to open a connection to the X server:
  542.     
  543.     display = XOpenDisplay(display_name);
  544.     if (display)
  545.         { do X stuff }
  546.     else
  547.         { do curses or something else }
  548. where display_name is either the string specified on the command-line following
  549. -display, by convention, or otherwise is (char*)NULL [in which case 
  550. XOpenDisplay uses the value of $DISPLAY, if set].
  551.  
  552. This is superior to simply checking for the existence a -display command-line 
  553. argument or checking for $DISPLAY set in the environment, neither of which is 
  554. adequate. [5/91]
  555.  
  556. ----------------------------------------------------------------------
  557. Subject: 126)  How do I make a "busy cursor" while my application is computing?
  558. Is it necessary to call XDefineCursor() for every window in my application?
  559.  
  560.     The easiest thing to do is to create a single InputOnly window that is 
  561. as large as the largest possible screen; make it a child of your toplevel 
  562. window and it will be clipped to that window, so it won't affect any other 
  563. application. (It needs to be as big as the largest possible screen in case the 
  564. user enlarges the window while it is busy or moves elsewhere within a virtual 
  565. desktop.) Substitute "toplevel" with your top-most widget here (similar code 
  566. should work for Xlib-only applications; just use your top Window):
  567.  
  568.      unsigned long valuemask;
  569.      XSetWindowAttributes attributes;
  570.  
  571.      /* Ignore device events while the busy cursor is displayed. */
  572.      valuemask = CWDontPropagate | CWCursor;
  573.      attributes.do_not_propagate_mask =  (KeyPressMask | KeyReleaseMask |
  574.          ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
  575.      attributes.cursor = XCreateFontCursor(XtDisplay(toplevel), XC_watch);
  576.  
  577.      /* The window will be as big as the display screen, and clipped by
  578.         its own parent window, so we never have to worry about resizing */
  579.      XCreateWindow(XtDisplay(toplevel), XtWindow(toplevel), 0, 0,
  580.          65535, 65535, (unsigned int) 0, CopyFromParent, InputOnly,
  581.          CopyFromParent, valuemask, &attributes);
  582.  
  583. When you want to use this busy cursor, map and raise this window; to go back to
  584. normal, unmap it. This will automatically keep you from getting extra mouse
  585. events; depending on precisely how the window manager works, it may or may not
  586. have a similar effect on keystrokes as well.
  587.  
  588. In addition, note also that most of the Xaw widgets support an XtNcursor 
  589. resource which can be temporarily reset, should you merely wish to change the
  590. cursor without blocking pointer events.
  591.  
  592. [thanks to Andrew Wason (aw@cellar.bae.bellcore.com), Dan Heller 
  593. (argv@sun.com), and mouse@larry.mcrcim.mcgill.edu; 11/90,5/91]
  594.  
  595. ----------------------------------------------------------------------
  596. Subject: 127)  How do I fork without hanging my parent X program?
  597.  
  598.     An X-based application which spawns off other Unix processes which 
  599. continue to run after it is closed typically does not vanish until all of its 
  600. children are terminated; the children inherit from the parent the open X 
  601. connection to the display. 
  602.     What you need to do is fork; then, immediately, in the child process, 
  603.     close (ConnectionNumber(XtDisplay(widget)));
  604. to close the file-descriptor in the display information. After this do your 
  605. exec. You will then be able to exit the parent.
  606.  
  607. [Thanks to Janet Anstett (anstettj@tramp.Colorado.EDU) and Gordon Freedman 
  608. (gjf00@duts.ccc.amdahl.com) 2/91]
  609.  
  610. ----------------------------------------------------------------------
  611. Subject: 128)  Can I make Xt or Xlib calls from a signal handler?
  612.  
  613.     No. Xlib and Xt have no mutual exclusion for protecting critical 
  614. sections. If your signal handler makes such a call at the wrong time (which 
  615. might be while the function you are calling is already executing), it can leave
  616. the library in an inconsistent state. Note that the ANSI C standard points
  617. out that behavior of a signal handler is undefined if the signal handler calls
  618. any function other than signal() itself, so this is not a problem specific to
  619. Xlib and Xt; the POSIX specification mentions other functions which may be
  620. called safely but it may not be assumed that these functions are called by 
  621. Xlib or Xt functions.
  622.     You can work around the problem by setting a flag in the interrupt
  623. handler and later checking it with a work procedure or a timer event which
  624. has previously been added.
  625.  
  626.     Note: the article in The X Journal 1:4 and the example in O'Reilly 
  627. Volume 6 are in error.
  628.  
  629. [Thanks to Pete Ware (ware@cis.ohio-state.edu) and Donna Converse 
  630. (converse@expo.lcs.mit.EDU), 5/92]
  631.  
  632. ----------------------------------------------------------------------
  633. Subject: 129)  What are these "Xlib sequence lost" errors?
  634.  
  635.     You may see these errors if you issue Xlib requests from an Xlib error 
  636. handler, or, more likely, if you make calls which generate X requests to Xt or 
  637. Xlib from a signal handler, which you shouldn't be doing in any case. 
  638.  
  639. ----------------------------------------------------------------------
  640. Subject: 130)  How can my Xt program handle socket, pipe, or file input?
  641.  
  642.     It's very common to need to write an Xt program that can accept input 
  643. both from a user via the X connection and from some other file descriptor, but 
  644. which operates efficiently and without blocking on either the X connection or 
  645. the other file descriptor.
  646.     A solution is use XtAppAddInput(). After you open your file descriptor, 
  647. use XtAppAddInput() to register an input handler. The input handler will be 
  648. called every time there is something on the file descriptor requiring your 
  649. program's attention. Write the input handler like you would any other Xt 
  650. callback, so it does its work quickly and returns.  It is important to use only 
  651. non-blocking I/O system calls in your input handlers.
  652.     Most input handlers read the file descriptor, although you can have an 
  653. input handler write or handle exception conditions if you wish.
  654.     Be careful when you register an input handler to read from a disk file.
  655. You will find that the function is called even when there isn't input pending.
  656. XtAppAddInput() is actually working as it is supposed to. The input handler is 
  657. called whenever the file descriptor is READY to be read, not only when there is
  658. new data to be read. A disk file (unlike a pipe or socket) is almost always 
  659. ready to be read, however, if only because you can spin back to the beginning
  660. and read data you've read before.  The result is that your function will almost
  661. always be called every time around XtAppMainLoop(). There is a way to get the 
  662. type of interaction you are expecting; add this line to the beginning of your 
  663. function to test whether there is new data:
  664.          if (ioctl(fd, FIONREAD, &n) == -1 || n == 0) return;
  665. But, because this is called frequently, your application is effectively in a 
  666. busy-wait; you may be better off not using XtAppAddInput() and instead setting 
  667. a timer and in the timer procedure checking the file for input.
  668.  
  669. [courtesy Dan Heller (argv@ora.com), 8/90; mouse@larry.mcrcim.mcgill.edu 5/91;
  670. Ollie Jones (oj@pictel.com) 6/92]
  671.  
  672. ----------------------------------------------------------------------
  673. Subject: 131)  How do I simulate a button press/release event for a widget?
  674.  
  675.     You can do this using XSendEvent(); it's likely that you're not setting
  676. the window field in the event, which Xt needs in order to match to the widget
  677. which should receive the event.
  678.      If you're sending events to your own application, then you can use 
  679. XtDispatchEvent() instead. This is more efficient than XSendEvent() in that you
  680. avoid a round-trip to the server.
  681.     Depending on how well the widget was written, you may be able to call
  682. its action procedures in order to get the effects you want.
  683.  
  684. [courtesy Mark A. Horstman (mh2620@sarek.sbc.com), 11/90]
  685.  
  686. ----------------------------------------------------------------------
  687. Subject: 132)  Why doesn't anything appear when I run this simple program?
  688.  
  689. > ...
  690. > the_window = XCreateSimpleWindow(the_display,
  691. >      root_window,size_hints.x,size_hints.y,
  692. >      size_hints.width,size_hints.height,BORDER_WIDTH,
  693. >      BlackPixel(the_display,the_screen),
  694. >      WhitePixel(the_display,the_screen));
  695. > ...
  696. > XSelectInput(the_display,the_window,ExposureMask|ButtonPressMask|
  697. >     ButtonReleaseMask);
  698. > XMapWindow(the_display,the_window);
  699. > ...
  700. > XDrawLine(the_display,the_window,the_GC,5,5,100,100);
  701. > ...
  702.  
  703.     You are right to map the window before drawing into it. However, the 
  704. window is not ready to be drawn into until it actually appears on the screen --
  705. until your application receives an Expose event. Drawing done before that will 
  706. generally not appear. You'll see code like this in many programs; this code 
  707. would appear after window was created and mapped:
  708.   while (!done)
  709.     {
  710.       XNextEvent(the_display,&the_event);
  711.       switch (the_event.type) {
  712.     case Expose:     /* On expose events, redraw */
  713.         XDrawLine(the_display,the_window,the_GC,5,5,100,100);
  714.         break;
  715.     ...
  716.     }
  717.     }
  718.  
  719.     Note that there is a second problem: some Xlib implementations don't 
  720. set up the default graphics context to have correct foreground/background 
  721. colors, so this program could previously include this code:
  722.   ...
  723.   the_GC_values.foreground=BlackPixel(the_display,the_screen);    /* e.g. */
  724.   the_GC_values.background=WhitePixel(the_display,the_screen);    /* e.g. */
  725.   the_GC = XCreateGC(the_display,the_window,
  726.                 GCForeground|GCBackground,&the_GC_values);
  727.   ...
  728.  
  729. Note: the code uses BlackPixel and WhitePixel to avoid assuming that 1 is 
  730. black and 0 is white or vice-versa.  The relationship between pixels 0 and 1 
  731. and the colors black and white is implementation-dependent.  They may be 
  732. reversed, or they may not even correspond to black and white at all.
  733.  
  734. Also note that actually using BlackPixel and WhitePixel is usually the wrong 
  735. thing to do in a finished program, as it ignores the user's preference for 
  736. foreground and background.
  737.  
  738. And also note that you can run into the same situation in an Xt-based program
  739. if you draw into the XtWindow(w) right after it has been realized; it may
  740. not yet have appeared.
  741.  
  742. ----------------------------------------------------------------------
  743. Subject: 133)  What is the difference between a Screen and a screen?
  744.  
  745.     The 'Screen' is an Xlib structure which includes the information about
  746. one of the monitors or virtual monitors which a single X display supports. A 
  747. server can support several independent screens. They are numbered unix:0.0,
  748. unix:0.1, unix:0.2, etc; the 'screen' or 'screen_number' is the second digit --
  749. the 0, 1, 2 which can be thought of as an index into the array of available 
  750. Screens on this particular Display connection.
  751.     The macros which you can use to obtain information about the particular
  752. Screen on which your application is running typically have two forms -- one
  753. which takes a Screen and one with takes both the Display and the screen_number.
  754.     In Xt-based programs, you typically use XtScreen(widget) to determine 
  755. the Screen on which your application is running, if it uses a single screen.
  756.     (Part of the confusion may arise from the fact that some of the macros
  757. which return characteristics of the Screen have "Display" in the names -- 
  758. XDisplayWidth, XDisplayHeight, etc.)
  759.     
  760. ----------------------------------------------------------------------
  761. Subject: 134)  Can I use C++ with X11? Motif? XView?
  762.     
  763.     The X11R4/5 header files are compatible with C++. The Motif 1.1 header 
  764. files are usable as is inside extern "C" {...}. However, the definition of
  765. String in Intrinsic.h can conflict with the libg++ or other String class and
  766. needs to be worked around.
  767.  
  768.     Some other projects which can help:
  769.     WWL, a set of C++ classes by Jean-Daniel Fekete to wrap X Toolkit 
  770. widgets, available via anonymous FTP from export.lcs.mit.edu as 
  771. contrib/WWL-1.2.tar.Z [7/92] or lri.lri.fr (129.175.15.1) as pub/WWL-1.2.tar.Z.
  772. It works by building a set of C++ classes in parallel to the class tree of the 
  773. widgets.
  774.     The C++ InterViews toolkit is obtainable via anonymous FTP from 
  775. interviews.stanford.edu. InterViews uses a box/glue model similar to that of 
  776. TeX for constructing user interfaces and supports multiple looks on the user 
  777. interfaces. Some of its sample applications include a WYSIWIG document editor 
  778. (doc), a MacDraw-like drawing program (idraw) and an interface builder (ibuild).
  779.     THINGS,  a class library written at the Rome Air Force Base by the 
  780. Strategic Air Command, available as freeware on archive sites.
  781.  
  782.     Motif++ is a public-domain library that defines C++ class wrappers for
  783. Motif 1.1; it adds an "application" class for, e.g., initializing X, and also
  784. integrates WCL and the Xbae widget set. This work was developed by Ronald van 
  785. Loon <rvloon@cv.ruu.nl> based on X++, a set of bindings done by the University 
  786. of Lowell Graphics Research Laboratory. The current sources are available from 
  787. decuac.dec.com (192.5.214.1) as /pub/X11/motif++.21.jul.92.tar.Z.
  788.     
  789.     The source code examples for Doug Young's "Object-Oriented Programming 
  790. with C++ and OSF/Motif" [ISBN 0-13-630252-1] do not include "widget wrappers" 
  791. but do include a set of classes that encapsulates higher-level facilities 
  792. commonly needed by Motif- or other Xt-based applications; check export in
  793. ~ftp/contrib/young.c++.tar.Z.
  794.     Rogue Wave offers "View.h++" for C++ programmers using Motif; info:
  795. 1-800-487-3217 or +1 503 754 2311.
  796.     A product called "Commonview" by Glockenspiel Ltd, Ireland (??) 
  797. apparently is a C++-based toolkit for multiple window systems, including PM,
  798. Windows, and X/Motif.
  799.     Xv++ is sold by Qualix (415-572-0200; fax -1300); it implements an 
  800. interface from the GIL files that Sun's OpenWindows Developers Guide 3.0 
  801. produces to Xview wrapper classes in C++.
  802.  
  803.     UIT is a set of C++ classes embedding the XView toolkit; it is intended
  804. for use with Sun's OpenWindows Developers Guide 3.0 builder tool. Sources are 
  805. on export.mit.edu.au as UIT.tar.Z. Version 2 was released 5/28/92.
  806.     
  807.     Also of likely use is ObjectCenter (Saber-C++). And a reasonable
  808. alternative to all of the above is ParcPlace's (formerly Solbourne's) Object 
  809. Interface.
  810.  
  811. [Thanks to Douglas S. Rand (dsrand@mitre.org) and George Wu (gwu@tcs.com);2/91]
  812.  
  813. ----------------------------------------------------------------------
  814. Subject: 135)  Where can I obtain alternate language bindings to X?
  815.  
  816.     Versions of the CLX Lisp bindings are part of the X11 core source 
  817. distributions. A version of CLX is on the R5 tape [10/91]; version 5.0.2 [9/92]
  818. is on export.lcs.mit.edu in /contrib/CLX.R5.02.tar.Z.
  819.  
  820.     The SAIC Ada-X11 bindings are through anonymous ftp in /pub from
  821. stars.rosslyn.unisys.com (128.126.164.2). 
  822.     There is an X/Ada study team sponsored by NASA JSC, which apparently is
  823. working out bindings. Information: xada@ghg.hou.tx.us.
  824.     GNU SmallTalk has a beta native SmallTalk binding to X called STIX (by
  825. Steven.Byrne@Eng.Sun.COM). It is still in its beginning stages, and 
  826. documentation is sparse outside the SmallTalk code itself. The sources are 
  827. available as /pub/gnu/smalltalk-1.1.1.tar.Z on prep.ai.mit.edu (18.71.0.38) or 
  828. ugle.unit.no (129.241.1.97).
  829.     Prolog bindings (called "XWIP") written by Ted Kim at UCLA while
  830. supported in part by DARPA are available by anonymous FTP from
  831. export.lcs.mit.edu:contrib/xwip.tar.Z or ftp.cs.ucla.edu:pub/xwip.tar.Z.
  832. These prolog language bindings depend on having a Quintus-type foreign function
  833. interface in your prolog. The developer has gotten it to work with Quintus and 
  834. SICStus prolog. Inquiries should go to xwip@cs.ucla.edu. [3/90]
  835.     Scheme bindings to Xlib, OSF/Motif, and Xaw are part of the Elk
  836. distribution; version 1.5a on export obsoletes the version on the R5 contrib
  837. tape. 
  838.     x-scm, a bolt-on accessory for Aubrey Jaffer's "scm" Scheme interpreter
  839. that provides an interface to Xlib, Motif, and OpenLook, is now available via 
  840. FTP from altdorf.ai.mit.edu:archive/scm/xscm1.05.tar.Z and 
  841. nexus.yorku.ca:pub/scheme/new/xscm1.05.tar.Z.
  842.  
  843.     Ada bindings to Motif, explicitly, will eventually be made available by
  844. the Jet Propulsion Laboratories, probably through the normal electronic
  845. means.  Advance information can be obtained from dsouleles@dsfvax.jpl.nasa.gov,
  846. who may respond as time permits.
  847.     SA-Motif is a complete binding to X Window and Motif for the Ada; it
  848. is based in part upon the SAIC/Unisys bindings. SA-Motif is available on the 
  849. Sun3 and Sun4. Info: Systems Engineering Research Corporation, 2348 Leghorn 
  850. Street, #202/Mountain View, CA 94043/1-800-Ada-SERC (well!serc@apple.com).
  851.     Also: the MIT Consortium, although not involved in producing Ada
  852. bindings for X, maintains a partial listing of people involved in X and Ada;
  853. information is available from Donna Converse, converse@expo.lcs.mit.edu.
  854.  
  855. ----------------------------------------------------------------------
  856. Subject: 136)  Can XGetWindowAttributes get a window's background pixel/pixmap?
  857.  
  858.     No.  Once set, the background pixel or pixmap of a window cannot be 
  859. re-read by clients.  The reason for this is that a client can create a pixmap,
  860. set it to be the background pixmap of a window, and then free the pixmap. The 
  861. window keeps this background, but the pixmap itself is destroyed.  If you're 
  862. sure a window has a background pixel (not a pixmap), you can use XClearArea() 
  863. to clear a region to the background color and then use XGetImage() to read 
  864. back that pixel.  However, this action alters the contents of the window, and 
  865. it suffers from race conditions with exposures. [courtesy Dave Lemke of NCD 
  866. and Stuart Marks of Sun]
  867.  
  868.     Note that the same applies to the border pixel/pixmap. This is a 
  869. (mis)feature of the protocol which allows the server is free to manipulate the
  870. pixel/pixmap however it wants.  By not requiring the server to keep the 
  871. original pixel or pixmap, some (potentially a lot of) space can be saved. 
  872. [courtesy Jim Fulton, MIT X Consortium]
  873.  
  874. ----------------------------------------------------------------------
  875. Subject: 137)  How do I create a transparent window?
  876.     
  877.     A completely transparent window is easy to get -- use an InputOnly
  878. window. In order to create a window which is *mostly* transparent, you have
  879. several choices:
  880.     - the SHAPE extension first released with X11R4 offers an easy way to
  881. make non-rectangular windows, so you can set the shape of the window to fit the
  882. areas where the window should be nontransparent; however, not all servers 
  883. support the extension.
  884.     - a machine-specific method of implementing transparent windows for
  885. particular servers is to use an overlay plane supported by the hardware.  Note 
  886. that there is no X notion of a "transparent color index".
  887.     - a generally portable solution is to use a large number of tiny 
  888. windows, but this makes operating on the application as a unit difficult.
  889.     - a final answer is to consider whether you really need a transparent
  890. window or if you would be satisfied with being able to overlay your application
  891. window with information; if so, you can draw into separate bitplanes in colors
  892. that will appear properly.
  893.  
  894. [thanks to der Mouse, mouse@lightning.McRCIM.McGill.EDU, 3/92; see also
  895. The X Journal 1:4 for a more complete answer, including code samples for this
  896. last option]
  897.  
  898. ----------------------------------------------------------------------
  899. Subject: 138)  Why doesn't GXxor produce mathematically-correct color values?
  900.  
  901.     When using GXxor you may expect that drawing with a value of black on a
  902. background of black, for example, should produce white. However, the drawing
  903. operation does not work on RGB values but on colormap indices. The color that
  904. the resulting colormap index actually points to is undefined and visually
  905. random unless you have actually filled it in yourself. [On many X servers Black
  906. and White often 0/1 or 1/0; programs taking advantage of this mathematical
  907. coincidence will break.]
  908.     If you want to be combining colors with GXxor, then you should be 
  909. allocating a number of your own color cells and filling them with your chosen
  910. pre-computed values.
  911.     If you want to use GXxor simply to switch between two colors, then you 
  912. can take the shortcut of setting the background color in the GC (graphics 
  913. context) to 0 and the foreground color to a value such that when it draws over 
  914. red, say, the result is blue, and when it draws over blue the result is red. 
  915. This foreground value is itself the XOR of the colormap indices of red and 
  916. blue.
  917.  
  918. [Thanks to Chris Flatters (cflatter@zia.aoc.nrao.EDU) and Ken Whaley 
  919. (whaley@spectre.pa.dec.com), 2/91]
  920.  
  921. ----------------------------------------------------------------------
  922. Subject: 139)  Why does every color I allocate show up as black?
  923.  
  924.     Make sure you're using 16 bits and not 8.  The red, green, and blue 
  925. fields of an XColor structure are scaled so that 0 is nothing and 65535 is 
  926. full-blast. If you forget to scale (using, for example, 0-255 for each color) 
  927. the XAllocColor function will perform correctly but the resulting color is 
  928. usually black. 
  929.  
  930. [Thanks to Paul Asente, asente@adobe.com, 7/91]
  931.  
  932. ----------------------------------------------------------------------
  933. Subject: 140)  Why can't my program get a standard colormap?
  934. I have an image-processing program which uses XGetRGBColormap() to get the 
  935. standard colormap, but it doesn't work. 
  936.  
  937.     XGetRGBColormap() when used with the property XA_RGB_DEFAULT_MAP does 
  938. not create a standard colormap -- it just returns one if one already exists.
  939. Use xstdcmap or do what it does in order to create the standard colormap first.
  940.  
  941. [1/91; from der Mouse (mouse@larry.mcrcim.mcgill.edu)]
  942.  
  943. ----------------------------------------------------------------------
  944. Subject: 141)  Why does the pixmap I copy to the screen show up as garbage? 
  945.  
  946.     The initial contents of pixmaps are undefined.  This means that most
  947. servers will allocate the memory and leave around whatever happens to be there 
  948. -- which is usually garbage.  You probably want to clear the pixmap first using
  949. XFillRectangle() with a function of GXcopy and a foreground pixel of whatever 
  950. color you want as your background (or 0L if you are using the pixmap as a 
  951. mask). [courtesy Dave Lemke of NCD and Stuart Marks of Sun]
  952.  
  953. ----------------------------------------------------------------------
  954. Subject: 142)  How do I check whether a window ID is valid?
  955. My program has the ID of a window on a remote display. I want to check whether
  956. the window exists before doing anything with it.
  957.  
  958.     Because X is asynchronous, there isn't a guarantee that the window 
  959. would still exist between the time that you got the ID and the time you sent an
  960. event to the window or otherwise manipulated it. What you should do is send the
  961. event without checking, but install an error handler to catch any BadWindow 
  962. errors, which would indicate that the window no longer exists. This scheme will
  963. work except on the [rare] occasion that the original window has been destroyed 
  964. and its ID reallocated to another window.
  965.  
  966. [courtesy Ken Lee (klee@wsl.dec.com), 4/90]
  967.  
  968. ----------------------------------------------------------------------
  969. Subject: 143)  Can I have two applications draw to the same window?
  970.  
  971.     Yes. The X server assigns IDs to windows and other resources (actually,
  972. the server assigns some bits, the client others), and any application that 
  973. knows the ID can manipulate the resource [almost any X server resource, except
  974. for GCs and private color cells, can be shared].
  975.     The problem you face is how to disseminate the window ID to multiple 
  976. applications. A simple way to handle this (and which solves the problem of the
  977. applications' running on different machines) is in the first application to 
  978. create a specially-named property on the root-window and put the window ID into 
  979. it. The second application then retrieves the property, whose name it also
  980. knows, and then can draw whatever it wants into the window.
  981.     [Note: this scheme works iff there is only one instance of the first
  982. application running, and the scheme is subject to the limitations mentioned
  983. in the Question about using window IDs on remote displays.]
  984.     Note also that you will still need to coordinate any higher-level 
  985. cooperation among your applications. 
  986.     Note also that two processes can share a window but should not try to 
  987. use the same server connection. If one process is a child of the other, it 
  988. should close down the connection to the server and open its own connection.
  989.  
  990. [mostly courtesy Phil Karlton (karlton@wpd.sgi.com) 6/90]
  991.  
  992. ----------------------------------------------------------------------
  993. Subject: 144)  Why can't my program work with tvtwm or swm?
  994.  
  995.     A number of applications, including xwd, xwininfo, and xsetroot, do not
  996. handle the virtual root window which tvtwm and swm use; they typically return 
  997. the wrong child of root. A general solution is to add this code or to use it in
  998. your own application where you would normally use RootWindow(dpy,screen):
  999.  
  1000. /* Function Name: GetVRoot
  1001.  * Description: Gets the root window, even if it's a virtual root
  1002.  * Arguments: the display and the screen
  1003.  * Returns: the root window for the client
  1004.  */
  1005. #include <X11/Xatom.h>
  1006. Window GetVRoot(dpy, scr)
  1007. Display        *dpy;
  1008. int             scr;
  1009. {
  1010. Window          rootReturn, parentReturn, *children;
  1011. unsigned int    numChildren;
  1012. Window          root = RootWindow(dpy, scr);
  1013. Atom            __SWM_VROOT = None;
  1014. int             i;
  1015.  
  1016.   __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
  1017.   XQueryTree(dpy, root, &rootReturn, &parentReturn, &children, &numChildren);
  1018.   for (i = 0; i < numChildren; i++) {
  1019.     Atom            actual_type;
  1020.     int             actual_format;
  1021.     long            nitems, bytesafter;
  1022.     Window         *newRoot = NULL;
  1023.  
  1024.     if (XGetWindowProperty(dpy, children[i], __SWM_VROOT, 0, 1,
  1025.         False, XA_WINDOW, &actual_type, &actual_format, &nitems,
  1026.             &bytesafter, (unsigned char **) &newRoot) == Success && newRoot) {
  1027.             root = *newRoot;
  1028.             break;
  1029.         }
  1030.     }
  1031.  
  1032.     return root;
  1033. }
  1034.  
  1035. [courtesy David Elliott (dce@smsc.sony.com). Similar code is in ssetroot, a
  1036. version of xsetroot distributed with tvtwm. 2/91]
  1037.  
  1038. A header file by Andreas Stolcke of ICSI on export.lcs.mit.edu:contrib/vroot.h 
  1039. functions similarly by providing macros for RootWindow and DefaultRootWindow;
  1040. code can include this header file first to run properly in the presence of a
  1041. virtual desktop.
  1042.     
  1043. ----------------------------------------------------------------------
  1044. Subject: 145)  How do I keep a window from being resized by the user?
  1045.  
  1046.     Resizing the window is done through the window manager; window managers
  1047. can pay attention to the size hints your application places on the window, but 
  1048. there is no guarantee that the window manager will listen. You can try setting 
  1049. the minimum and maximum size hints to your target size and hope for the best. 
  1050. [1/91]
  1051.  
  1052. ----------------------------------------------------------------------
  1053. Subject: 146)  How do I keep a window in the foreground at all times?
  1054.  
  1055.     It's rather antisocial for an application to constantly raise itself
  1056. [e.g. by tracking VisibilityNotify events] so that it isn't overlapped -- 
  1057. imagine the conflict between two such programs running.  
  1058.     The only sure way to have your window appear on the top of the stack
  1059. is to make the window override-redirect; this means that you are temporarily
  1060. assuming window-management duties while the window is up, so you want to do 
  1061. this infrequently and then only for short periods of time (e.g. for popup 
  1062. menus or other short parameter-setting windows).
  1063.  
  1064. [thanks to der Mouse (mouse@larry.mcrcim.mcgill.edu); 7/92]
  1065.  
  1066. ----------------------------------------------------------------------
  1067. Subject: 147)  How do I make text and bitmaps blink in X?
  1068.  
  1069.     There is no easy way.  Unless you're willing to depend on some sort of
  1070. extension (as yet non-existent), you have to arrange for the blinking yourself,
  1071. either by redrawing the contents periodically or, if possible, by playing games
  1072. with the colormap and changing the color of the contents.
  1073.  
  1074. [Thanks to mouse@larry.mcrcim.mcgill.edu (der Mouse), 7/91]
  1075.  
  1076. ----------------------------------------------------------------------
  1077. Subject: 148)  How do I render rotated text?
  1078.     
  1079.     Xlib intentionally does not provide such sophisticated graphics 
  1080. capabilities, leaving them up to server-extensions or clients-side graphics
  1081. libraries.
  1082.     Your only choice, if you want to stay within the core X protocol, is to
  1083. render the text into a pixmap, read it back via XGetImage(), rotate it "by 
  1084. hand" with whatever matrices you want, and put it back to the server via 
  1085. XPutImage(); more specifically:
  1086.     1) create a bitmap B and write your text to it.
  1087.     2) create an XYBitmap image I from B (via XGetImage).
  1088.     3) create an XYBitmap Image I2 big enough to handle the transformation.
  1089.     4) for each x,y in I2, I2(x,y) = I(a,b) where 
  1090.         a = x * cos(theta) - y * sin(theta)
  1091.         b = x * sin(theta) + y * cos(theta)
  1092.     5) render I2
  1093.     Note that you should be careful how you implement this not to lose
  1094. bits; an algorithm based on shear transformations may in fact be better.
  1095.     The high-level server-extensions and graphics packages available for X 
  1096. also permit rendering of rotated text: Display PostScript, PEX, PHiGS, and GKS,
  1097. although most are not capable of arbitrary rotation and probably do not use the
  1098. same fonts that would be found on a printer.
  1099.     In addition, if you have enough access to the server to install a font
  1100. on it, you can create a font which consists of letters rotated at some
  1101. predefined angle. Your application can then itself figure out placement of each
  1102. glyph.
  1103.  
  1104. [courtesy der Mouse (mouse@larry.mcrcim.mcgill.edu), Eric Taylor 
  1105. (etaylor@wilkins.bmc.tmc.edu), and Ken Lee (klee@wsl.dec.com), 11/90;
  1106. Liam Quin (lee@sq.com), 12/90]
  1107.  
  1108.     InterViews (C++ UI toolkit, in the X contrib software) has support for
  1109. rendering rotated fonts in X.  It could be one source of example code.
  1110. [Brian R. Smith (brsmith@cs.umn.edu), 3/91]
  1111.     Another possibility is to use the Hershey Fonts; they are 
  1112. stroke-rendered and can be used by X by converting them into XDrawLine 
  1113. requests. [eric@pencom.com, 10/91]
  1114.  
  1115.     The xrotfont program by Alan Richardson (mppa3@syma.sussex.ac.uk) 
  1116. (posted to comp.sources.x July 14 1992) paints a rotated font by implementing 
  1117. the method above and by using an outline (Hershey) font.
  1118.  
  1119.     O'Reilly's X Resource Volume 3 includes information from HP about
  1120. modifications to the X fonts server which provide for rotated and scaled text.
  1121.  
  1122. ----------------------------------------------------------------------
  1123. Subject: 149)  What is the X Registry? (How do I reserve names?)
  1124.  
  1125.     There are places in the X Toolkit, in applications, and in the X
  1126. protocol that define and use string names. The context is such that conflicts
  1127. are possible if different components use the same name for different things.
  1128.     The MIT X Consortium maintains a registry of names in these domains:
  1129. orgainization names, selection names, selection targets, resource types,
  1130. application classes, and class extension record types; and several others.
  1131.     The list as of 7/91 is in the directory mit/doc/Registry on the R5 
  1132. tape; it is also available by sending "send docs registry" to the xstuff mail
  1133. server.
  1134.     To register names (first come, first served) or to ask questions send 
  1135. to xregistry@expo.lcs.mit.edu; be sure to include a postal address for
  1136. confirmation.
  1137.  
  1138. [11/90; condensed from Asente/Swick Appendix H]
  1139. ----------------------------------------------------------------------
  1140.  
  1141.  
  1142. David B. Lewis                     faq%craft@uunet.uu.net
  1143.  
  1144.         "Just the FAQs, ma'am." -- Joe Friday 
  1145. -- 
  1146. David B. Lewis        Temporarily at but not speaking for Visual, Inc.
  1147. day: dbl@visual.com    evening: david%craft@uunet.uu.net
  1148.