From: rika@informix.com (Rika Tsitsinia)
Newsgroups: comp.windows.x.motif
Subject: kill window and Xt Warning
Date: 12 Jan 93 22:16:56 GMT
Organization: Informix Software, Inc.
Originator: rika@anhialos


I have been stuck on an Xt warning I am getting from my motif 
application and I have not found something in the documentation 
that really helps me.  I am new to motif and any advice is very 
useful and appreciated.

To help resolve the problem I have written a small example that
reproduces the warning.

The warning says:
    Warning: XtRemoveGrab asked to remove a widget not on the list

The scenario is:

(1)	I create an applicationShell widget that contains a bulletin
	board with two buttons.  The fist button simply terminates 
	the program, the second one pops up a dialog.

	The dialog (dialogShell) contains a bulletin board with 
	two buttons as well.  The first one closes (unmanages) the 
	dialog, whereas the second one pops up a second dialog.

	The second dialog (dialogShell) contains a bulletin board 
	with one button that closes (unmanages) the dialog.

	Both dialogs have XmNdialogStyle set to XMDIALOG_APPLICATION_MODAL
	and the resource is set to the bulletin boards.

(2)	I also have a toplevelShell widget with a bulletin board
	that contains a dummy button (does not do anything).

(3)	Both dialog shells, the application shell and the toplevel 
	shell have XmdeleteResponse to XmDO_NOTHING and a callback
	killCB is called when the WM_DELETE_WINDOW protocol is 
	received by the window manager. killCB calls XtDestroyWidget.

I run the example, pop up the first dialog and from it the second one.
Then, I move to the toplevelShell window and select kill (close) from 
the system menu.  Then I go back to close the second dialog, the
dialog is unmanaged and at this point I get the warning I mention above.

From the work I have done, I believe the reason is that Xt tries 
to remove the widget for the second dialog from the grab list and 
it does not find it there.

The X Window System Toolkit book by Paul Asente and Ralph Swick 
mentions on page 302 (section 6.5 The Grab List) "XtRemoveGrab 
removes the specified widget and any other widgets added to the grab 
list more recently than the specified widget from the grab list."

In my example, the second dialog is added to the grab list after the 
window and it is being removed. Then, there is code in Xt that
adds the dialog back to the grab list but then it is removed again.
In this last step I am lost.

Why is the above happening? Am I doing something wrong?  
Is there a workarround to the warning?  Do I need to do something 
else in the application to avoid this warning?

Thanks in advance,
Rika

PS. Below I have the motif example for anyone who wants to run it.
-------------------------------------------------------
/*  k1.c
 *
 *  produces an Xt warning when a top level window is killed
 */

#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/Protocols.h>
#include <Xm/Xm.h>
#include <Xm/BulletinB.h>
#include <Xm/PushB.h>
#include <Xm/DialogS.h>

void
quit(w, client_data, call_data)
Widget    w;
caddr_t   client_data;
XtPointer call_data;
{
    exit(0);
};

void
dlgShow( w, dialog, call_data)
Widget	  w, dialog;
XtPointer call_data;
{
    XtManageChild(dialog);    
};

void
dlgClose( w, dialog, call_data)
Widget	  w, dialog;
XtPointer call_data;
{
    XtUnmanageChild(dialog);
};

void
killCB( w, ptr1, ptr2)
Widget 	  w;
XtPointer ptr1, ptr2;
{
 	XtDestroyWidget(ptr1);
};


main(argc, argv)
int	  argc;
char	* argv[];
{

	XtAppContext	  appContext;
	Display		* display;
	Widget	  	  appShell,	topShell,
		  	  BBApp,	BBTop,
		  	  exitBt,	dialogBt,
		  	  dlg1Shell,	dlg2Shell, 
		  	  dlg1Box,	dlg2Box,
		  	  dlg1Bt1,	dlg1Bt2, 
		  	  dlg2Bt1,
		  	  dummy;
	Arg	  al[5];
	short	  ac;
	Atom	  delWindow1, delWindow2, delWindow3, delWindow4;


	XtToolkitInitialize();
	appContext = XtCreateApplicationContext();
	display    = XtOpenDisplay(appContext, NULL, argv[0], 
			    "Generic", NULL, 0, 
			    (Cardinal *)&argc, argv);
	ac = 0;
	XtSetArg( al[ac], XmNdeleteResponse, XmDO_NOTHING ); ac++;
	appShell   = XtAppCreateShell( argv[0], "Generic",
			    applicationShellWidgetClass, display, al, ac);
	delWindow1 = XmInternAtom(XtDisplay(appShell), 
			    "WM_DELETE_WINDOW", FALSE);
	XmAddWMProtocolCallback(appShell, delWindow1, 
			    (XtCallbackProc)killCB,
			    appShell);

		/* Creating Bulletin board and Buttons */
	ac = 0;
	BBApp = XmCreateBulletinBoard( appShell, "MAIN", al, ac);
	XtManageChild(BBApp); 

	ac = 0;
	exitBt  = XtCreateManagedWidget("exitBt", 
			    xmPushButtonWidgetClass,
			    BBApp, al, ac);
	XtAddCallback( exitBt, XmNactivateCallback, quit, NULL);
	ac = 0;
	XtSetArg(al[ac], XmNx, 80); ac++;
	XtSetArg(al[ac], XmNy, 0); ac++;
	dialogBt = XtCreateManagedWidget("button1", 
			    xmPushButtonWidgetClass, 
			    BBApp, al, ac);

		/* Creating second toplevel window */
	ac = 0;
	XtSetArg( al[ac], XmNdeleteResponse, XmDO_NOTHING ); ac++;
	topShell   = XtAppCreateShell(NULL,"Generic",
			    topLevelShellWidgetClass,
			    XtDisplay(appShell), al, ac);
	delWindow2 = XmInternAtom(XtDisplay(appShell), 
			    "WM_DELETE_WINDOW", FALSE);
	XmAddWMProtocolCallback(topShell, delWindow2, 
			    (XtCallbackProc)killCB,
			    topShell);
	BBTop = XtCreateManagedWidget("BB", 
			    xmBulletinBoardWidgetClass, 
			    topShell, NULL, 0);
	dummy = XtCreateManagedWidget("dummy", 
			    xmPushButtonWidgetClass,
			    BBTop, NULL, 0);

		/* Creating the first dialog */
	ac = 0;
	XtSetArg( al[ac], XmNdeleteResponse, XmDO_NOTHING ); ac++;
	dlg1Shell  = XmCreateDialogShell( BBApp, "Dlg", al, ac);
	delWindow1 = XmInternAtom( XtDisplay(dlg1Shell), 
			    "WM_DELETE_WINDOW", FALSE);
	XmAddWMProtocolCallback(dlg1Shell, delWindow3, 
			    (XtCallbackProc)killCB,
			    dlg1Shell);
	ac = 0;
	XtSetArg( al[ac], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); ac++;
	XtSetArg( al[ac], XmNautoUnmanage, FALSE); ac++;
	dlg1Box    = XmCreateBulletinBoard( dlg1Shell, "dlgBB", al, ac);
	ac = 0;
	dlg1Bt1 = XtCreateManagedWidget("Close", xmPushButtonWidgetClass,
			dlg1Box, al, ac);
	XtAddCallback( dlg1Bt1,XmNactivateCallback, dlgClose, dlg1Box); 
	ac = 0;
	XtSetArg(al[ac], XmNx, 80); ac++;
	XtSetArg(al[ac], XmNy, 0); ac++;
	dlg1Bt2 = XtCreateManagedWidget("PopDlg", xmPushButtonWidgetClass, 
			dlg1Box, al, ac);

		/* attaching the dlg1Box to the appShell */
	XtAddCallback( dialogBt, XmNactivateCallback, dlgShow, dlg1Box); 

		/* Creating the second dialog */
	ac = 0;
	XtSetArg( al[ac], XmNdeleteResponse, XmDO_NOTHING ); ac++;
	dlg2Shell  = XmCreateDialogShell( dlg1Box, "Dlg2", al, ac);
	delWindow1 = XmInternAtom( XtDisplay(dlg2Shell), 
			    "WM_DELETE_WINDOW", FALSE);
	XmAddWMProtocolCallback(dlg2Shell, delWindow4, 
			    (XtCallbackProc)killCB,
			    dlg2Shell);
	ac = 0;
	XtSetArg( al[ac], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); ac++;
	XtSetArg( al[ac], XmNautoUnmanage, FALSE); ac++;
	dlg2Box    = XmCreateBulletinBoard( dlg2Shell, "dlgBB", al, ac);
	ac = 0;
	dlg2Bt1 = XtCreateManagedWidget("BUTTON", 
			    xmPushButtonWidgetClass,
			    dlg2Box, al, ac);
	XtAddCallback( dlg2Bt1,XmNactivateCallback, dlgClose, dlg2Box); 

		/* attaching the dlg2Box to the button of the 1st Dialog */
	XtAddCallback( dlg1Bt2, XmNactivateCallback, dlgShow, dlg2Box); 

	XtRealizeWidget(appShell);
	XtRealizeWidget(topShell); 
	XtAppMainLoop(appContext);
}