Motif:拦截关闭框事件并阻止应用程序退出? (C++)

发布于 2024-08-04 00:14:11 字数 139 浏览 9 评论 0原文

当用户单击主题窗口(小部件)的关闭框时,如何拦截,以及如何防止 Motif 窗口管理器在单击关闭框时关闭整个调用应用程序(以便我的应用程序可以关闭 Motif 应用程序上下文)和窗口并继续运行)?我试图通过谷歌、图茨和文档来找到自己,但没有任何结果。需要 C++。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

二智少女猫性小仙女 2024-08-11 00:14:11

这似乎有效(在 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;
}

设置这样的回调将防止应用程序因关闭事件被默认事件处理程序处理而被关闭。

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.

記柔刀 2024-08-11 00:14:11

vendorShellWidgetClass 不会为你解决这个问题吗?就像这样,仅关闭主题应用程序上下文而不是窗口。

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

骄兵必败 2024-08-11 00:14:11

IIRC,在 X11 上,当您单击窗口的关闭框时,窗口管理器会向您的应用程序发送一个信号,告诉它退出。无论您使用主题、gtk 还是 Qt 都无关紧要,因为关闭框属于 WM,而不是您的应用程序。

您需要捕获 unix 信号以防止应用程序关闭。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文