[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: check if X is running?

> I think another way to do it is to build two seperate binaries.  For
> example, create xprog and prog, one that is X-only, and another that is
> console-only.  This allows the user to specifcally set which version they
> want, and it might also reduce the amount of code needed per program and
> speed it up a bit.  Downside is, tho, you have to actually seperate the
> code for both programs, and keep them updated at the same time (or just
> share .c files... however you please.).  Anyway.  As far as detection, I
> dunno, but hope this helps. 

As far as detection is concerned, this is a bit tricky point. The main problem
is what you really want to check? I can imagine the situation when i logged to
remote machine over slow line and have $DISPLAY set properly, but I don't want
to use X version of the program - it would be too slow.
In any case, to check whether X is at all available:


Display* td=XOpenDisplay(NULL);
} else {
  /* HAVE X */

This is not bullet-proof though since DISPLAY may be specified in the 
options - then it is better use that DISPLAY string instead of NULL
(as an argument to XOpenDisplay, otherwile it would only pick DISPLAY 
from environment). On the other hand, if user specifies DISPLAY in the 
options, s/he definitely wants X version and the program should just go X way
and fail if not possible.

Alex Y.
 _( )_
(     (o___           +-------------------------------------------+
 |      _ 7           |            Alexander Yukhimets            |
  \    (")            |       http://pages.nyu.edu/~aqy6633/      |
  /     \ \           +-------------------------------------------+

Reply to: