[comp.windows.x] Ways to detect what window system is running.

nelson@wrl.epi.com (Ken Nelson) (04/12/91)

I am looking for scripts or ideas for how to detect what
window system is running.  We need to run different versions of
the same program when under X Windows or SunView.  Ways to detect
Sun's X News server and MIT X would be helpful as well.

I will summarize to comp.windows.misc.

Thanks!

-- 

 --------------------------------------------------------------------
| Ken Nelson  (nelson@wrl.epi.com) | No thoughts today, sorry.	     | 
| Computer Systems Manager         |				     |
| Entropic Research Laboratory     |				     |	
| Washington, D.C.		   |				     |
|--------------------------------------------------------------------

mouse@lightning.mcrcim.mcgill.EDU (der Mouse) (04/13/91)

> I am looking for scripts or ideas for how to detect what window
> system is running.  We need to run different versions of the same
> program when under X Windows or SunView.

(Assuming that by "X Windows" you mean The X Window System, or X for
short....)

The usual thing to do is to check for DISPLAY in the environment, which
implies X, or WINDOW_PARENT, which implies SunView.  (If both are set,
you are probably in some environment where either one will work, so use
whichever provides a better interface for your program.)

> Ways to detect Sun's X News server and MIT X would be helpful as
> well.

Check the vendor string (see XServerVendor() and possibly
XVendorRelease() in the Xlib documentation).  The MIT server I'm using
now returns "MIT X Consortium" and "4", at least according to xdpyinfo.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

flaps@dgp.toronto.edu (Alan J Rosenthal) (04/17/91)

nelson@wrl.epi.com (Ken Nelson) writes:
>I am looking for scripts or ideas for how to detect what
>window system is running.  We need to run different versions of
>the same program when under X Windows or SunView.

You could always just put only the correct one in people's paths.  The startup
script for the window system can add something to their path, or something like
that.  Alternatively, you could go with the semi-standard of calling them
"xmyprog" and "myprog".

If you want to write a shellscript to detect this, in this particular case you
could use the $TERM variable, i.e. the shellscript would run something like
/dist/$TERM/myprog.

Generally speaking, for most systems like that, there is some sort of
initialization sequence all programs have to go through, and it fails if the
window system isn't running.  Therefore you can write a program which works
under both by attempting to use one window system and then the other.  [I've
never done this personally, although I have written programs which use either
the window system or the terminal emulator.]  Or in this particular case, you
could do a getenv("TERM") and see if it's "sun" or "xterm".  I think I prefer
the separate binaries, though, personally.

ajr

guy@auspex.auspex.com (Guy Harris) (04/20/91)

>Or in this particular case, you could do a getenv("TERM") and see if it's
>"sun" or "xterm".

Umm, well, it could be "sun" if you're running under X; "shelltool"
*does* come in a version that runs under X....