Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

comp.windows.x.intrinsics Frequently Asked Questions (FAQ)
Section - 18. How do I open multiple displays?

( Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Zip codes ]


Top Document: comp.windows.x.intrinsics Frequently Asked Questions (FAQ)
Previous Document: 17. How do I write a resource converter?
Next Document: 19. What changed from R3 to R4 to R5?
See reader questions & answers on this topic! - Help others by sharing your knowledge
----------------------------------------------------------------------

See "Multi-user Application Software Using Xt", The X Resource, Issue 3,
(Summer 1992) by Oliver Jones for a complete coverage of the issues
involved.  Most of this answer is based on that article.  In a
nutshell, one uses XtOpenDisplay() to add each display to a _single_
application context and then XtCloseDisplay() to shutdown each display
and remove it from the application context.

The real problems occur when trying to close down a display.  This can
happen 3 ways:
	1. User selects a "quit" button on one of the displays,
	2. User has window manager send a WM_DELETE_WINDOW message,
	3. Server disconnect -- possibly from a KillClient message,
	   server shutdown/crash, or network failure.

I'll assume you can deal gracefully with 1 & 2 since it is _merely_ a
problem of translating a Widget to a display and removing that
display.  If not, then read the Oliver Jones article.

The third one is difficult to handle.  The following is based on the
Oliver Jones article and I include it here because it is a difficult
problem.

The difficulty arises because the Xlib design presumed that an I/O
error is always unrecoverable and so fatal.  This is essentially true
for a single display X based application, but not true for a
multiple display program or an application that does things other than
display information on an X server.  When an X I/O error occurs the
I/O error handler is called and _if_ it returns then an exit()
happens.  The only way around this is to use setjmp/longjmp to avoid
returning to the I/O error handler.  The following code fragment
demonstrates this:

#include <setjmp.h>
jmp_buf XIOrecover;

void
XIOHandler (dpy)
	Display		*dpy;
{
	destroyDisplay (dpy);
	longjmp (XIOrecover, 1);
}

main ()
{
	...
	if (setjmp (XIOrecover) == 0)
		XSetIOErrorHandler (XIOHandler);
	XtAppMainLoop (app_context);
}

The destroyDisplay() is something that given a Display pointer can go
back to the application specific data and perform any necessary
cleanup.  It should also call XtCloseDisplay().

For those of you unfamiliar with setjmp/longjmp, when setjmp() is
first called it returns a 0 and save's enough information in the
jmp_buf that a latter execution of longjmp() can return the program to
the same state as if the setjmp() was just executed.  The return value
of this second setjmp() is the value of the second argument to
longjmp().  There are several caveats about using these but for this
purpose it is adequate.

Some other problems you might run into are resource converters that
improperly cache resources.  The most likely symptoms are Xlib errors
such as BadColor, BadAtom, or BadFont.  There may be problems with the
total number of displays you can open since typically only a limited
number of file descriptors are available with 32 being a typical
value.  You may also run into authorization problems when trying to
connect to a display.

There was much discussion in comp.windows.x about this topic in
November of 91.  Robert Scheifler posted an article which basically
said this is the way it will be and Xlib will not change.

User Contributions:

Comment about this article, ask questions, or add new information about this topic:




Top Document: comp.windows.x.intrinsics Frequently Asked Questions (FAQ)
Previous Document: 17. How do I write a resource converter?
Next Document: 19. What changed from R3 to R4 to R5?

Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
ware@cis.ohio-state.edu





Last Update March 27 2014 @ 02:11 PM