File: Wait.c

package info (click to toggle)
gridengine 6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 51,532 kB
  • ctags: 51,172
  • sloc: ansic: 418,155; java: 37,080; sh: 22,593; jsp: 7,699; makefile: 5,292; csh: 4,244; xml: 2,901; cpp: 2,086; perl: 1,895; tcl: 1,188; lisp: 669; ruby: 642; yacc: 393; lex: 266
file content (97 lines) | stat: -rw-r--r-- 2,989 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* 
 * Motif Tools Library, Version 3.1
 * $Id$
 * 
 * Written by David Flanagan.
 * Copyright (c) 1992-2001 by David Flanagan.
 * All Rights Reserved.  See the file COPYRIGHT for details.
 * This is open source software.  See the file LICENSE for details.
 * There is no warranty for this software.  See NO_WARRANTY for details.
 *
 * $Log$
 * Revision 1.1.1.1  2001/07/18 11:06:03  root
 * Initial checkin.
 *
 * Revision 1.2  2001/06/12 16:25:28  andre
 * *** empty log message ***
 *
 *
 */

#include <Xmt/Xmt.h>
#include <Xmt/Util.h>

/*
 * The following procedure is by David Brooks of the OSF and appears in
 * the Motif FAQ list.  It has been renamed for the Xmt library.
 */

/*
 * This procedure will ensure that, if a dialog window is being mapped,
 * its contents become visible before returning.  It is intended to be
 * used just before a bout of computing that doesn't service the display.
 * You should still call XmUpdateDisplay() at intervals during this
 * computing if possible.
 *
 * The monitoring of window states is necessary because attempts to map
 * the dialog are redirected to the window manager (if there is one) and
 * this introduces a significant delay before the window is actually mapped
 * and exposed.  This code works under mwm, twm, uwm, and no-wm.  It
 * doesn't work (but doesn't hang) with olwm if the mainwindow is iconified.
 *
 * The argument to ForceDialog is any widget in the dialog (often it
 * will be the BulletinBoard child of a DialogShell).
 */

#if NeedFunctionPrototypes
void XmtWaitUntilMapped(Widget w)
#else
void XmtWaitUntilMapped(w)
Widget w;
#endif
{
    Widget diashell, topshell;
    Window diawindow, topwindow;
    Display *dpy;
    XWindowAttributes xwa;
    XEvent event;
    XtAppContext cxt;
    
    for (diashell = w; !XtIsShell(diashell); diashell = XtParent(diashell)) ;
    for (topshell = diashell;
	 !XtIsTopLevelShell(topshell);
	 topshell = XtParent(topshell));
    
    if (XtIsRealized(diashell) && XtIsRealized(topshell)) {
	dpy = XtDisplay(topshell);
	diawindow = XtWindow(diashell);
	topwindow = XtWindow(topshell);
	cxt = XtWidgetToApplicationContext(diashell);
	
	/* Wait for the dialog to be mapped. */
	while (XGetWindowAttributes(dpy, diawindow, &xwa),
	       xwa.map_state != IsViewable) {
	    
	    /*
	     * unless the primary is (or becomes) unviewable or unmapped, it's
	     * probably iconified, and nothing will happen.
	     * We make an exception to this case when topwindow==diawindow
	     */
	    if ((topwindow != diawindow) &&
		(XGetWindowAttributes(dpy, topwindow, &xwa),
		 xwa.map_state != IsViewable))
		break;

	    /*
	     * At this stage, we are guaranteed there will be
	     * an event of some kind.  Beware; we are presumably
	     * in a callback, so this can recurse.
	     */
	    XtAppNextEvent(cxt, &event);
	    XtDispatchEvent(&event);
	}
    }
    
    /* The next XSync() will get an expose event if the dialog was unmapped. */
    XmUpdateDisplay(topshell);
}