[comp.windows.x] How does one establish a destroy function within an application?

arthur@media.uucp (Art Poley) (09/14/90)

This is most likely something that should be added to the Frequently Asked
Questions list.  The question being, How does one implement a destroy function
similar to SunView's notify_interpose_destroy_func?  This function would be
called whenever the user quits the window (most likely from the window 
menu).  Note that the implementation should work on a variety of window 
managers (mwm, twm, etc.).

I've noticed that mwm seems to send an XClientMessageEvent to the application.
The client message has an Atom name of WM_PROTOCOLS (found via XGetAtomName on
the message_type field of the message).  Twm, on the other hand, notes within
its documentation that twm will send a WM_DELETE_WINDOW if the application has
requested it through the WM_PROTOCOLS property.  How does one do this?

I'd appreciate anyones comments on how one goes about registering a destroy
function. 

Thanks!

-- 
--------------------------------------------------------------------------
Art Poley - Media Cybernetics           Phone: (301)495-3305 (5964 FAX)
Internet: arthur%media@uunet.uu.net     UUCP: {uunet,hqda-ai}!media!arthur

jeff@aspect.UUCP (Jeff Rosler) (09/19/90)

>This is most likely something that should be added to the Frequently Asked
>Questions list.  The question being, How does one implement a destroy function
>similar to SunView's notify_interpose_destroy_func?  This function would be
>called whenever the user quits the window (most likely from the window 
>menu).  Note that the implementation should work on a variety of window 
>managers (mwm, twm, etc.).
>
>I've noticed that mwm seems to send an XClientMessageEvent to the application.
>The client message has an Atom name of WM_PROTOCOLS (found via XGetAtomName on
>the message_type field of the message).  Twm, on the other hand, notes within
>its documentation that twm will send a WM_DELETE_WINDOW if the application has
>requested it through the WM_PROTOCOLS property.  How does one do this?
>
>I'd appreciate anyones comments on how one goes about registering a destroy
>function. 
>
>Thanks!

This is explained in ICCCM version 1.0 in section 5.2.2 on Window Deletion.
If the window manager in question is ICCCM compliant, it should use this
method of shutting down a client.  The following code segment uses Motif
library calls to implement a callback on window close from a window manager.
The window manager can be any ICCCM compliant window manager, however.


 Atom dw_atom;
 Widget toplevel;

 toplevel = XtInitialize( ... );

 ...

/***************
 *
 * Set up callback to occur when the WM_DELETE_WINDOW message
 * recvd.
 *
 ***************/
 dw_atom = XmInternAtom(XtDisplay(toplevel),"WM_DELETE_WINDOW",FALSE);
 XmAddWMProtocolCallback(toplevel,dw_atom,ImDying,NULL);

 ...


static void ImDying(shell,unused,cdata)

 Widget shell;
 caddr_t unused;
 caddr_t cdata;

{
/***************
 *
 * The window or session manager has sent a delete
 * message.  Perform some action.
 *
 ***************/
/***************
 *
 * If you wish to tell the shell to do nothing else after message is
 * rcvd. than the deleteResponse resource in the VendorShell can be set.
 * (this is detailed in the documentation for VendorShell.)
 *
 ***************/
   XtSetArg(args[0],XmNdeleteResponse,XmDO_NOTHING);
   XtSetValues(shell,args,1);
}


Jeff Rosler
Aspect Telecommunications
1730 Fox Drive
San Jose, CA  95131-2312
uunet!aspect!jeff
(408) 441-2420