[comp.windows.x] Summary: Detecting which window system

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

Thanks to all who replied.  In general most recommended detecting
standard environment variables in use by each window system. 
One problem with that approach is that sometimes variables 
like DISPLAY are set in the users .cshrc all the time, even
when SunView is used. 

I will be using a combination of environment variables, scripts and
C programs that poke and prod to see what is running. 

Here is the summary of responses:

>>> Misc:54

Date:    Fri, 12 Apr 91 13:56:55 -0700 
From:    Edward Dergharapetian <uunet!math.ucla.edu!edward>
Subject: Re: Ways to detect what window system is running.

In article <963@epiwrl.UUCP> you write:
>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.

Here's a common algorithm based on environment variables:

if $DISPLAY is defined
	then you're running X windows.
elif $WINDOW_PARENT is defined
	then you're running sunview.
elif $NEWS_SERVER is defined
	then you're running Sun NeWS.
else You're not using a window system I'm familiar with.

I don't know how to distinguish Sun's xnews vs. MIT's X server, but
I'm sure a similar mechanism exists.

>| Ken Nelson  (nelson@wrl.epi.com) | No thoughts today, sorry.	     | 

edward.



>>> Misc:55

Date:    Fri, 12 Apr 91 13:58:16 -0600 
From:    CADSI <uunet!cadfx.ccad.uiowa.edu!cadsi>
Subject: Re: Ways to detect what window system is running.

nelson@wrl.epi.com (Ken Nelson):
> 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.
> 

In order to check for X availability, just attempt to open the Display.
if the OpenDisplay call is successful, X is there.  If now, it is not
running.  This is not via scripts however, just via C code.  Thus, 
you sould write yourself a little program that exits(1) if X is
available or exits(0) if not.  Then the shell scripts could check this
little programs exit status and branch accordingly.

						Tom Hite



>>> Misc:56

Date:    Fri, 12 Apr 91 23:54:54 -0400 
From:    der Mouse <uunet!lightning.McRCIM.McGill.EDU!mouse>
Subject: Re: Ways to detect what window system is running.

> 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



>>> Misc:57

Date:    Mon, 15 Apr 91 17:32:32 -0700 
From:    uunet!auspex.com!guy (Guy Harris)
Subject: Re: Ways to detect what window system is running.

>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.

The best thing to do is probably to assume you're running under SunView
if the WINDOW_PARENT environment variable is set, and that you're
running under X if the DISPLAY environment variable is set.

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

The best I can suggest is to have a small program call "XOpenDisplay()",
and then look at what "ServerVendor()" and/or "VendorRelease()" return
when handed the return value from "XOpenDisplay()".  Unfortunately, this
means your program will have to know what values the MIT and Sun servers
return, and those are subject to change....

There *might* be some environment variable that the stuff that starts up
Open Windows sets (e.g. NEWSSERVER), but I don't know whether you can
*count* on it *always* being set if you're running under Open Windows. 
What is the reason why your program cares?  There may be a better way of
finding out what it really wants to know....


-- 

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

jsb@cs.brown.edu (John Bazik) (04/23/91)

In article <1015@epiwrl.UUCP>, nelson@wrl.epi.com (Ken Nelson) writes:
|> 
|> Here's a common algorithm based on environment variables:
|> 
|> if $DISPLAY is defined
|> 	then you're running X windows.
|> elif $WINDOW_PARENT is defined
|> 	then you're running sunview.
|> elif $NEWS_SERVER is defined
|> 	then you're running Sun NeWS.
|> else You're not using a window system I'm familiar with.
|> 
|> I don't know how to distinguish Sun's xnews vs. MIT's X server, but
|> I'm sure a similar mechanism exists.

We check for $OPENWINHOME to differentiate X/NeWS from X11R4.  It's
defined for the former.  Useful for setting font paths.

John Bazik
jsb@cs.brown.edu