This is the mail archive of the
cygwin-apps
mailing list for the Cygwin project.
Re: ITP: rxvt-W
Charles Wilson wrote:
> int main() {
> int rc;
> Display* dpy = XOpenDisplay(NULL); /* null lets XOpenDisplay handle
> querying for $DISPLAY */
> rc = !(dpy == NULL);
> if (dpy) XCloseDisplay(dpy);
> return rc; /* exits with status of 0 if X available */
> }
[snip]
>
> I'd also need to fiddle with PATH just-in-case /usr/X11R6/bin isn't in
> the system PATH, before running X-test-app or X-hosted, but those are
> refinements. Doing all this in a .bat file will be...interesting.
>
> Just had another thought: instead of the five-line app above, I could
> steal a page from current rxvt, and dlopen(cygX11-[6,7,8,9].dll), dlsym
> ONLY XOpenDisplay and XCloseDisplay, and THEN do the five lines. Then
> my app really wouldn't explicitly depend on xorg-x11-bin-dlls, AND I'd
> avoid needing to call grep and cygcheck from a .bat file, (do pipes work
> .bat files?), AND I wouldn't need to "hide" X-test-app.
Well, it took a bit more than just five lines, to Do It Right. See
attached code...
-----------
checkX determines if X is installed and Xserver is running
returns 0 if yes, nonzero otherwise
Options:
-h|--help : prints this help message
-d|--display S : use S instead of $DISPLAY
-l|--location : print location of Xlib DLL on stdout
-a|--appendpath S : append S to value of $PATH (cumulative)
-p|--prependpath S : prepend S to value of $PATH (cumulative)
-r|--replacepath S : use S instead of $PATH when searching
-x|--xlibname S : use exactly S instead of cygX11-*.dll search
-t|--timeout FLT : allow FLT seconds to connect with Xserver
defaults to 0.5, use 0.0 for Xlib's (safe, 12s) timeout
--nogui : disable informational popups
--notty : disable stderr messages
--debug : turn on debugging messages
--no-silent : allow error, warning, and info messages
Note that -a defaults to '/usr/bin:/usr/X11R6/bin'. To eliminate the
default, use '-a ""'
-----------
As compiled with the attached makefile, checkX is silent, and all it
really does is return a status (0 or 1). There are no popups or stderr
messages. However, --no-silent is useful for displaying WHY a failure
code was returned ("couldn't find dll", "couldn't connect to $DISPLAY",
etc). --notty turns off any stdio output, forcing MessageBoxes (not
that it matters in silent mode).
The --timeout option was necessary because if the Xserver is not
running, but $DISPLAY is set and cygX11-*.dll is found, then
XOpenDisplay() takes WAY too long. 12 - 15 seconds. So, I spun a
separate thread to call XOpenDisplay and the main thread detaches it if
it doesn't answer back soon enough. The default timeout of 0.5s seems
to work well: it's not too short [*] and it's not annoyingly long either.
[*] Too short would be if the main thread gave up faster than a
*successful* call to a running, local, Xserver takes. Too short on my
machine was "0.01" (0.02 seemed to work most of the time). But, other
machines may not be as responsive, so 0.5 seemed okay.
Note that if DISPLAY is unset, then there is no long delay; XOpenDisplay
returns immediately. The only long delay is if you have DISPLAY set,
(say, to ":0" like the current rxvt wants) but there is no actual
XServer running.
-----
Now, this is obviously not yet needed, although one could write a script
to switch between rxvt-unicode-X and current rxvt, so that current rxvt
is only used in native mode. But, current rxvt doesn't know how to hide
its console after the fact....
That is, if you have a symlink to a script (foo.bat or
'C:/cygwin/bin/bash.exe -c foo.sh') then a console window WILL get
created to run that script itself. It doesn't matter if you then say
"run.exe rxvt.exe" to launch the current rxvt -- you're still stuck with
the existing console.
-----
Anyway, I plan to incorporate the checkX program into my
rxvt-unicode-common package and roll out a -2 release. But in the
meantime, can I get a GTG for xsri and rxvt-unicode-X?
--
Chuck
Attachment:
checkX.tar.bz2
Description: Binary data