[comp.windows.x] WM_DELETE and the Shell Widget

jlv@ebt-inc.uucp (Jeffrey L. Vogel) (12/17/90)

I am having the following problem with the XtR4 Shell Widget.
I want to know when the user, via the window manager,
requested that my shell be closed.
I don't, however, want the shell to be destroyed, just unmapped.

So, this is what I did.

1) selected WM_DELETE properties with XSetWMProtocols.
2) Used XtAddEventHandler to register for the ClientMessage events.
3) In the callback I issued a XWithdrawWindow request to the window manager
   to unmap the window and its icon, as the ICCCM says I should. 
   I believe that the window and widget should not be destroyed 
   unless I explicitly destroy them.

Well...
I noticed weird things happening to my application after I got my
ClientMessage from the Window Manger.

SO, I register with the ShellWidget for a XtNdestroyCallback, and sure enough,
I was getting called.  Apparently, the Xt Shell Widget is getting these
messages from the window manager also, and taking it upon itself
to destroy itself.

Is this TRUE, if so, how can it be stopped?

dex@hpcvlx.cv.hp.com (Dex Smith) (12/20/90)

In Motif, the VendorShell widget class (which is used by application
shells) defines an XmNdeleteResponse resource.  The default value for this
resource is XmDESTORY.  So, when the window receives a WM_DELETE_WINDOW 
message (ie. window manager Close command), the shell is destroyed.  If it
is the application's top-level shell, the process terminates.

To "trap" the window manager Close command, you do two things:

 1. Set the top-level shell's "deleteResponse" resource to XmDO_NOTHING:

        ac = 0;
        XtSetArg (al[ac], XmNdeletResponse, XmDO_NOTHING);  ac++;
        XtSetValues (toplevel, al, ac);

 2. Add a window manager protocol callback to detect when the shell gets
    the WM_DELETE_WINDOW message:

        Atom  XaWmDelete;

        XaWmDelete= XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", False);
        XmAddWMProtocolCallback(toplevel, XaWmDelete, MenuCB, MENU_File_Exit);

    This example code sets the callback to call a MenuCB() callback routine
    with an application-specific defined client_data of MENU_File_Exit.  
    Presumably, this is the same callback and client_data used for the
    Exit command in the application's File menu.  (That is, the window 
    manager's Close command is now equivalent to the Exit command in the 
    File menu.)

I hope this helps!

- Dex Smith, Learning Products Developer
  Interface Technology Operation
  Hewlett-Packard Company
  Corvallis, Oregon

  dex@hpcvlx.cv.hp.com