Path: utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!bu.edu!polygen!bill From: bill@polygen.uucp (Bill Poitras) Newsgroups: comp.windows.x Subject: Re: UNIX/X-windows questions Message-ID: <960@redford.UUCP> Date: 22 Jan 91 15:28:49 GMT References: <139@bwilab3.UUCP> <1441@rascal.UUCP> Reply-To: bill@redford.UUCP (Bill Poitras(X258)) Organization: Polygen Corporation, Waltham, MA Lines: 31 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 | +-----------------+---------------------------+-----------------------------+