[comp.windows.x] Detection which windowing system I'm in

pp@wsinti01.info.win.tue.nl (Peter Peters) (02/19/91)

Can anyone shed some light on the following problem :

I have a window labelling mechanism (to change the headers
in the window title bar) that I want to use when in open windows
and/or sunview. To be able to do so, I have to know whether I'm in
a window manager or not. All of this is possible using checks on 
environment variables, but these checks ar not 100%.
Anyone can define e.g. OPENWINHOME or LD_LIBRARY_PATH to be
whatever they want, so the existence of these environment variables
do not ensure you are in open windows. So what are the correct
methods to determine if I'm

1 - on the bare console. (I'm using `tty` == /dev/console right now)
2 - in sunview
3 - in open windows
4 - remote logged in via 1..3

And these cases should all be distinguishable....

Any pointers will be appreciated.


-- 
| Peter Peters                              | UUCP  : pp@win.tue.nl     |
| Eindhoven University of Technology (TUE)  | PHONE : +31-(0)40-474120  |
| Dept. of Mathematics and Computer Science | TUE   : HG 8.82 / 4120    |
| Disclaimer : I said WHAT ???              | VHF   : pa0ppe            |

guy@auspex.auspex.com (Guy Harris) (02/26/91)

>If $TERM is set to "xterm" I can expect to be in Xwindows.
>If $TERM is set to "sun-cmd" I am in a SunView CommandTool window.

Or in an XView commandtool window - i.e., if TERM is set to "sun-cmd",
you could well be running in X.

>If $TERM is set to "sun" and...
>      $?WINDOW_ME is true I am in a SunView ShellTool window...

See previous paragraph.

Note also that you are likely to be in X if TERM is set to "tm19",
say....

I.e., there are a number of terminal emulator programs that run under X;
"xterm" may be the most popular, but it sure ain't the only one.

On top of that, note that if you rlogin to another UNIX machine, say,
that has no X support but that does have an "xterm" entry in "termcap"
or "terminfo", TERM will be set to "xterm" but you won't be "in X" in
the general sense (i.e., you won't be able to fire up some X application
on that machine).

belinfan@cs.utwente.nl (Axel Belinfante) (03/01/91)

In article <1768@svin02.info.win.tue.nl>, pp@wsinti01.info.win.tue.nl (Peter Peters) writes:
[introduction deleted]
|>  So what are the correct
|> methods to determine if I'm
|> 
|> 1 - on the bare console. (I'm using `tty` == /dev/console right now)
|> 2 - in sunview
|> 3 - in open windows
|> 4 - remote logged in via 1..3
|> 
|> And these cases should all be distinguishable....
|> 
|> Any pointers will be appreciated.
|> 
|> 
|> -- 
|> | Peter Peters                              | UUCP  : pp@win.tue.nl     |
|> | Eindhoven University of Technology (TUE)  | PHONE : +31-(0)40-474120  |
|> | Dept. of Mathematics and Computer Science | TUE   : HG 8.82 / 4120    |
|> | Disclaimer : I said WHAT ???              | VHF   : pa0ppe            |

Some time ago i wrote a couple of small C programs that test if
X windows or sunview is running. They simply try to open a window and
return the corresponding error status.
They are called SUNVIEWrunning (tests whether sunview runs) and
X11running (tests whether X11 runs or not). I also included below a shorter
version of X11running, Xt11running that uses XtInitialize instead
of XOpenDisplay.
I put a shar file of those programs below. (Or should i only mention them
here and post the programs in comp.sources.x?)

With respect to the remote login problem... if you pass over the DISPLAY
env var during the remote login, X11running will do its job as expected.
SUNVIEWrunning will not work, however: it will try to open a window at
the console of the *remote* machine!
We fiddle a little bit with the TERM env var to pass over the DISPLAY
env var in a rlogin, in a similar way as has been discussed in this group
some time ago.

I hope this helps.

#!/bin/sh
# This is a shell archive (shar 3.47)
# made 03/01/1991 09:41 UTC by belinfan@utis90
# Source directory /home/tools/belinfan/src/lie/Window
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#    349 -rw-r----- SUNVIEWrunning.c
#    448 -rw-r----- X11running.c
#    621 -rw-r----- Xt11running.c
#
# ============= SUNVIEWrunning.c ==============
if test -f 'SUNVIEWrunning.c' -a X"$1" != X"-c"; then
	echo 'x - skipping SUNVIEWrunning.c (File already exists)'
else
echo 'x - extracting SUNVIEWrunning.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'SUNVIEWrunning.c' &&
/* to compile: cc -o SUNVIEWrunning SUNVIEWrunning.c -lsuntool -lsunwindow -lpixrect */
X
#include <suntool/sunview.h>
#include <stdio.h>
X
main()
{
X    Frame frame;
X
X    frame = window_create(NULL, FRAME, 0);
X    if (! frame) {
X	printf( "SunView is not running\n" );
X	exit( 1 );
X    }
X    else {
X	printf( "SunView is running\n");
X	exit( 0 );
X    }
}
SHAR_EOF
chmod 0640 SUNVIEWrunning.c ||
echo 'restore of SUNVIEWrunning.c failed'
Wc_c="`wc -c < 'SUNVIEWrunning.c'`"
test 349 -eq "$Wc_c" ||
	echo 'SUNVIEWrunning.c: original size 349, current size' "$Wc_c"
fi
# ============= X11running.c ==============
if test -f 'X11running.c' -a X"$1" != X"-c"; then
	echo 'x - skipping X11running.c (File already exists)'
else
echo 'x - extracting X11running.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'X11running.c' &&
/* to compile:  cc -o X11running -I/Window/X11/include X11running.c -lX11 */
X
#include <X11/Xlib.h>
#include <stdio.h>
X
main()
{
X    Display *dpy;
X    char *displayname;
X
X    displayname = (char *) NULL;
X    dpy  = XOpenDisplay( displayname );
X    if (! dpy) {
X	printf( "X11 is not running\n" );
X	exit( 1 );
X    }
X    else {
X        XCloseDisplay( dpy );
X	printf( "X11 is running on display %s\n", XDisplayName( displayname ));
X	exit( 0 );
X    }
}
SHAR_EOF
chmod 0640 X11running.c ||
echo 'restore of X11running.c failed'
Wc_c="`wc -c < 'X11running.c'`"
test 448 -eq "$Wc_c" ||
	echo 'X11running.c: original size 448, current size' "$Wc_c"
fi
# ============= Xt11running.c ==============
if test -f 'Xt11running.c' -a X"$1" != X"-c"; then
	echo 'x - skipping Xt11running.c (File already exists)'
else
echo 'x - extracting Xt11running.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'Xt11running.c' &&
/* to compile:  cc -o X11running -I/Window/X11/include X11running.c -lX11 */
X
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <stdio.h>
X
main(argc, argv) int argc; char *argv[];
{
/*
X    Display *dpy;
X    char *displayname;
X
X    displayname = (char *) NULL;
X    dpy  = XOpenDisplay( displayname );
X    if (! dpy) {
X	printf( "X11 is not running\n" );
X	exit( 1 );
X    }
X    else {
X        XCloseDisplay( dpy );
X	printf( "X11 is running on display %s\n", XDisplayName( displayname ));
X	exit( 0 );
X    }
X */
X    XtInitialize( "main", "xT11running", 0, 0, &argc, argv );
X    exit( 0 );
}
SHAR_EOF
chmod 0640 Xt11running.c ||
echo 'restore of Xt11running.c failed'
Wc_c="`wc -c < 'Xt11running.c'`"
test 621 -eq "$Wc_c" ||
	echo 'Xt11running.c: original size 621, current size' "$Wc_c"
fi
exit 0

--
    ___				                         "Dirlididi! -- piv"
 __/   \__________  Axel Belinfante          <Axel.Belinfante@cs.utwente.nl>
|  \___/          | University of Twente                  tfx. +31 53 333815
|___     __   ___ | Tele-Informatics & Open Systems       tel. +31 53 893774
| |  |  /  \ (__  | P.O. Box 217    NL-7500 AE Enschede      The Netherlands
| |__|__\__/____) | "Als das Kind Kind war, wusste es nicht das es Kind war,
|_________________|  alles war ihm beseelt, und die Seelen waren eins."