home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / internet / news0498.zip / NEWS0498.TXT
Text File  |  1993-05-14  |  44KB  |  891 lines

  1. Archive-name: x-faq/part5
  2. Last-modified: 1993/05/11
  3.  
  4. ----------------------------------------------------------------------
  5. Subject: 119)  I'm writing a widget and can't use a float as a resource value.
  6.  
  7. Float resources are not portable; the size of the value may be larger than
  8. the size of an XtPointer. Try using a pointer to a float instead; the Xaw
  9. Scrollbar float resources are handled in this way. 
  10.  
  11. ----------------------------------------------------------------------
  12. Subject: 120)  Is this a memory leak in the X11R4 XtDestroyWidget()?!
  13.  
  14. Yes. This is the "unofficial" fix-19 for the X11R4 Destroy.c:
  15.  
  16. *** Destroy.c.1.37    Thu Jul 11 15:41:25 1991
  17. --- lib/Xt/Destroy.c    Thu Jul 11 15:42:23 1991
  18. ***************
  19. *** 1,4 ****
  20. --- 1,5 ----
  21.   /* $XConsortium: Destroy.c,v 1.37 90/09/28 10:21:32 swick Exp $ */
  22. + /* Plus unofficial patches in revisions 1.40 and 1.41 */
  23.   
  24.   /***********************************************************
  25.   Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  26. ***************
  27. *** 221,239 ****
  28.        */
  29.   
  30.       int i = 0;
  31. !     DestroyRec* dr = app->destroy_list;
  32.       while (i < app->destroy_count) {
  33.       if (dr->dispatch_level >= dispatch_level)  {
  34.           Widget w = dr->widget;
  35.           if (--app->destroy_count)
  36.           bcopy( (char*)(dr+1), (char*)dr,
  37. !                app->destroy_count*sizeof(DestroyRec)
  38.                 );
  39.           XtPhase2Destroy(w);
  40.       }
  41.       else {
  42.           i++;
  43. -         dr++;
  44.       }
  45.       }
  46.   }
  47. --- 222,245 ----
  48.        */
  49.   
  50.       int i = 0;
  51. !     DestroyRec* dr;
  52.       while (i < app->destroy_count) {
  53. +     /* XtPhase2Destroy can result in calls to XtDestroyWidget,
  54. +      * and these could cause app->destroy_list to be reallocated.
  55. +      */
  56. +     dr = app->destroy_list + i;
  57.       if (dr->dispatch_level >= dispatch_level)  {
  58.           Widget w = dr->widget;
  59.           if (--app->destroy_count)
  60.           bcopy( (char*)(dr+1), (char*)dr,
  61. !                (app->destroy_count - i) * sizeof(DestroyRec)
  62.                 );
  63.           XtPhase2Destroy(w);
  64.       }
  65.       else {
  66.           i++;
  67.       }
  68.       }
  69.   }
  70.  
  71. [from Donna Converse, converse@expo.lcs.mit.EDU]
  72.  
  73. ----------------------------------------------------------------------
  74. Subject: 121)  Are callbacks guaranteed to be called in the order registered?
  75.  
  76.     Although some books demonstrate that the current implementation of Xt
  77. happens to call callback procedures in the order in which they are registered, 
  78. the specification does not guarantee such a sequence, and supplemental 
  79. authoritative documents (i.e. the Asente/Swick volume) do say that the order is
  80. undefined.  Because the callback list can be manipulated by both the widget and
  81. the application, Xt cannot guarantee the order of execution.
  82.     In general, the callback procedures should be thought of as operating 
  83. independently of one another and should not depend on side-effects of other
  84. callbacks operating; if a seqence is needed, then the single callback to be 
  85. registered can explicitly call other functions necessary.
  86.  
  87. [4/92; thanks to converse@expo.lcs.mit.edu]
  88.  
  89. ----------------------------------------------------------------------
  90. Subject: 122)  Why doesn't XtDestroyWidget() actually destroy the widget?
  91.  
  92.     XtDestroyWidget() operates in two passes, in order to avoid leaving
  93. dangling data structures; the function-call marks the widget, which is not 
  94. actually destroyed until your program returns to its event-loop. 
  95.  
  96. ----------------------------------------------------------------------
  97. Subject: 123)  How do I query the user synchronously using Xt?
  98.     
  99.     It is possible to have code which looks like this trivial callback,
  100. which has a clear flow of control. The calls to AskUser() block until answer
  101. is set to one of the valid values. If it is not a "yes" answer, the code drops
  102. out of the callback and back to an event-processing loop: 
  103.  
  104.     void quit(Widget w, XtPointer client, XtPointer call)
  105.     {
  106.         int             answer;
  107.         answer = AskUser(w, "Really Quit?");
  108.         if (RET_YES == answer)
  109.             {
  110.             answer = AskUser(w, "Are You Really Positive?");
  111.             if (RET_YES == answer)
  112.                 exit(0);
  113.                 }
  114.     }
  115.  
  116.     A more realistic example might ask whether to create a file or whether 
  117. to overwrite it.
  118.     This is accomplished by entering a second event-processing loop and
  119. waiting until the user answers the question; the answer is returned to the
  120. calling function. That function AskUser() looks something like this, where the 
  121. Motif can be replaced with widget-set-specific code to create some sort of 
  122. dialog-box displaying the question string and buttons for "OK", "Cancel" and 
  123. "Help" or equivalents:
  124.  
  125.   int AskUser(w, string)
  126.         Widget          w;
  127.         char           *string;
  128.   {
  129.         int             answer=RET_NONE;    /* some not-used marker */
  130.         Widget          dialog;            /* could cache&carry, but ...*/
  131.         Arg             args[3];
  132.         int             n = 0;
  133.         XtAppContext    context;
  134.  
  135.         n=0;
  136.         XtSetArg(args[n], XmNmessageString, XmStringCreateLtoR(string,
  137.                 XmSTRING_DEFAULT_CHARSET)); n++;
  138.         XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); n++;
  139.         dialog = XmCreateQuestionDialog(XtParent(w), string, args, n);
  140.         XtAddCallback(dialog, XmNokCallback, response, &answer);
  141.         XtAddCallback(dialog, XmNcancelCallback, response, &answer);
  142.         XtAddCallback(dialog, XmNhelpCallback, response, &answer);
  143.         XtManageChild(dialog);
  144.  
  145.         context = XtWidgetToApplicationContext (w);
  146.         while (answer == RET_NONE || XtAppPending(context)) {
  147.                 XtAppProcessEvent (context, XtIMAll);
  148.         }
  149.         XtDestroyWidget(dialog);  /* blow away the dialog box and shell */
  150.         return answer;
  151.   }
  152.  
  153.     The dialog supports three buttons, which are set to call the same 
  154. function when tickled by the user.  The variable answer is set when the user 
  155. finally selects one of those choices:
  156.  
  157.   void response(w, client, call)
  158.         Widget          w;
  159.         XtPointer client;
  160.         XtPointer call;
  161.   {
  162.   int *answer = (int *) client;
  163.   XmAnyCallbackStruct *reason = (XmAnyCallbackStruct *) call;
  164.         switch (reason->reason) {
  165.         case XmCR_OK:
  166.                 *answer = RET_YES;    /* some #define value */
  167.                 break;
  168.         case XmCR_CANCEL:
  169.                 *answer = RET_NO; 
  170.         break;
  171.         case XmCR_HELP:
  172.                 *answer = RET_HELP;
  173.                 break;
  174.         default:
  175.                 return;
  176.         }
  177. }
  178.  
  179. and the code unwraps back to the point at which an answer was needed and
  180. continues from there.
  181.  
  182. [Thanks to Dan Heller (argv@sun.com); further code is in Dan's R3/contrib
  183. WidgetWrap library. 2/91]
  184.  
  185. ----------------------------------------------------------------------
  186. Subject: 124)  How do I determine the name of an existing widget?
  187. I have a widget ID and need to know what the name of that widget is.
  188.  
  189.     Users of R4 and later are best off using the XtName() function, which 
  190. will work on both widgets and non-widget objects.
  191.  
  192.     If you are still using R3, you can use this simple bit of code to do 
  193. what you want. Note that it depends on the widget's internal data structures 
  194. and is not necessarily portable to future versions of Xt, including R4.
  195.  
  196.     #include <X11/CoreP.h>
  197.     #include <X11/Xresource.h>
  198.     String XtName (widget)
  199.     Widget widget;    /* WILL work with non-widget objects */
  200.     {
  201.     return XrmNameToString(widget->core.xrm_name);
  202.     }
  203.  
  204. [7/90; modified with suggestion by Larry Rogers (larry@boris.webo.dg.com) 9/91]
  205.  
  206. ----------------------------------------------------------------------
  207. Subject: 125)  Why do I get a BadDrawable error drawing to XtWindow(widget)?
  208. I'm doing this in order to get a window into which I can do Xlib graphics
  209. within my Xt-based program:
  210.  
  211. > canvas = XtCreateManagedWidget ( ...,widgetClass,...) /* drawing area */
  212. > ...
  213. > window = XtWindow(canvas);    /* get the window associated with the widget */
  214. > ...
  215. > XDrawLine (...,window,...);    /* produces error */
  216.  
  217.     The window associated with the widget is created as a part of the 
  218. realization of the widget.  Using a window id of NULL ("no window") could 
  219. create the error that you describe.  It is necessary to call XtRealizeWidget() 
  220. before attempting to use the window associated with a widget. 
  221.     Note that the window will be created after the XtRealizeWidget() call, 
  222. but that the server may not have actually mapped it yet, so you should also 
  223. wait for an Expose event on the window before drawing into it.
  224.  
  225. ----------------------------------------------------------------------
  226. Subject: 126)  Why do I get a BadMatch error when calling XGetImage?
  227.  
  228. The BadMatch error can occur if the specified rectangle goes off the edge of 
  229. the screen. If you don't want to catch the error and deal with it, you can take
  230. the following steps to avoid the error:
  231.  
  232. 1) Make a pixmap the same size as the rectangle you want to capture.
  233. 2) Clear the pixmap to background using XFillRectangle.
  234. 3) Use XCopyArea to copy the window to the pixmap.
  235. 4) If you get a NoExpose event, the copy was clean. Use XGetImage to grab the
  236. image from the pixmap.
  237. 5) If you get one or more GraphicsExpose events, the copy wasn't clean, and 
  238. the x/y/width/height members of the GraphicsExpose event structures tell you 
  239. the parts of the pixmap which aren't good.
  240. 6) Get rid of the pixmap; it probably takes a lot of memory.
  241.  
  242. [10/92; thanks to Oliver Jones (oj@pictel.com)]
  243.  
  244. ----------------------------------------------------------------------
  245. Subject: 127)  How can my application tell if it is being run under X?
  246.  
  247.     A number of programs offer X modes but otherwise run in a straight
  248. character-only mode. The easiest way for an application to determine that it is
  249. running on an X display is to attempt to open a connection to the X server:
  250.     
  251.     display = XOpenDisplay(display_name);
  252.     if (display)
  253.         { do X stuff }
  254.     else
  255.         { do curses or something else }
  256. where display_name is either the string specified on the command-line following
  257. -display, by convention, or otherwise is (char*)NULL [in which case 
  258. XOpenDisplay uses the value of $DISPLAY, if set].
  259.  
  260. This is superior to simply checking for the existence a -display command-line 
  261. argument or checking for $DISPLAY set in the environment, neither of which is 
  262. adequate. [5/91]
  263.  
  264. ----------------------------------------------------------------------
  265. Subject: 128)  How do I make a "busy cursor" while my application is computing?
  266. Is it necessary to call XDefineCursor() for every window in my application?
  267.  
  268.     The easiest thing to do is to create a single InputOnly window that is 
  269. as large as the largest possible screen; make it a child of your toplevel 
  270. window and it will be clipped to that window, so it won't affect any other 
  271. application. (It needs to be as big as the largest possible screen in case the 
  272. user enlarges the window while it is busy or moves elsewhere within a virtual 
  273. desktop.) Substitute "toplevel" with your top-most widget here (similar code 
  274. should work for Xlib-only applications; just use your top Window):
  275.  
  276.      unsigned long valuemask;
  277.      XSetWindowAttributes attributes;
  278.  
  279.      /* Ignore device events while the busy cursor is displayed. */
  280.      valuemask = CWDontPropagate | CWCursor;
  281.      attributes.do_not_propagate_mask =  (KeyPressMask | KeyReleaseMask |
  282.          ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
  283.      attributes.cursor = XCreateFontCursor(XtDisplay(toplevel), XC_watch);
  284.  
  285.      /* The window will be as big as the display screen, and clipped by
  286.         its own parent window, so we never have to worry about resizing */
  287.      XCreateWindow(XtDisplay(toplevel), XtWindow(toplevel), 0, 0,
  288.          65535, 65535, (unsigned int) 0, 0, InputOnly,
  289.          CopyFromParent, valuemask, &attributes);
  290.  
  291. where the maximum size above could be replaced by the real size of the screen,
  292. particularly to avoid servers which have problems with windows larger than
  293. 32767.
  294.  
  295. When you want to use this busy cursor, map and raise this window; to go back to
  296. normal, unmap it. This will automatically keep you from getting extra mouse
  297. events; depending on precisely how the window manager works, it may or may not
  298. have a similar effect on keystrokes as well.
  299.  
  300. In addition, note also that most of the Xaw widgets support an XtNcursor 
  301. resource which can be temporarily reset, should you merely wish to change the
  302. cursor without blocking pointer events.
  303.  
  304. [thanks to Andrew Wason (aw@cellar.bae.bellcore.com), Dan Heller 
  305. (argv@sun.com), and mouse@larry.mcrcim.mcgill.edu; 11/90,5/91]
  306.  
  307. ----------------------------------------------------------------------
  308. Subject: 129)  How do I fork without hanging my parent X program?
  309.  
  310.     An X-based application which spawns off other Unix processes which 
  311. continue to run after it is closed typically does not vanish until all of its 
  312. children are terminated; the children inherit from the parent the open X 
  313. connection to the display. 
  314.     What you need to do is fork; then, immediately, in the child process, 
  315.         close (ConnectionNumber(XtDisplay(widget)));
  316. to close the file-descriptor in the display information. After this do your 
  317. exec. You will then be able to exit the parent.
  318.     Alternatively, before exec'ing make this call, which causes the file 
  319. descriptor to be closed on exec.
  320.         (void) fcntl(ConnectionNumber(XDisplay), F_SETFD, 1);
  321.  
  322. [Thanks to Janet Anstett (anstettj@tramp.Colorado.EDU), Gordon Freedman 
  323. (gjf00@duts.ccc.amdahl.com); 2/91. Greg Holmberg (holmberg@frame.com), 3/93.]
  324.  
  325. ----------------------------------------------------------------------
  326. Subject: 130)  Can I make Xt or Xlib calls from a signal handler?
  327.  
  328.     No. Xlib and Xt have no mutual exclusion for protecting critical 
  329. sections. If your signal handler makes such a call at the wrong time (which 
  330. might be while the function you are calling is already executing), it can leave
  331. the library in an inconsistent state. Note that the ANSI C standard points
  332. out that behavior of a signal handler is undefined if the signal handler calls
  333. any function other than signal() itself, so this is not a problem specific to
  334. Xlib and Xt; the POSIX specification mentions other functions which may be
  335. called safely but it may not be assumed that these functions are called by 
  336. Xlib or Xt functions.
  337.     You can work around the problem by setting a flag in the interrupt
  338. handler and later checking it with a work procedure or a timer event which
  339. has previously been added.
  340.  
  341.     Note: the article in The X Journal 1:4 and the example in O'Reilly 
  342. Volume 6 are in error.
  343.  
  344. [Thanks to Pete Ware (ware@cis.ohio-state.edu) and Donna Converse 
  345. (converse@expo.lcs.mit.EDU), 5/92]
  346.  
  347. ----------------------------------------------------------------------
  348. Subject: 131)  What are these "Xlib sequence lost" errors?
  349.  
  350.     You may see these errors if you issue Xlib requests from an Xlib error 
  351. handler, or, more likely, if you make calls which generate X requests to Xt or 
  352. Xlib from a signal handler, which you shouldn't be doing in any case. 
  353.  
  354. ----------------------------------------------------------------------
  355. Subject: 132)  How can my Xt program handle socket, pipe, or file input?
  356.  
  357.     It's very common to need to write an Xt program that can accept input 
  358. both from a user via the X connection and from some other file descriptor, but 
  359. which operates efficiently and without blocking on either the X connection or 
  360. the other file descriptor.
  361.     A solution is use XtAppAddInput(). After you open your file descriptor,
  362. use XtAppAddInput() to register an input handler. The input handler will be 
  363. called every time there is something on the file descriptor requiring your 
  364. program's attention. Write the input handler like you would any other Xt 
  365. callback, so it does its work quickly and returns.  It is important to use only
  366. non-blocking I/O system calls in your input handlers.
  367.     Most input handlers read the file descriptor, although you can have an 
  368. input handler write or handle exception conditions if you wish.
  369.     Be careful when you register an input handler to read from a disk file.
  370. You will find that the function is called even when there isn't input pending.
  371. XtAppAddInput() is actually working as it is supposed to. The input handler is 
  372. called whenever the file descriptor is READY to be read, not only when there is
  373. new data to be read. A disk file (unlike a pipe or socket) is almost always 
  374. ready to be read, however, if only because you can spin back to the beginning
  375. and read data you've read before.  The result is that your function will almost
  376. always be called every time around XtAppMainLoop(). There is a way to get the 
  377. type of interaction you are expecting; add this line to the beginning of your 
  378. function to test whether there is new data:
  379.          if (ioctl(fd, FIONREAD, &n) == -1 || n == 0) return;
  380. But, because this is called frequently, your application is effectively in a 
  381. busy-wait; you may be better off not using XtAppAddInput() and instead setting 
  382. a timer and in the timer procedure checking the file for input.
  383.  
  384. [courtesy Dan Heller (argv@ora.com), 8/90; mouse@larry.mcrcim.mcgill.edu 5/91;
  385. Ollie Jones (oj@pictel.com) 6/92]
  386.  
  387. ----------------------------------------------------------------------
  388. Subject: 133)  How do I simulate a button press/release event for a widget?
  389.  
  390.     You can do this using XSendEvent(); it's likely that you're not setting
  391. the window field in the event, which Xt needs in order to match to the widget
  392. which should receive the event.
  393.      If you're sending events to your own application, then you can use 
  394. XtDispatchEvent() instead. This is more efficient than XSendEvent() in that you
  395. avoid a round-trip to the server.
  396.     Depending on how well the widget was written, you may be able to call
  397. its action procedures in order to get the effects you want.
  398.  
  399. [courtesy Mark A. Horstman (mh2620@sarek.sbc.com), 11/90]
  400.  
  401. ----------------------------------------------------------------------
  402. Subject: 134)  Why doesn't anything appear when I run this simple program?
  403.  
  404. > ...
  405. > the_window = XCreateSimpleWindow(the_display,
  406. >      root_window,size_hints.x,size_hints.y,
  407. >      size_hints.width,size_hints.height,BORDER_WIDTH,
  408. >      BlackPixel(the_display,the_screen),
  409. >      WhitePixel(the_display,the_screen));
  410. > ...
  411. > XSelectInput(the_display,the_window,ExposureMask|ButtonPressMask|
  412. >     ButtonReleaseMask);
  413. > XMapWindow(the_display,the_window);
  414. > ...
  415. > XDrawLine(the_display,the_window,the_GC,5,5,100,100);
  416. > ...
  417.  
  418.     You are right to map the window before drawing into it. However, the 
  419. window is not ready to be drawn into until it actually appears on the screen --
  420. until your application receives an Expose event. Drawing done before that will 
  421. generally not appear. You'll see code like this in many programs; this code 
  422. would appear after window was created and mapped:
  423.   while (!done)
  424.     {
  425.       XNextEvent(the_display,&the_event);
  426.       switch (the_event.type) {
  427.     case Expose:     /* On expose events, redraw */
  428.         XDrawLine(the_display,the_window,the_GC,5,5,100,100);
  429.         break;
  430.     ...
  431.     }
  432.     }
  433.  
  434.     Note that there is a second problem: some Xlib implementations don't 
  435. set up the default graphics context to have correct foreground/background 
  436. colors, so this program could previously include this code:
  437.   ...
  438.   the_GC_values.foreground=BlackPixel(the_display,the_screen);    /* e.g. */
  439.   the_GC_values.background=WhitePixel(the_display,the_screen);    /* e.g. */
  440.   the_GC = XCreateGC(the_display,the_window,
  441.                 GCForeground|GCBackground,&the_GC_values);
  442.   ...
  443.  
  444. Note: the code uses BlackPixel and WhitePixel to avoid assuming that 1 is 
  445. black and 0 is white or vice-versa.  The relationship between pixels 0 and 1 
  446. and the colors black and white is implementation-dependent.  They may be 
  447. reversed, or they may not even correspond to black and white at all.
  448.  
  449. Also note that actually using BlackPixel and WhitePixel is usually the wrong 
  450. thing to do in a finished program, as it ignores the user's preference for 
  451. foreground and background.
  452.  
  453. And also note that you can run into the same situation in an Xt-based program
  454. if you draw into the XtWindow(w) right after it has been realized; it may
  455. not yet have appeared.
  456.  
  457. ----------------------------------------------------------------------
  458. Subject: 135)  What is the difference between a Screen and a screen?
  459.  
  460.     The 'Screen' is an Xlib structure which includes the information about
  461. one of the monitors or virtual monitors which a single X display supports. A 
  462. server can support several independent screens. They are numbered unix:0.0,
  463. unix:0.1, unix:0.2, etc; the 'screen' or 'screen_number' is the second digit --
  464. the 0, 1, 2 which can be thought of as an index into the array of available 
  465. Screens on this particular Display connection.
  466.     The macros which you can use to obtain information about the particular
  467. Screen on which your application is running typically have two forms -- one
  468. which takes a Screen and one with takes both the Display and the screen_number.
  469.     In Xt-based programs, you typically use XtScreen(widget) to determine 
  470. the Screen on which your application is running, if it uses a single screen.
  471.     (Part of the confusion may arise from the fact that some of the macros
  472. which return characteristics of the Screen have "Display" in the names -- 
  473. XDisplayWidth, XDisplayHeight, etc.)
  474.     
  475. ----------------------------------------------------------------------
  476. Subject: 136)! Can I use C++ with X11? Motif? XView?
  477.     
  478.     The X11R4/5 header files are compatible with C++. The Motif 1.1 header 
  479. files are usable as is inside extern "C" {...}. However, the definition of
  480. String in Intrinsic.h can conflict with the libg++ or other String class and
  481. needs to be worked around.
  482.  
  483.     Some other projects which can help:
  484.     WWL, a set of C++ classes by Jean-Daniel Fekete to wrap X Toolkit 
  485. widgets, available via anonymous FTP from export.lcs.mit.edu as 
  486. contrib/WWL-1.2.tar.Z [7/92] or lri.lri.fr (129.175.15.1) as pub/WWL-1.2.tar.Z.
  487. It works by building a set of C++ classes in parallel to the class tree of the 
  488. widgets.
  489.     The C++ InterViews toolkit is obtainable via anonymous FTP from 
  490. interviews.stanford.edu. InterViews uses a box/glue model similar to that of 
  491. TeX for constructing user interfaces and supports multiple looks on the user 
  492. interfaces. Some of its sample applications include a WYSIWIG document editor 
  493. (doc), a MacDraw-like drawing program (idraw) and an interface builder 
  494. (ibuild).
  495.     THINGS,  a class library written at the Rome Air Force Base by the 
  496. Strategic Air Command, available as freeware on archive sites.
  497.  
  498.     Motif++ is a public-domain library that defines C++ class wrappers for
  499. Motif 1.1; it adds an "application" class for, e.g., initializing X, and also
  500. integrates WCL and the Xbae widget set. This work was developed by Ronald van 
  501. Loon <rvloon@cv.ruu.nl> based on X++, a set of bindings done by the University 
  502. of Lowell Graphics Research Laboratory. The current sources are available from 
  503. decuac.dec.com (192.5.214.1) as /pub/X11/motif++.21.jul.92.tar.Z; there was
  504. a release 4/93 as well.
  505.     
  506.     The source code examples for Doug Young's "Object-Oriented Programming 
  507. with C++ and OSF/Motif" [ISBN 0-13-630252-1] do not include "widget wrappers" 
  508. but do include a set of classes that encapsulates higher-level facilities 
  509. commonly needed by Motif- or other Xt-based applications; check export in
  510. ~ftp/contrib/young.c++.tar.Z.
  511.     Rogue Wave offers "View.h++" for C++ programmers using Motif; info:
  512. 1-800-487-3217 or +1 503 754 2311.
  513.     A product called "Commonview" by Glockenspiel Ltd, Ireland (??) 
  514. apparently is a C++-based toolkit for multiple window systems, including PM,
  515. Windows, and X/Motif.
  516.     Xv++ is sold by Qualix (415-572-0200; fax -1300); it implements an 
  517. interface from the GIL files that Sun's OpenWindows Developers Guide 3.0 
  518. produces to Xview wrapper classes in C++.
  519.  
  520.     UIT is a set of C++ classes embedding the XView toolkit; it is intended
  521. for use with Sun's OpenWindows Developers Guide 3.0 builder tool. Sources are 
  522. on export.mit.edu.au as UIT.tar.Z. Version 2 was released 5/28/92.
  523.     
  524.     Also of likely use is ObjectCenter (Saber-C++). And a reasonable
  525. alternative to all of the above is ParcPlace's (formerly Solbourne's) Object 
  526. Interface.
  527.  
  528. [Thanks to Douglas S. Rand (dsrand@mitre.org) and George Wu (gwu@tcs.com);2/91]
  529.  
  530. ----------------------------------------------------------------------
  531. Subject: 137)  Where can I obtain alternate language bindings to X?
  532.  
  533.     Versions of the CLX Lisp bindings are part of the X11 core source 
  534. distributions. A version of CLX is on the R5 tape [10/91]; version 5.0.2 [9/92]
  535. is on export.lcs.mit.edu in /contrib/CLX.R5.02.tar.Z.
  536.  
  537.     The SAIC Ada-X11 bindings are through anonymous ftp in /pub from
  538. stars.rosslyn.unisys.com (128.126.164.2). 
  539.     There is an X/Ada study team sponsored by NASA JSC, which apparently is
  540. working out bindings. Information: xada@ghg.hou.tx.us.
  541.     GNU SmallTalk has a beta native SmallTalk binding to X called STIX (by
  542. Steven.Byrne@Eng.Sun.COM). It is still in its beginning stages, and 
  543. documentation is sparse outside the SmallTalk code itself. The sources are 
  544. available as /pub/gnu/smalltalk-1.1.1.tar.Z on prep.ai.mit.edu (18.71.0.38) or 
  545. ugle.unit.no (129.241.1.97).
  546.     Prolog bindings (called "XWIP") written by Ted Kim at UCLA while
  547. supported in part by DARPA are available by anonymous FTP from
  548. export.lcs.mit.edu:contrib/xwip.tar.Z or ftp.cs.ucla.edu:pub/xwip.tar.Z.
  549. These prolog language bindings depend on having a Quintus-type foreign function
  550. interface in your prolog. The developer has gotten it to work with Quintus and 
  551. SICStus prolog. Inquiries should go to xwip@cs.ucla.edu. [3/90]
  552.     Scheme bindings to Xlib, OSF/Motif, and Xaw are part of the Elk
  553. distribution; version 1.5a on export obsoletes the version on the R5 contrib
  554. tape. 
  555.     x-scm, a bolt-on accessory for Aubrey Jaffer's "scm" Scheme interpreter
  556. that provides an interface to Xlib, Motif, and OpenLook, is now available via 
  557. FTP from altdorf.ai.mit.edu:archive/scm/xscm1.05.tar.Z and 
  558. nexus.yorku.ca:pub/scheme/new/xscm1.05.tar.Z.
  559.  
  560.     Ada bindings to Motif, explicitly, will eventually be made available by
  561. the Jet Propulsion Laboratories, probably through the normal electronic
  562. means.  Advance information can be obtained from dsouleles@dsfvax.jpl.nasa.gov,
  563. who may respond as time permits.
  564.     AdaMotif is a complete binding to X and Motif for the Ada language, for
  565. many common systems; it is based in part upon the SAIC/Unisys bindings and also
  566. includes a UIL to Ada translator. Info: Systems Engineering Research 
  567. Corporation, 1-800-Ada-SERC (well!serc@apple.com).
  568.  
  569.     Also: the MIT Consortium, although not involved in producing Ada
  570. bindings for X, maintains a partial listing of people involved in X and Ada;
  571. information is available from Donna Converse, converse@expo.lcs.mit.edu.
  572.  
  573. ----------------------------------------------------------------------
  574. Subject: 138)  Can XGetWindowAttributes get a window's background pixel/pixmap?
  575.  
  576.     No.  Once set, the background pixel or pixmap of a window cannot be 
  577. re-read by clients.  The reason for this is that a client can create a pixmap,
  578. set it to be the background pixmap of a window, and then free the pixmap. The 
  579. window keeps this background, but the pixmap itself is destroyed.  If you're 
  580. sure a window has a background pixel (not a pixmap), you can use XClearArea() 
  581. to clear a region to the background color and then use XGetImage() to read 
  582. back that pixel.  However, this action alters the contents of the window, and 
  583. it suffers from race conditions with exposures. [courtesy Dave Lemke of NCD 
  584. and Stuart Marks of Sun]
  585.  
  586.     Note that the same applies to the border pixel/pixmap. This is a 
  587. (mis)feature of the protocol which allows the server is free to manipulate the
  588. pixel/pixmap however it wants.  By not requiring the server to keep the 
  589. original pixel or pixmap, some (potentially a lot of) space can be saved. 
  590. [courtesy Jim Fulton, MIT X Consortium]
  591.  
  592. ----------------------------------------------------------------------
  593. Subject: 139)  How do I create a transparent window?
  594.     
  595.     A completely transparent window is easy to get -- use an InputOnly
  596. window. In order to create a window which is *mostly* transparent, you have
  597. several choices:
  598.     - the SHAPE extension first released with X11R4 offers an easy way to
  599. make non-rectangular windows, so you can set the shape of the window to fit the
  600. areas where the window should be nontransparent; however, not all servers 
  601. support the extension.
  602.     - a machine-specific method of implementing transparent windows for
  603. particular servers is to use an overlay plane supported by the hardware.  Note 
  604. that there is no X notion of a "transparent color index".
  605.     - a generally portable solution is to use a large number of tiny 
  606. windows, but this makes operating on the application as a unit difficult.
  607.     - a final answer is to consider whether you really need a transparent
  608. window or if you would be satisfied with being able to overlay your application
  609. window with information; if so, you can draw into separate bitplanes in colors
  610. that will appear properly.
  611.  
  612. [thanks to der Mouse, mouse@lightning.McRCIM.McGill.EDU, 3/92; see also
  613. The X Journal 1:4 for a more complete answer, including code samples for this
  614. last option]
  615.  
  616. ----------------------------------------------------------------------
  617. Subject: 140)  Why doesn't GXxor produce mathematically-correct color values?
  618.  
  619.     When using GXxor you may expect that drawing with a value of black on a
  620. background of black, for example, should produce white. However, the drawing
  621. operation does not work on RGB values but on colormap indices. The color that
  622. the resulting colormap index actually points to is undefined and visually
  623. random unless you have actually filled it in yourself. [On many X servers Black
  624. and White often 0/1 or 1/0; programs taking advantage of this mathematical
  625. coincidence will break.]
  626.     If you want to be combining colors with GXxor, then you should be 
  627. allocating a number of your own color cells and filling them with your chosen
  628. pre-computed values.
  629.     If you want to use GXxor simply to switch between two colors, then you 
  630. can take the shortcut of setting the background color in the GC (graphics 
  631. context) to 0 and the foreground color to a value such that when it draws over 
  632. red, say, the result is blue, and when it draws over blue the result is red. 
  633. This foreground value is itself the XOR of the colormap indices of red and 
  634. blue.
  635.  
  636. [Thanks to Chris Flatters (cflatter@zia.aoc.nrao.EDU) and Ken Whaley 
  637. (whaley@spectre.pa.dec.com), 2/91]
  638.  
  639. ----------------------------------------------------------------------
  640. Subject: 141)  Why does every color I allocate show up as black?
  641.  
  642.     Make sure you're using 16 bits and not 8.  The red, green, and blue 
  643. fields of an XColor structure are scaled so that 0 is nothing and 65535 is 
  644. full-blast. If you forget to scale (using, for example, 0-255 for each color) 
  645. the XAllocColor function will perform correctly but the resulting color is 
  646. usually black. 
  647.  
  648. [Thanks to Paul Asente, asente@adobe.com, 7/91]
  649.  
  650. ----------------------------------------------------------------------
  651. Subject: 142)  Why can't my program get a standard colormap?
  652. I have an image-processing program which uses XGetRGBColormap() to get the 
  653. standard colormap, but it doesn't work. 
  654.  
  655.     XGetRGBColormap() when used with the property XA_RGB_DEFAULT_MAP does 
  656. not create a standard colormap -- it just returns one if one already exists.
  657. Use xstdcmap or do what it does in order to create the standard colormap first.
  658.  
  659. [1/91; from der Mouse (mouse@larry.mcrcim.mcgill.edu)]
  660.  
  661. ----------------------------------------------------------------------
  662. Subject: 143)  Why does the pixmap I copy to the screen show up as garbage? 
  663.  
  664.     The initial contents of pixmaps are undefined.  This means that most
  665. servers will allocate the memory and leave around whatever happens to be there 
  666. -- which is usually garbage.  You probably want to clear the pixmap first using
  667. XFillRectangle() with a function of GXcopy and a foreground pixel of whatever 
  668. color you want as your background (or 0L if you are using the pixmap as a 
  669. mask). [courtesy Dave Lemke of NCD and Stuart Marks of Sun]
  670.  
  671. ----------------------------------------------------------------------
  672. Subject: 144)  How do I check whether a window ID is valid?
  673. My program has the ID of a window on a remote display. I want to check whether
  674. the window exists before doing anything with it.
  675.  
  676.     Because X is asynchronous, there isn't a guarantee that the window 
  677. would still exist between the time that you got the ID and the time you sent an
  678. event to the window or otherwise manipulated it. What you should do is send the
  679. event without checking, but install an error handler to catch any BadWindow 
  680. errors, which would indicate that the window no longer exists. This scheme will
  681. work except on the [rare] occasion that the original window has been destroyed 
  682. and its ID reallocated to another window.
  683.  
  684. [courtesy Ken Lee (klee@synoptics.com), 4/90]
  685.  
  686. ----------------------------------------------------------------------
  687. Subject: 145)  Can I have two applications draw to the same window?
  688.  
  689.     Yes. The X server assigns IDs to windows and other resources (actually,
  690. the server assigns some bits, the client others), and any application that 
  691. knows the ID can manipulate the resource [almost any X server resource, except
  692. for GCs and private color cells, can be shared].
  693.     The problem you face is how to disseminate the window ID to multiple 
  694. applications. A simple way to handle this (and which solves the problem of the
  695. applications' running on different machines) is in the first application to 
  696. create a specially-named property on the root-window and put the window ID into
  697. it. The second application then retrieves the property, whose name it also
  698. knows, and then can draw whatever it wants into the window.
  699.     [Note: this scheme works iff there is only one instance of the first
  700. application running, and the scheme is subject to the limitations mentioned
  701. in the Question about using window IDs on remote displays.]
  702.     Note also that you will still need to coordinate any higher-level 
  703. cooperation among your applications. 
  704.     Note also that two processes can share a window but should not try to 
  705. use the same server connection. If one process is a child of the other, it 
  706. should close down the connection to the server and open its own connection.
  707.  
  708. [mostly courtesy Phil Karlton (karlton@wpd.sgi.com) 6/90]
  709.  
  710. ----------------------------------------------------------------------
  711. Subject: 146)  Why can't my program work with tvtwm or swm?
  712.  
  713.     A number of applications, including xwd, xwininfo, and xsetroot, do not
  714. handle the virtual root window which tvtwm and swm use; they typically return 
  715. the wrong child of root. A general solution is to add this code or to use it in
  716. your own application where you would normally use RootWindow(dpy,screen):
  717.  
  718. /* Function Name: GetVRoot
  719.  * Description: Gets the root window, even if it's a virtual root
  720.  * Arguments: the display and the screen
  721.  * Returns: the root window for the client
  722.  */
  723. #include <X11/Xatom.h>
  724. Window GetVRoot(dpy, scr)
  725. Display        *dpy;
  726. int             scr;
  727. {
  728. Window          rootReturn, parentReturn, *children;
  729. unsigned int    numChildren;
  730. Window          root = RootWindow(dpy, scr);
  731. Atom            __SWM_VROOT = None;
  732. int             i;
  733.  
  734.   __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
  735.   XQueryTree(dpy, root, &rootReturn, &parentReturn, &children, &numChildren);
  736.   for (i = 0; i < numChildren; i++) {
  737.     Atom            actual_type;
  738.     int             actual_format;
  739.     long            nitems, bytesafter;
  740.     Window         *newRoot = NULL;
  741.  
  742.     if (XGetWindowProperty(dpy, children[i], __SWM_VROOT, 0, 1,
  743.         False, XA_WINDOW, &actual_type, &actual_format, &nitems,
  744.             &bytesafter, (unsigned char **) &newRoot) == Success && newRoot) {
  745.             root = *newRoot;
  746.             break;
  747.         }
  748.     }
  749.  
  750.     return root;
  751. }
  752.  
  753. [courtesy David Elliott (dce@smsc.sony.com). Similar code is in ssetroot, a
  754. version of xsetroot distributed with tvtwm. 2/91]
  755.  
  756. A header file by Andreas Stolcke of ICSI on export.lcs.mit.edu:contrib/vroot.h 
  757. functions similarly by providing macros for RootWindow and DefaultRootWindow;
  758. code can include this header file first to run properly in the presence of a
  759. virtual desktop.
  760.     
  761. ----------------------------------------------------------------------
  762. Subject: 147)  How do I keep a window from being resized by the user?
  763.  
  764.     Resizing the window is done through the window manager; window managers
  765. can pay attention to the size hints your application places on the window, but 
  766. there is no guarantee that the window manager will listen. You can try setting 
  767. the minimum and maximum size hints to your target size and hope for the best. 
  768. [1/91]
  769.  
  770. ----------------------------------------------------------------------
  771. Subject: 148)  How do I keep a window in the foreground at all times?
  772.  
  773.     It's rather antisocial for an application to constantly raise itself
  774. [e.g. by tracking VisibilityNotify events] so that it isn't overlapped -- 
  775. imagine the conflict between two such programs running.  
  776.     The only sure way to have your window appear on the top of the stack
  777. is to make the window override-redirect; this means that you are temporarily
  778. assuming window-management duties while the window is up, so you want to do 
  779. this infrequently and then only for short periods of time (e.g. for popup 
  780. menus or other short parameter-setting windows).
  781.  
  782. [thanks to der Mouse (mouse@larry.mcrcim.mcgill.edu); 7/92]
  783.  
  784. ----------------------------------------------------------------------
  785. Subject: 149)  How do I make text and bitmaps blink in X?
  786.  
  787.     There is no easy way.  Unless you're willing to depend on some sort of
  788. extension (as yet non-existent), you have to arrange for the blinking yourself,
  789. either by redrawing the contents periodically or, if possible, by playing games
  790. with the colormap and changing the color of the contents.
  791.  
  792. [Thanks to mouse@larry.mcrcim.mcgill.edu (der Mouse), 7/91]
  793.  
  794. ----------------------------------------------------------------------
  795. Subject: 150)  How do I get a double-click in Xlib?
  796.  
  797.     Users of Xt have the support of the translation manager to help 
  798. get notification of double-clicking.
  799.     There is no good way to get only a double-click in Xlib, because the 
  800. protocol does not provide enough support to do double-clicks.  You have to do 
  801. client-side timeouts, unless the single-click action is such that you can defer
  802. actually taking it until you next see an event from the server.  Thus, you 
  803. have to do timeouts, which means system-dependent code.  On most UNIXish 
  804. implementations, you can use XConnectionNumber to get the file descriptor of 
  805. the X connection and then use select() or something similar on that.
  806.     Note that many user-interface references suggest that a double-click
  807. be used to extend the action indicated by a single-click; if this is the case
  808. in your interface then you can execute the first action and as a compromise
  809. check the timestamp on the second event to determine whether it, too, should
  810. be the single-click action or the double-click action.
  811.  
  812. [Thanks to mouse@larry.mcrcim.mcgill.edu (der Mouse), 4/93]
  813.  
  814. ----------------------------------------------------------------------
  815. Subject: 151)  How do I render rotated text?
  816.     
  817.     Xlib intentionally does not provide such sophisticated graphics 
  818. capabilities, leaving them up to server-extensions or clients-side graphics
  819. libraries.
  820.     Your only choice, if you want to stay within the core X protocol, is to
  821. render the text into a pixmap, read it back via XGetImage(), rotate it "by 
  822. hand" with whatever matrices you want, and put it back to the server via 
  823. XPutImage(); more specifically:
  824.     1) create a bitmap B and write your text to it.
  825.     2) create an XYBitmap image I from B (via XGetImage).
  826.     3) create an XYBitmap Image I2 big enough to handle the transformation.
  827.     4) for each x,y in I2, I2(x,y) = I(a,b) where 
  828.         a = x * cos(theta) - y * sin(theta)
  829.         b = x * sin(theta) + y * cos(theta)
  830.     5) render I2
  831.     Note that you should be careful how you implement this not to lose
  832. bits; an algorithm based on shear transformations may in fact be better.
  833.     The high-level server-extensions and graphics packages available for X 
  834. also permit rendering of rotated text: Display PostScript, PEX, PHiGS, and GKS,
  835. although most are not capable of arbitrary rotation and probably do not use the
  836. same fonts that would be found on a printer.
  837.     In addition, if you have enough access to the server to install a font
  838. on it, you can create a font which consists of letters rotated at some
  839. predefined angle. Your application can then itself figure out placement of each
  840. glyph.
  841.  
  842. [courtesy der Mouse (mouse@larry.mcrcim.mcgill.edu), Eric Taylor 
  843. (etaylor@wilkins.bmc.tmc.edu), and Ken Lee (klee@synoptics.com), 11/90;
  844. Liam Quin (lee@sq.com), 12/90]
  845.  
  846.     InterViews (C++ UI toolkit, in the X contrib software) has support for
  847. rendering rotated fonts in X.  It could be one source of example code.
  848. [Brian R. Smith (brsmith@cs.umn.edu), 3/91]
  849.     Another possibility is to use the Hershey Fonts; they are 
  850. stroke-rendered and can be used by X by converting them into XDrawLine 
  851. requests. [eric@pencom.com, 10/91]
  852.  
  853.     The xrotfont program by Alan Richardson (mppa3@syma.sussex.ac.uk) 
  854. (posted to comp.sources.x July 14 1992) paints a rotated font by implementing 
  855. the method above and by using an outline (Hershey) font.
  856.     The xvertext package by Alan Richardson (mppa3@syma.sussex.ac.uk) is a 
  857. set of functions to facilitate the writing of text at any angle.  It is on 
  858. export as contrib/xvertext.5.0.shar.Z. 
  859.  
  860.     O'Reilly's X Resource Volume 3 includes information from HP about
  861. modifications to the X fonts server which provide for rotated and scaled text.
  862.  
  863. ----------------------------------------------------------------------
  864. Subject: 152)  What is the X Registry? (How do I reserve names?)
  865.  
  866.     There are places in the X Toolkit, in applications, and in the X
  867. protocol that define and use string names. The context is such that conflicts
  868. are possible if different components use the same name for different things.
  869.     The MIT X Consortium maintains a registry of names in these domains:
  870. orgainization names, selection names, selection targets, resource types,
  871. application classes, and class extension record types; and several others.
  872.     The list as of 7/91 is in the directory mit/doc/Registry on the R5 
  873. tape; it is also available by sending "send docs registry" to the xstuff mail
  874. server.
  875.     To register names (first come, first served) or to ask questions send 
  876. to xregistry@expo.lcs.mit.edu; be sure to include a postal address for
  877. confirmation.
  878.  
  879. [11/90; condensed from Asente/Swick Appendix H]
  880. ----------------------------------------------------------------------
  881.  
  882.  
  883. David B. Lewis                     faq%craft@uunet.uu.net
  884.  
  885.         "Just the FAQs, ma'am." -- Joe Friday 
  886. -- 
  887. David B. Lewis        Temporarily at but not speaking for Visual, Inc.
  888. day: dbl@visual.com    evening: david%craft@uunet.uu.net
  889.