Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!utrcu1!infnews!infnews!belinfan From: belinfan@cs.utwente.nl (Axel Belinfante) Newsgroups: comp.windows.x Subject: Re: Detection which windowing system I'm in Keywords: open windows,sunview,bare terminal Message-ID: <1991Mar1.103144@cs.utwente.nl> Date: 1 Mar 91 09:31:44 GMT References: <1768@svin02.info.win.tue.nl> Sender: usenet@cs.utwente.nl Reply-To: belinfan@cs.utwente.nl (Axel Belinfante) Organization: University of Twente, Dept. of Computer Science Lines: 173 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 #include 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 #include 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 #include #include #include 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 | \___/ | 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."