chris@bwilab3.UUCP (Chris Curtin) (01/08/91)
I have two simple questions, both of which deal with X windows. (One has to do with UNIX enviornment variables, so the cross post). First the UNIX/X question: I have a application that needs to know the WINDOWID of the window that it is being run in. So far no problems. BUT when I log into one machine, the server, then tell the window manager to create a window on another machine the WINDOWID is lost. I suspect it has to do with how the server is creating the window and logging in. Now the question: Is it possible to pass this WINDOWID when the server logs in? I know this has little to do with X but maybe someone has run into this before. Now the X question: We have ported a number of ASCII based programs to X windows and thus have two versions of the same code. A large installed base and demand for the ASCII versions have caused this problem. Question: Is it possible to tell if the program is running in an X enviornment? Most enviornment variables will not work since some are set in .login files. The WINDOWID is also not valid since some programs do not have access to it. (See above) Is there a call to see if we are in X? I would rather not do a simple call and see if it fails since this is a hack and doesn't look too good. Thanks in advance for any and all help Christopher M. Curtin -- Christopher M. Curtin Bradley Ward, Inc. gatech!galbp!bwilab3!chris 5901-A Peachtree Dunwoody Rd Atlanta, Ga 30350 -- -- Christopher M. Curtin Bradley Ward, Inc. gatech!galbp!bwilab3!chris 5901-A Peachtree Dunwoody Rd Atlanta, Ga 30350
theo@rascal.UUCP (T. Kramer) (01/15/91)
In article <139@bwilab3.UUCP> chris@bwilab3.UUCP (Chris Curtin) writes: > > >I have two simple questions, both of which deal with X windows. (One has >to do with UNIX enviornment variables, so the cross post). > >Now the X question: > >Is there a call to see if we are in X? I would rather not do a simple call >and see if it fails since this is a hack and doesn't look too good. > How about setting an environment variable eg. TERM=xterm for the X logins and TERM=vt100 for character based terminal logins. You of course have to know which tty lines support X terminals and which do not. Then using the following on startup if (!strcmp("xterm",getenv("TERM"))) XtInitialise(); /* Xt Intrinsic call */ else initscr(); /* Curses call */ +------------------------------+--------------------------------------------+ | theo@rascal | You should have seen my EX screen manager! | +------------------------------+--------------------------------------------+
razdan@phx.mcd.mot.com (Anshuman Razdan) (01/21/91)
In article <1991Jan18.075159.26771@eng.umd.edu> stripes@eng.umd.edu (Joshua Osborne) writes: In article <1441@rascal.UUCP>, theo@rascal.UUCP (T. Kramer) writes: > In article <139@bwilab3.UUCP> chris@bwilab3.UUCP (Chris Curtin) writes: > > > > > >I have two simple questions, both of which deal with X windows. (One has > >to do with UNIX enviornment variables, so the cross post). > > > >Now the X question: > > > >Is there a call to see if we are in X? I would rather not do a simple call > >and see if it fails since this is a hack and doesn't look too good. > > > How about setting an environment variable eg. TERM=xterm for the X logins > and TERM=vt100 for character based terminal logins. You of course have to > know which tty lines support X terminals and which do not. > > Then using the following on startup > > if (!strcmp("xterm",getenv("TERM"))) > XtInitialise(); /* Xt Intrinsic call */ > else > initscr(); /* Curses call */ In my XView shelltool window my TERM variable is sun-cmd, not xterm. If I start X by "logging-in" from xdm my TERM variable will not be set for programs my window manager starts for me, or my .xsession script starts, and that's most all of the X I run form day to day. Users of dxterm may be using anything from vt52 to vt340 for TERM. Besides you missed my common setting for TERM: xterms-notite (Small [25x80] xterm with no tite [page flipping]). -- stripes@eng.umd.edu "Security for Unix is like ------------------------- ------------------------- Am I missing something or ..... Couldn't this be done by just trying to do a XOpenDisplay and if this returns NULL or error (whatever the case may be) you are not in X and should assume for all purposes not to do any X related stuff. -- Anshuman Razdan ************************************************************ * razdan@toy Test and Methodology Group * * * * razdan@phx.mcd.mot.com Diablo Plant, Tempe Az * ************************************************************
bill@polygen.uucp (Bill Poitras) (01/22/91)
In article <1441@rascal.UUCP> theo@rascal.UUCP (T. Kramer) writes: >In article <139@bwilab3.UUCP> chris@bwilab3.UUCP (Chris Curtin) writes: >>Is there a call to see if we are in X? I would rather not do a simple call >>and see if it fails since this is a hack and doesn't look too good. > >if (!strcmp("xterm",getenv("TERM"))) You wouldn't always be garenteed that the term is set to xterm. Especially if you are using aixterm (AIX IBM's version of unix), or cmdtool within Open Windows. The best way is to try to open the display XOpenDisplay(":0.0"). If it returns NULL, then you can't connect to the server, whether it is there or not. I don't think that this is a kludgy way to do it. It is basically asking "Are you there X?", and X either says "Yes, and here is my display address", or no response (NULL). It is one call. Its simple. An example piece of code would be: if ((display = XOpenDisplay(":0.0")) == NULL) initscr(); /* Curses */ else { XCloseDisplay(display); /* Your real X initialization goes here. Presumably a call to XInitialize. If you are using just Xlib calls, the XCloseDisplay call are not necessary, and you can refer to the display with the above "display" variable */ +-----------------+---------------------------+-----------------------------+ | Bill Poitras | Polygen Corporation | {princeton mit-eddie | | (bill) | Waltham, MA USA | bu sunne}!polygen!bill | | | FAX (617)890-8694 | bill@polygen.com | +-----------------+---------------------------+-----------------------------+
mouse@larry.mcrcim.mcgill.EDU (01/24/91)
>>> Is there a call to see if we are in X? >> if (!strcmp("xterm",getenv("TERM"))) Or mterm, or aixterm, or sun, or any of the many other possible values of $TERM when running under X.... > The best way is to try to open the display XOpenDisplay(":0.0"). Except that you may be in X, but the server may not be on the machine you're trying to run the program on. I would say that if -display is on the command line, use it. Otherwise check for DISPLAY in the environment, and if set, use it; otherwise, assume X is not available. This also allows the user to avoid using X even when available, by unsetting DISPLAY in the environment. (Yes, this is sometimes desirable.) der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu
sarima@tdatirv.UUCP (Stanley Friesen) (01/25/91)
In article <RAZDAN.91Jan21101031@behemoth.phx.mcd.mot.com> razdan@phx.mcd.mot.com (Anshuman Razdan) writes: >In article <1991Jan18.075159.26771@eng.umd.edu> stripes@eng.umd.edu (Joshua Osborne) writes: > In article <1441@rascal.UUCP>, theo@rascal.UUCP (T. Kramer) writes: > > In article <139@bwilab3.UUCP> chris@bwilab3.UUCP (Chris Curtin) writes: > > >Is there a call to see if we are in X? I would rather not do a simple call > > >and see if it fails since this is a hack and doesn't look too good. > > How about setting an environment variable eg. TERM=xterm for the X logins > > and TERM=vt100 for character based terminal logins. > In my XView shelltool window my TERM variable is sun-cmd, not xterm. Quite true. This whole thing seems to be getting overly clever. I have simply used the environment variable DISPLAY, since almost all startup mechanisms I know set it (including xinit and xdm). Why mess around with stuff that does not really have anything to do with X, stick with: if(getenv("DISPLAY") != NULL) { /* We are running under X */ } else { /* We are running in a ''terminal' *. } -- --------------- uunet!tdatirv!sarima (Stanley Friesen)
sarima@tdatirv.UUCP (Stanley Friesen) (01/26/91)
In article <960@redford.UUCP> bill@redford.UUCP (Bill Poitras(X258)) writes: >>In article <139@bwilab3.UUCP> chris@bwilab3.UUCP (Chris Curtin) writes: >>>Is there a call to see if we are in X? ... >The best way is to try to open the display XOpenDisplay(":0.0"). If it >returns NULL, then you can't connect to the server, whether it is there >or not. The problem with this is that it assumes the application and the X server are on the same machine! A chancy assumption at best, given the design of X. I would try to use something like: dp = getenv(DISPLAY); display = XOpenDisplay(dp); if(display == NULL) { /* use curses or something */ } else { /* Initialize your X toolkit */ } -- --------------- uunet!tdatirv!sarima (Stanley Friesen)
grp@Unify.com (Greg Pasquariello) (01/29/91)
In article <99@tdatirv.UUCP>, sarima@tdatirv.UUCP (Stanley Friesen) writes: > In article <960@redford.UUCP> bill@redford.UUCP (Bill Poitras(X258)) writes: > >>In article <139@bwilab3.UUCP> chris@bwilab3.UUCP (Chris Curtin) writes: > >>>Is there a call to see if we are in X? ... > > >The best way is to try to open the display XOpenDisplay(":0.0"). If it > >returns NULL, then you can't connect to the server, whether it is there > >or not. > > The problem with this is that it assumes the application and the X server > are on the same machine! A chancy assumption at best, given the design of X. > I would try to use something like: > > dp = getenv(DISPLAY); > display = XOpenDisplay(dp); > if(display == NULL) > { > /* use curses or something */ > } > else > { > /* Initialize your X toolkit */ > } No, use XOpenDisplay(NULL). That will do the job of the getenv for you. If the open fails, NULL will be returned. > -- > --------------- > uunet!tdatirv!sarima (Stanley Friesen) -- --- Greg Pasquariello Unify Corporation grp@Unify.Com
stripes@eng.umd.edu (Joshua Osborne) (01/30/91)
In article <96@tdatirv.UUCP>, sarima@tdatirv.UUCP (Stanley Friesen) writes: > Quite true. This whole thing seems to be getting overly clever. > I have simply used the environment variable DISPLAY, since almost all > startup mechanisms I know set it (including xinit and xdm). > > Why mess around with stuff that does not really have anything to do with X, > stick with: > > if(getenv("DISPLAY") != NULL) > { > /* We are running under X */ > } > else > { > /* We are running in a ''terminal' *. > } Well, that will work more offen then most trys... it will still die when I login on a non-X terminal. I try to set DISPLAY in my .login, sometime I don't get it right. I supose I could try harder... anyway I can allways unsetenv DISPLAY before using whatever it is you wrote, just like I would have to if I used emacs. (I still think checking for a succesful XOpenDisplay & providing a "Don't use X" flag would be the best choice) -- stripes@eng.umd.edu "Security for Unix is like Josh_Osborne@Real_World,The Multitasking for MS-DOS" "The dyslexic porgramer" - Kevin Lockwood "CNN is the only nuclear capable news network..." - lbruck@eng.umd.edu (Lewis Bruck)
mouse@lightning.mcrcim.mcgill.EDU (02/01/91)
>> dp = getenv(DISPLAY); >> display = XOpenDisplay(dp); > No, use XOpenDisplay(NULL). Well, XOpenDisplay((char *)NULL), unless you want to ignore sites using pre-ANSI C compilers, or that don't have prototyped X include files. (Or, of course, XOpenDisplay((char *)0)....) > That will do the job of the getenv for you. It should also do the analogous thing on systems without getenv(), which keep the default display name somewhere else. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu