Question

How do I intercept when the user clicks on a motif window's (widget's) close box, and how do I prevent the Motif window manager to close the entire calling application on the close box being clicked (so that my app can close the Motif application context and windows and continue to run)? I've tried to find out myself with Google, tuts and docs, but no dice. C++ required.

Was it helpful?

Solution

This seems to work (found on the inet):

#include <Xm/Protocols.h>

Boolean SetCloseCallBack (Widget shell, void (*callback) (Widget, XtPointer, XtPointer))
{
extern Atom XmInternAtom (Display *, char *, Boolean);

if (!shell)
    return False;
Display* disp = XtDisplay (shell);
if (!disp)
    return False;
// Retrieve Window Manager Protocol Property
Atom prop = XmInternAtom (disp, const_cast<char*>("WM_PROTOCOLS"), False);
if (!prop)
    return False;
// Retrieve Window Manager Delete Window Property
Atom prot = XmInternAtom (disp, const_cast<char*>("WM_DELETE_WINDOW"), True);
if (!prot)
    return False;
// Ensure that Shell has the Delete Window Property
// NB: Necessary since some Window managers are not
// Fully XWM Compilant (olwm for instance is not)
XmAddProtocols (shell, prop, &prot, 1);
// Now add our callback into the Protocol Callback List
XmAddProtocolCallback (shell, prop, prot, callback, NULL);
return True;
}

Setting such a callback will prevent the application being closed as a result of the close event being handle be the default event handlers.

OTHER TIPS

Won't vendorShellWidgetClass do the trick for you? As in, closing just the motif app context and not the window..

IIRC, on X11, when you click a window's close box, the window manager sends a signal to your application, which tells it to exit. Whether you use motif or gtk or Qt is irrelevant since the close box belongs to the WM, not your application.

You need to catch the unix signal to prevent your application from closing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top