home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / windows / x / 19258 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  54.7 KB

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