Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!samsung!usc!ucsd!ucbvax!ucdavis!csusac!unify!Unify.com!grp From: grp@Unify.com (Greg Pasquariello) Newsgroups: comp.windows.x Subject: Re: UNIX/X-windows questions Message-ID: <1991Jan28.105219@Unify.com> Date: 28 Jan 91 18:52:19 GMT References: <139@bwilab3.UUCP> <1441@rascal.UUCP> <960@redford.UUCP> <99@tdatirv.UUCP> Sender: news@Unify.Com (news admin) Reply-To: grp@Unify.com (Greg Pasquariello) Organization: Unify Corporation, Sacramento, CA, USA Lines: 36 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