tags:

views:

373

answers:

2

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.

A: 

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.

static_rtti
I asked *how* to do it. I know already that I have to intercept the event(s) involved somehow and prevent the default exit handler from being called.
karx11erx
I *have* told you how to do it. Google "unix signal" and you'll have the answer.
static_rtti
You have nothing. Your supposed hint is worthless. See my self-given response, that's a good reply.
karx11erx
A: 

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.

karx11erx