Mapper
Wait.c
Go to the documentation of this file.
1 /*
2  * Motif Tools Library, Version 2.0
3  * $Id: Wait.c,v 2.10 1994/07/04 03:03:50 david Exp $
4  *
5  * Written by David Flanagan.
6  * Copyright (c) 1992, 1993, 1994 by Dovetail Systems.
7  * All Rights Reserved. See the file COPYRIGHT for details.
8  * This is not free software. See the file SHAREWARE for details.
9  * There is no warranty for this software. See NO_WARRANTY for details.
10 
11 
12 #include <Xmt/Xmt.h>
13 #include <Xmt/Util.h>
14 
15 
16  * The following procedure is by David Brooks of the OSF and appears in
17  * the Motif FAQ list. It has been renamed for the Xmt library.
18  */
19 
20 /*
21  * This procedure will ensure that, if a dialog window is being mapped,
22  * its contents become visible before returning. It is intended to be
23  * used just before a bout of computing that doesn't service the display.
24  * You should still call XmUpdateDisplay() at intervals during this
25  * computing if possible.
26  *
27  * The monitoring of window states is necessary because attempts to map
28  * the dialog are redirected to the window manager (if there is one) and
29  * this introduces a significant delay before the window is actually mapped
30  * and exposed. This code works under mwm, twm, uwm, and no-wm. It
31  * doesn't work (but doesn't hang) with olwm if the mainwindow is iconified.
32  *
33  * The argument to ForceDialog is any widget in the dialog (often it
34  * will be the BulletinBoard child of a DialogShell).
35  */
36 
37 #include "prototypes_new.h"
38 
39 void XmtWaitUntilMapped(Widget w)
40 
41 {
42  Widget diashell, topshell;
43  Window diawindow, topwindow;
44  Display *dpy;
45  XWindowAttributes xwa;
46  XEvent event;
47  XtAppContext cxt;
48 
49  for (diashell = w; !XtIsShell(diashell); diashell = XtParent(diashell)) ;
50  for (topshell = diashell;
51  !XtIsTopLevelShell(topshell);
52  topshell = XtParent(topshell));
53 
54  if (XtIsRealized(diashell) && XtIsRealized(topshell)) {
55  dpy = XtDisplay(topshell);
56  diawindow = XtWindow(diashell);
57  topwindow = XtWindow(topshell);
58  cxt = XtWidgetToApplicationContext(diashell);
59 
60  /* Wait for the dialog to be mapped. */
61  while (XGetWindowAttributes(dpy, diawindow, &xwa),
62  xwa.map_state != IsViewable) {
63 
64  /*
65  * unless the primary is (or becomes) unviewable or unmapped, it's
66  * probably iconified, and nothing will happen.
67  * We make an exception to this case when topwindow==diawindow
68  */
69  if ((topwindow != diawindow) &&
70  (XGetWindowAttributes(dpy, topwindow, &xwa),
71  xwa.map_state != IsViewable))
72  break;
73 
74  /*
75  * At this stage, we are guaranteed there will be
76  * an event of some kind. Beware; we are presumably
77  * in a callback, so this can recurse.
78  */
79  XtAppNextEvent(cxt, &event);
80  XtDispatchEvent(&event);
81  }
82  }
83 
84  /* The next XSync() will get an expose event if the dialog was unmapped. */
85  XmUpdateDisplay(topshell);
86 }
void XmtWaitUntilMapped(Widget w)
Definition: Wait.c:39