
From apollo-request@umix.cc.umich.edu Mon Nov 20 01:59:27 1989
Received:  from mailrus.cc.umich.edu (2301011a) by icaen.uiowa.edu (4.12/1.1) id AA24610
	on Mon, 20 Nov 89 01:59:18 cdt.
Received: from umix.cc.umich.edu by mailrus.cc.umich.edu (5.61/gossip-1.1)
	id AA28953; Mon, 20 Nov 89 02:12:53 -0500
Received: by umix.cc.umich.edu (5.54/umix-2.0)
	id AA05282; Mon, 20 Nov 89 00:13:21 EST
Received: by umix.cc.umich.edu (5.54/umix-2.0)
	id AA03242; Sun, 19 Nov 89 23:24:48 EST
Received: by ucbvax.Berkeley.EDU (5.61/1.39)
	id AA27684; Sun, 19 Nov 89 20:04:13 -0800
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for apollo-arpa@umix.cc.umich.edu (apollo@umix.cc.umich.edu)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 19 Nov 89 14:48:00 GMT
From: oj%apollo%hp-sdd%ncr-sd%ncrlnk.uucp@uunet.uu.net  (Ellis Oliver Jones)
Organization: Apollo Computer, Chelmsford, MA
Subject: The X Window System on Domain/OS: Questions and Answers
Message-Id: <46ee4d8f.20b6d@apollo.HP.COM>
Sender: apollo-request@umix.cc.umich.edu
To: apollo@umix.cc.umich.edu

Domain/OS System Release 10.2 is finally shipping (for m68k node types;
the DN10000 schedule runs a few weeks behind the m68k).  As many of you
know, HP/Apollo has bundled the X Window System(TM) with SR10.2.

During the alpha and beta period for SR10.2, we had many internal users
and a fairly large number of beta sites.  In the X development group we
kept a log of questions and answers about how to use it.  I've edited that
question-and-answer log and I'm posting it here to help newnews readers 
come up to speed with SR10.2 and X.  

This posting covers questions from users.  The next posting will cover
programming questions.

A disclaimer:  keeping the Q&A log and answering the questions has been a
midnight project for myself and others.  I take personal responsibility
for errors in this material, and I hope anyone spotting an error will
inform both me and comp.sys.apollo.  Nothing in this posting should be 
interpreted as the "official" position of HP.

Enjoy!

Ollie Jones.


Question:  I am getting the following messages:
	69>  /usr/X11/bin/xterm
	reference to undefined global (process manager/loader) 
	/usr/X11/bin/xterm
Any ideas?  What am I missing?
Answer:  If you're running Domain/X11 V1.1 on SR10.1, be sure that 
you've followed the installation instructions about adding a reference to 
x11lib to the file /etc/sys.conf.  Alternatively, inlib /lib/x11lib 
before running xterm.

Q:  I get this error message when I run xterm or xclock:
	X Toolkit Error: Can't Open display: 
A:  Make sure the DISPLAY environment variable is defined, and make 
sure your X server is running.  
On SR10.1 you have to do this manually (in some startup script).  
On SR10.2, the DISPLAY environment variable is set for you automatically 
in the appropriate one of the following node startup files:
	/sys/node_data/startup
	/sys/node_data/startup.19l
	/sys/node_data/startup.color
	/sys/node_data/startup.1280bw
	/sys/node_data/startup.1280color
Beware; if you installed SR10.2 as an upgrade on a node which already had 
SR10.1 running on it  the new startup files don't replace the old ones but 
rather get installed with the current date appended to the file name.  If you 
don't have a DISPLAY environment variable, you (or your system 
adminstrator) may have to do some editing of startup files.  
Suppose you installed your SR10.2 upgrade on December 13th, and suppose 
you're using a DN3500F.  Then you should edit 
/sys/node_data/startup.1280color so it includes the setting of the 
environment variable we added for SR10.2.  In this example you would look 
in the SR10.2-installed file /sys/node_data/startup.1280color.12.13. 
Maybe your X server isn't running.  In this case, on SR10.2, create an empty 
(zero-length) file named /etc/daemons/Xapollo and reboot the node.  
Notice that the zero-length file /etc/templates/daemons/Xapollo 
controls what happens with diskless nodes.  

Q:  What exact lines do I need in my ~/user_data/startup_dm.1280.bw 
file?  Are these what I need ?

  env display := ':0'
  export display
  /com/crf /etc/daemons/Xapollo   

A:  You shouldn't need to do any of these things in your private startup 
file.  Just once, you should create the zero-length file 
/etc/daemons/Xapollo, then reboot.  The DISPLAY environment variable 
should be set up automatically in your node-wide startup script (but see the 
previous question and answer).

Q:  Well, I am really stuck. I can't seem to keep X up on my SR10.1 node 
today. Everytime I run xset (no matter which font is being set) I get a XIO 
error, broken pipe. 
   % /usr/bin/X11/Xapollo -K ~/user_data/Xkey.config -D1 s+r- &
   % /usr/bin/X11/xclient &
   % xset fp /usr/lib/X11/fonts/75dpis/ &   
   % Connection # 3 to server broken.
   XIO: Broken pipe
   Connection # 3 to server broken.
   XIO: Broken pipe 

A:  Are you waiting for Xapollo to start before issuing the client 
commands? Sometimes Xapollo takes a while to start up.  This is especially 
true if tcp/ip isn't working on your node:  the X server attempts to initialize 
a TCP socket.   Try sleep 60 or similar right after the Xapollo command.
Also, notice that /usr/lib/X11/fonts/75dpis/ probably isn't a valid font 
path, and /usr/lib/X11/fonts/75dpi/ probably is.

Q:  My Xapollo server crashes sometimes.
A:  What's in the /sys/node_data/system_logs/X0msgs file? That's 
how we tell what the crash was.  You can read this file with the UNIX(r)
utility cat.  Please file an APR when you see a server crash.

Q:  I'm running Xapollo SR10.2.  Today, when I tried to run gnuemacs I 
got the error message
   emacs: X server unable to find requested font `fixed'.
Does anyone know what I need to do to make X happy with my fonts?
On related notes, I'm not terribly happy with the default behavior of Emacs-
under-X;  the font is so small as to be almost unreadable and the window-
size is correspondingly tiny

A:  Try putting this line in your .Xdefaults file in your home directory.  If 
you already use xrdb, don't forget to rerun it.  This will give you a legible 
font in emacs.
    emacs*font:	*-courier-bold-r-normal*-140-*
Also, try issuing this command to allow your SR10.2 X server to use the 
fonts from both XV11R3 and XV11R2:
    % xset fp+ /usr/lib/X11/fonts/oldX11/


Q:  I would like to start xclock from my startup_dm file.  (Is there a 
better way to start xclock at login?)  When I am logged in and give the 
following to the dm:
   cpo /bin/csh -c '/usr/X11/bin/xclock -display \:0 -u 60 -g 100x100+1178+0 &'
the xclock seems to start just fine, but if I put the same line in my personal 
DM startup file , the xclock nevers starts up when I log in and doesn't give 
any error messages.  What am I doing wrong?

A:  Many /bin/csh or /bin/sh users start X stuff from their .login or 
.profile files.  This is a good way to do things for a couple of reasons:
(1) it's a good idea to use xrdb to load resource info from your ~/.Xdefaults 
file.  (2) Once you've loaded resource info, you don't have to say as much to 
the xclock command.  For example, if you have these lines in your 
~/.Xdefaults file, the position and update time of your xclock are automatic.

    xclock.*.mode:              analog
    xclock.*.borderWidth:       3
    xclock.*.update:            60
    xclock.*.geometry:          40x40-1-50
    #ifdef COLOR
    xclock.*.border:            red
    xclock.*.background:	turquoise
    xclock.*.foreground:	black
    xclock.*.hands:             red
    xclock.*.highlight:         black
    #endif

Q:  I am having this strange bug with deleting windows. It seems
somewhat connected to using X windows.  When windows are resized, 
there are leftover parts of windows left around on the screen. 
A:  We've seen this before, when running with an X window manager 
(like uwm, twm, or the like) and forgetting to tell the X server it owns the 
"root" or screen background window.
To run an X window manager, you have to do three things:
  (1) say "wmgr -off" (to the DM command window.)
  (2) say /usr/X11/bin/xownroot -on   (to some shell)
  (3) run the window manager, e.g. uwm & (to some shell)
It sounds like you forgot  step 2, which leaves nobody owning the root, which 
means that neither the DM nor X can clean up after windows which have 
gone away.

Q:  If I let the DM own root at startup, everything works fine, but if I 
have X own the root at startup and comment the "xownroot -on" out of my 
.login file, I don't get any rubberbanding when I resize or move windows 
and icons.
A:  Try changing your background to some other color, for example
   xsetroot -solid cornflowerblue
Then see if you still don't get rubberbanding.  

Q:  I am currently running sr10.2 on my color node and by using xgif I 
have been able to display images as my background display.  Do you have 
anything like that that I could run on my mono node? 
A:  Mono gif images can be converted to xbitmaps via 
	giftopbm | pbmtoxbm > file.xbm
and xsetroot can then be used to make them the background.  Similarly the 
macpaint files can be viewed with xmac, or converted using 
	macptopbm | pbmtoxbm
Do a "man pbm" and "man fbm" (both in /usr/local/man) for more 
information about these publicly available programs.  Use ftp to get them 
from expo.lcs.mit.edu.

Q:  I don't know how to make xgif get rid of previous root pictures:  
successive invocations cause refreshes to recapitulate all of the old images. 
A:  You are probably running several different invocations of xgif.  Kill
all-but-one.


Q:  Does Xlib support anything analogous to the external GPR  bitmap 
file?
A:  Not really.  It supports an ASCII representation for single-plane 
bitmaps.  This ASCII representation is in a form that can be read/written 
by Xlib (XReadBitmapFile/XWriteBitmapFile) or #included in a C program.
See /usr/X11/include/bitmaps/star for an example.

Q:  I hate X.  It's a stupid system, but now at SR10.2 Apollo forces me to 
run it on my node, wasting memory and a process slot.  Do I have to go back 
to SR10.1 to get rid of X?
A:  No, you can stay with SR10.2 even if you don't want X running.  To 
prevent the X server from starting automatically when you boot your node, 
either answer "no" to the relevant config question or customize your 
SR10.2 installation by deleting the following files (if they exist).  Reboot your 
node after deleting the files.
         /etc/daemons/Xapollo
         /etc/templates/daemons/Xapollo
These files have zero length and contain no useful information, so if you 
decide later that you wish to run the X server, you may recreate these files 
with zero length and reboot.
Please be aware that an increasing number of software developers are 
committing to X, and that you may need to run the X server in the future
to use their products.

Q:  Whenever I try to set the DISPLAY variable so I can draw on the 
color node in the next  office, I get "Can't open display" as an error 
message.  If I set it to just :0 for my own node everything is OK.  These nodes 
all run TCP and have proper TCP addresses.  
A:  You have to log in to the node in the next office and use the xhost 
command to allow your node to have access. For example, suppose your 
node is named //mine and the color node is named //color.  Log in to 
//color and issue these two commands:

    /usr/X11/bin/xclient &
    /usr/X11/bin/xhost +mine

Notice that you should invoke xclient to keep the X server on //color 
from resetting after the xhost command (whenever the X server detects 
that no client programs are attached to it it assumes the user has logged off 
and "resets," cleaning up all sorts of per-session data).  Notice also that you 
don't use the node name's slashes in the xhost command.  
A permanent xhost entry can be created by editing the file /etc/X0hosts to 
include the appropriate host name.  

Q:  We are trying to determine if we are able to set up X on an Apollo 
workstation and have the client process run on a Digital VAXStation (tm).
A:  Yes, network transparency is the entire point of X.  You have to make sure 
your VAX is registered as a host in the /etc/hosts file on your Apollo node, 
and vice versa.   See the answer to the previous question for information 
on how to authorize the VAX to connect to the Apollo display.

Q:  I tried out the Motif Window Manager on a 1280 x 1028 x 8 DM 4500 at 
sr10.2.  The machine was started with the DM managing the root and X 
running in shared mode. I started up the mwm and turned DM window 
management off.
In this configuration the MWM does not clear the display. A posted menu 
stays up. A moved window shows up in both locations.
A:  Here's a script you can use to start up mwm on a "vanilla" SR10.2 
node.  I suspect you didn't give the "xownroot -on" command.
    /com/xdmc "wmgr -off"  # turn off dm's window manager capability
    xownroot -on           # tell X it owns the root window
    xclient &              # start up a dummy client to prevent server reset
    xrdb ~/.Xdefaults      # load my ~/.Xdefaults file into the server
    mwm   &                # start mwm
    /usr/X11/bin/xmodmap /usr/lib/X11/keyboard/xmodmap.kb3sample 

[the mwm window manager isn't distributed with SR10.2, but rather with
 the Domain Motif distribution, which isn't out yet.  -editor]

Q:  I seem to be having a problem when I set this in my .Xdefaults:
     mwm*iconBoxGeometry: =500x100+10+690
A:  Holy Cow!  You're asking for an icon box with enough room for 500 
icons across by 100 icons down.  That's big!  Try
     mwm*iconBoxGeometry: 7x1+10+690

Q:  The window manager is oue problem.  We would like to use twm instead 
of uwm.  But apollo has made undocumented modifications (no source code) to uwm 
and so the customer is not able to use both dm and x clients with twm 
simultaneously.
A:  If we have made changes to uwm, they're insignificant.  uwm from 
the MIT tape should run fine on Domain/X11.  
The actual problem with using twm is that it's a reparenting window 
manager:  it wraps windows in new "decoration" windows.  This gives nice 
functionality.  Unfortunately it also plays havoc with the Domain/X11 share 
mode.   Only at sr10.2 and later does the share-mode Domain/X11 server 
work correctly with reparenting window managers. So, I suggest 
upgrading to sr10.2 as soon as it is available.  If you can't upgrade
to sr10.2 call Customer Service and explain your problem.  They should
be able to help you.

Q:  Why does my xterm take so much virtual memory, and why does it 
take so long to resize?
A:  You may have set your xterm saveLines to a large number, like 10000, 
in your ~/.Xdefaults file to emulate the DM's infinite transcript pads.  If you 
do this, each time you make an xterm it allocates several megabytes of 
virtual memory complete with backing store (enough to hold 10000 of the 
longest lines you can have).  Furthermore, when you resize the xterm, it 
reallocates the memory.  Better to set xterm's saveLines property to a much 
small number, like 500 or 1000.

Q:  What's the "name" of the dm windows as far as mwm or twm is 
concerned? If I want the alarm server's little windows to pop up with no 
decoration, what do I put in my ~/.Xdefaults file?
A:  For the sr10.2 DM there isn't one stored in the X property. Therefore 
all DM windows will use no name or as mwm likes to put it, "*****".  twm 
labels these windows "NoName."  The only way to treat a DM window 
specially is to set the default window dressing to be what you want for the 
DM and individually tailor X apps. Or you can wait for the Grue DM.

Q:  Occasionally, I try to start up an xterm and get this message:
	xterm: no available ptys
I'm not sure, but I think this is a lie; I have ptyp0 through ptypf and ttyp0 
through ttypf, and I'm not running that many processes. Any hints?
A:  For some reason your pty(s) became trashed.  The easiest way to
solve the problem is recreate them.   Use these commands, then reboot:
	rm /dev/pty* /dev/ttyp*
	/etc/mkdev /dev pty 16
GNU emacs is one program which appears to consume ptys.  After several 
invocations of shells from with GNU emacs you may have to recreate the 
ptys.

Q:  How can I create a DM transcript pad with a shell running in it 
from within an xterm or other X program?  /com/xdmc only works from 
within a DM pad. so I can't use a DM "cp" command.
A:  Use /usr/X11/bin/dmwin.  This program serves as a wrapper from 
which any program that uses PAD calls on any of the standard streams 
may be run.  dmwin creates a transcript/input pad pair on the screen of the 
local Display Manager, and then runs the program given to it with its 
standard streams connected to the new pads.  It also makes sure the 
"TERM" environment variable is set to a reasonable value for a DM 
window.

Q:  If I've got two dm windows (started in my startx script) overlapping 
each other and they are controlled by mwm (with X as root), I can get the 
arrow keys to move from one window to another without catching on the 
window manager resize border.  I'm using OSF/Motif 1.0 beta.
A:  The DM keeps track of its "locator" and its cursor position separately.  
The arrow keys move the locator, but not this cursor.  So if you drive out of a 
window with an arrow key then hit a letter key, you get <beep>.  But if you 
drive from one window to another, it just works (except the cursor 
doesn't follow along, but rather jumps when the locator arrives in the new 
window).  We have a bug logged on this, but fixing it is deferred until the 
next major release.

Q:  I used to let the DM use colors 0 - 16 and lived with 240 colors for the 
color ramp (this was real easy to do with GPR).
Now I want to do the same with X/Motif.  Unfortunately, when I start up 
mwm, it allocates (by default) colors 3-6 and 16-22.  I can cut down on a 
couple of colors that it grabs above index 15 (by making DM colors the same, 
so that it will *share* them in the 7 - 15 range), but not all of them.

How can I get 240 contiguous colors in X and still use mwm?  Will using 
xdm instead work (ie: are colors 7 - 15 available for mwm?)?

A:  Yes, before you start mwm issue the "mono" command to the DM.  
This will induce the DM to release some colors.  Also, don't run any other 
motif stuff besides the window manager.  Now, if you play around with the 
stuff in your ~/.Xdefaults file (to simplify the motif colors) you may get 240 
consecutive colors 14-253 to play with.   You'll probably be able to figure 
something out.

Q:  I understand that apollo has created a separate X library called xdl 
for performance reasons.  My question is does this library work in share 
mode or is it X only functionality?
  
A:  We have improved X performance on sr10.2 by using native X 
graphics on selected devices.  The code we use for this is the "X display 
library" or "xdl." 
Currently only monochrome devices (including the DN2500) have xdl 
drivers.  These drivers cause the X server to run faster, and have no effect 
on GPR or the DM.  Share-mode still works with these xdl drivers.

If you use X on sr10.2 on the supported devices, then you are using the xdl 
drivers (but see the next question and answer).  Stay tuned for news about 
support of color displays post-sr10.2.

Q:  My SR10.2 X server runs ridiculously slowly.  Why?

A:  There are some installation and configuration problems which can 
cause an Xapollo server to run abnormally slowly.

(1) If your node is monochrome, you may not have the x display type 
manager running due to an error in installation.  To find out whether it's 
running, do this:

a)  ps axu to find out the Xapollo process id.
b)  /usr/apollo/bin/las <pid> on the Xapollo process id (list-address-space)
        Look for one of the following files to be mapped:
          /sys/mgrs.split/dtm_mono_big/xdl_trait 
          /sys/mgrs.split/dtm_mono_small/xdl_trait 
          /sys/mgrs.split/dtm_fm/xdl_trait 
If none of these files is mapped on your mono node, there's something 
wrong with your sr10.2 installation.

(2) Make sure your X fonts are installed locally rather than through a soft 
link to another node.     Network-access time for fonts can slow you down 
drastically.

Q:  How do X window managers deal with the three dm command lines 
at the bottom of the screen?  Is there some way to tell mwm not to put 
decorations around these three windows?

A:  X window managers (mwm for example) deal poorly with those 
windows.  You can specify that the default window decoration should be 
"none" but then that affects all DM windows, not just the command 
windows.  If you wanted to do that with mwm, you'd put lines like the 
following in your xrdb file:

      Mwm*defaults.clientDecoration:		none
      Mwm*xgetmail.clientDecoration:		none
      Mwm*xprmon.clientDecoration:		title
      Mwm*xperfmon.clientDecoration:	title
      Mwm*xsysmon.clientDecoration:		title
      Mwm*datebook.clientDecoration:		all

Many of us mwm users just leave the decorations on the command 
windows, but make the command windows smaller to accomodate the 
decorations, using the following entries in `node_data/startup.1280color .   
Notice that these same lines will work in `node_data/startup.1280bw , but 
that you'll need something else in the files for a 1024x800 display.

       (630,1001)dr;(1270,1013)cv /sys/dm/output
       (540,1001)dr;(620,1013)dr;(632,1010)cc;pb
       (0,1001)dr;(530,1013)cv /sys/dm/input


Thanks to Kee Hinckley, Rod Owen, Joe Bowbeer, Glen Valante, Craig 
Wolpert, John Brezak, Jim Glading, Mike Burati and Rob Stanzel for some 
of these answers, and to many people for the questions.

From apollo-request@umix.cc.umich.edu Mon Nov 20 01:43:36 1989
Received:  from mailrus.cc.umich.edu (2301011a) by icaen.uiowa.edu (4.12/1.1) id AA24594
	on Mon, 20 Nov 89 01:43:30 cdt.
Received: from umix.cc.umich.edu by mailrus.cc.umich.edu (5.61/gossip-1.1)
	id AA27176; Mon, 20 Nov 89 01:58:39 -0500
Received: by umix.cc.umich.edu (5.54/umix-2.0)
	id AA05272; Mon, 20 Nov 89 00:12:42 EST
Received: by umix.cc.umich.edu (5.54/umix-2.0)
	id AA03234; Sun, 19 Nov 89 23:24:22 EST
Received: by ucbvax.Berkeley.EDU (5.61/1.39)
	id AA27664; Sun, 19 Nov 89 20:03:41 -0800
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for apollo-arpa@umix.cc.umich.edu (apollo@umix.cc.umich.edu)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 19 Nov 89 15:02:00 GMT
From: oj%apollo%hp-sdd%ncr-sd%ncrlnk.uucp@uunet.uu.net  (Ellis Oliver Jones)
Organization: Apollo Computer, Chelmsford, MA
Subject: The X Window System on Domain/OS: Questions and Answers part 2
Message-Id: <46ee595d.20b6d@apollo.HP.COM>
Sender: apollo-request@umix.cc.umich.edu
To: apollo@umix.cc.umich.edu

This posting covers X Window System questions from programmers.  
The previous posting covered user questions.

A disclaimer:  keeping the Q&A log and answering the questions has been a
midnight project for myself and others.  I take personal responsibility
for errors in this material, and I hope anyone spotting an error will
inform both me and comp.sys.apollo.  Nothing in this posting should be 
interpreted as the "official" position of HP.

Enjoy!

Ollie Jones.

Question:  Does Xlib support anything like the external GPR bitmap file?
Answer:  Not really.  It supports an ASCII representation for single-plane 
bitmaps.  This ASCII representation is in a form that can be read/written 
by Xlib (XReadBitmapFile/XWriteBitmapFile) or #included in a C program.
See /usr/X11/include/bitmaps/star for an example.

Q:  How do I use Apollo event counts with X, rather than the Berkeley 
select(2) call?
A:  (thanks to Joe Bowbeer) On SR10.2, look at 
     /usr/X11/examples/x_and_gpr_input/x_and_gpr_input.c
The gist of it is this:   (1) retrieve the event count for the socket used by the X 
display connection:
    #define necs 2   /* or whatever number of event counts you want */
    #define ix   0   /* or whatever index you want for X waits */
    #define igpr 1   /* or whatever... */
    Display         *display;	    /* X display structure */
    ec2_$ptr_t      ec2_ptr[necs]; /* arrays for ec2_$wait */
    unsigned long   ec2_val[necs]; 
    status_$t       status;        /* status code for sys calls */
    ...
    ios_$get_ec( (ios_$id_t)ConnectionNumber(display), 
                 ios_$get_ec_key, &ec2_ptr[ix], &status);
    ec2_val[ix]  = ec2_$read(*ec2_ptr[ix]);
(2) initialize any other event counts you want in the event count arrays.  For 
example:
    gpr_$get_ec(gpr_$input_ec, &ec2_ptr[igpr], &status);
    ec2_val[igpr] = ec2_$read(*ec2_ptr[igpr]);
(3) in your main loop, use ec2_$wait to block, rather than XNextEvent or 
gpr_$event_wait:
  while (!quit)   {
    XFlush(display);   /* flush X display connection before blocking */
    which = ec2_$wait (ec2_ptr, (ec2_$val_list_t)ec2_val, 
                         necs, &status);
    switch (--which) {      /* decrement for 0-based indices */
      case igpr:
        /* advance ec */
        ec2_val[igpr] = ec2_$read(*ec2_ptr[igpr]) + 1;
        do { /* flush gpr events. gpr calls refresh entry here */
          gpr_$cond_event_wait(&event, &button, &position, &status);
          if (event != gpr_$no_event) 
            /* process the gpr event */
        } while (!quit && (event != gpr_$no_event));
        break;

      case ix:
        /* advance ec */
        ec2_val[ix] = ec2_$read(*ec2_ptr[ix]) + 1;
        while (0 != XEventsQueued(display, QueuedAfterReading)) {
          XNextEvent(display, &event);
            /* process all queued X events */
        }
        break;
    } /* end switch (--which) */
  } /* end  while (!quit)  */

This uses plain-old event-count handling.  You can use whatever event 
counts you wish for this; you're not limited to GPR and X event counts.

Q:  My application references include files that I can't seem to locate:
    #include <Xr/keycode.h>
    #include <Xw/Xw.h>
    #include <Xw/XwP.h>
A:  These include files have to do with HP toolkits.  You can find up-to-
date copies of the Xw stuff via ftp on expo.lcs.mit.edu.  The Xr stuff is from a 
library called Xrlib, colloquially known as Xray.  You might consider
switching to OSF/Motif.

Q:  Is there a way to draw vertical text in x? I want to label the vertical 
axis of a graph.
A:  Short answer:  No.
Long answer:  There's an XV11R2 font called rot-s16  which has characters 
oriented going down the page.  If you image each character with a separate 
Xlib call, each on its own baseline, you can label axes.  Yuk, but functional.

Q:  Is there any easy way of converting a font charater to an X bitmap?
A:  This depends on what you mean by "X bitmap", and what you mean 
by "easy."  You can make an X bitmap file with the client named "bitmap," 
and digitize the character's bits.  This is easy from a coding point of view 
but quite hard work.
You can use xfd to display all the characters in a font in an on-screen 
window.
You can make a one-plane Pixmap and draw your character into it.  Use 
XLoadQueryFont, then XTextExtents to find out the size of the character, 
then create the Pixmap, then draw the character into it.  You could use 
XWriteBitmapFile to move the Pixmap into a bitmap file.
If you wrote the code to do all this, it might be nice if you added it to the 
bitmap client.

Q:  In our new user interface, while the application is off performing 
some computation, it is not waiting for any X events.  Therefore there 
appears to be no easy way to present the user with some sort of <Interrupt> 
or <Abort> button. 
A:  Yes, this is a real problem with X-based applications.  There's 
another reason why you might try to keep watching the event queue while 
your application is doing computations:  some of them take a long time and 
the user might do things to incur exposure events while they're going on.  
They'd like it better if the refreshes came through correctly.  Not all events 
you'll get are interrupts from the user.
Here are some wild ideas on how maybe to manage this:
(1) do nothing...probably unacceptable.
(2) modify the long-running computations to somehow look for events.
(3) Whenever you start one of these long-running computes, spawn off a 
little separate user interface process which merely displays an <Interrupt> 
button, and if the user pushes it, sends a SIGTERM or something to the 
main application process.
(4) Establish a signal handler and condition the X connection socket to 
generate a signal when any X event arrives.  Code the signal handler to look 
ahead in the queue and figure out whether it's received something 
meaning abort, in which case longjmp somewhere to clean up.
(5) Use a lightweight thread, created via the task_$create call.  Be careful in 
this case as Xlib is not guaranteed reentrant.    
(6) Separate the UI process and the application's process.  This is probably 
the most robust and elegant solution.  It has upfront labor, but I suspect the 
investment will pay off handsomely in such areas as flexibility of the UI.

Q:  I get the message "XIO: Operation would block" from my X client 
program whenever I try to connect to the X server.
A:  You may be defining the variable errno in your program 
somewhere.  This variable is reserved for use by the C runtime library in 
reporting exceptional conditions to callers.  Xlib receives reports from the 
runtime library code to read and write sockets using errno, and if your 
program defines errno you may confuse Xlib.
The best way to obtain access to errno in your program is to use this: 
	#include <errno.h>
If you must declare errno explicitly, do so with the following line only:
	extern int errno;

Q:  I'm having trouble porting my Xt-based application to Apollo 
workstations.  It works fine on HP9000-300 series workstations and Sun 3 
workstations, but I'm getting bad data back from subroutines which create 
widgets on the Apollos. 
A:  Both the 9000-300 series workstations and the Suns use C compilers 
based on PCC.  Machine registers in these compilers are allocated such 
that D0 is used both for intermediate storage in computations and for 
returning function results.  So,  if you leave out the "return" statement at 
the end of a function compiled by such a compiler, the caller can get lucky 
and receive the result of the last computational expression in the function.  
The Domain C compiler is far less likely to allocate registers this way.  A 
good way to find this kind of programming mistake is to run lint.   

Q:  I'm getting protocol errors from my X application after I use 
XDestroyWindow to eliminate one of my windows.
A:  If you have an event-accepting loop which responds to MotionNotify 
hints by doing XQueryPointer, you can get into trouble if you destroy the 
window, because there may be some pending motion events after the 
window's gone.  What you need to do is clean out the event queue of those 
MotionNotify events right after issuing the XDestroyWindow request;  this 
code will do the trick:

          XEvent foo;
          XDestroyWindow(dpy, w); 
          XSync (dpy,0); 
          while (XCheckWindowEvent ( dpy,
                          ~(SubstructureNotifyMask|StructureNotifyMask), &foo ));

The advantage of this code is that it will flush out input and Expose events, 
and leave window structure  events (like, maybe, DeleteNotify and 
UnmapNotify) around for regular event processing to handle; thus other 
code can get notified of window destruction in due course if it cares.

It's not as drastic as XSync ( dpy, 1); which blows away all waiting events 
for all windows.  Notice this is a problem on all X workstations, not just apollos.

Q:  When trying to compile some code under sys5 I get the following errors:

  cc my.c /usr/X11/lib/libX11.a /usr/X11/lib/libXt.a  -o my
    /usr/include/X11/Xos.h: 69: Can't find include file strings.h
    /usr/include/X11/Xos.h: 80: Can't find include file sys/file.h
    /usr/include/X11/Xos.h: 98: Can't find include file sys/time.h

Define the symbol SYSV when compiling, and Xlib's includes will work 
properly.  Use "-DSYSV" as follows:

  cc my.c -DSYSV /usr/X11/lib/libX11.a /usr/X11/lib/libXt.a  -o my

Q:  When compiling an x program I get some undefined globals.
    
    cc -o xapp xapp.o -L/usr/lib/X11 -lX11 -lXt -lXaw
    undefined                             first referenced
     symbol                                  in file
    XtDestroyGC                         /usr/lib/X11/libXaw.a
    XtGetGC                             /usr/lib/X11/libXaw.a
    ld warning: Output file xapp not executable

What is wrong?  Is there a way to dump the libXt.a to find out what are the 
globals defined?  Like /com/bind -map ??
A:  You are specifying the order of your libraries incorrectly.  Try this:

    cc -o xapp xapp.o -L/usr/lib/X11 -lXaw -lXt -lX11

You can use /bin/nm (the Unix namelist command) to find out what 
symbols are defined in an object, archive, or shareable library:

      /bin/nm /usr/X11/lib/libXt.a | grep GC

Q:  Mouse motion events (after a button-down event) are not getting 
reported until after the button-up event.  Why are the motion events being 
delayed?   
A:  You are probably running "xev" or some other program which 
receives MotionNotify events from the server and printfs them to the 
standard output.  Also, you're probably running this program from a DM 
pad.   The problem is, the share-mode server acquires the GPR display lock 
while buttons are being held down, because of an X requirement that an 
active button grab be in effect while the button is held down.  

Your program receives the events at the correct time, and sends the output
to the DM.  The DM queues it up and doesn't output it until the user 
releases the button.  Try running your program from an xterm rather than 
a DM pad.

Q:  I am trying to compile an X application which includes an 
"Atoms.h" header file.   I can't find "Atoms.h".
A: Atoms.h is an XV11R2 Xt intrinsics file.  At XV11R3 it was renamed 
StringDefs.h, and Apollo supplies the XV11R3 intrinsics with SR10.2.

Q:  I have an X application that works fine in mono but fails to draw 
anything at all on a color node.  I'm using the following code:

       fg = BlackPixel( dpy, DefaultScreen( dpy ));
       bg = WhitePixel( dpy, DefaultScreen( dpy ) );
       GC = XCreateGC(dpy, w, 0, 0);
       XSetFunction(dpy,  GC, GXxor);
       XSetForeground(dpy, GC, fg );
       XSetBackground(dpy, GC, bg );
       XSetPlaneMask( dpy, GC, AllPlanes );

A:  You've got things set up wrong for exclusive-or drawing.  Set the 
plane mask to fg xor bg, set fg to all ones, and set bg to zero.

   XSetFunction(dpy,  GC, GXxor);
   XSetForeground(dpy, GC, AllPlanes );
   XSetBackground(dpy, GC, 0 );
   XSetPlaneMask( dpy, GC, fg^bg );

Alternatively, set the plane mask to fg xor bg and use GXinvert instead of
GXxor:

   XSetFunction(dpy,  GC, GXinvert);
   XSetForeground(dpy, GC, fg );
   XSetBackground(dpy, GC, bg );
   XSetPlaneMask( dpy, GC, fg^bg );

Notice that this applies to all X workstations, not just Apollos.

Q: Is the source-code for any of the example programs from 
the O'Reilly documentation series available somewhere?
A: It's in /usr/X11/src/oreilly.tar unless you told "config" not to install it.
See /usr/X11/src/README for an explanation.

Thanks to Kee Hinckley Rod Owen, Joe Bowbeer, Glen Valante, Craig 
Wolpert, John Brezak, Jim Glading, Mike Burati and Rob Stanzel for some 
of these answers.  I take responsibility for any errors.


