xlib 防止关闭按钮退出应用程序

xlib prevent close button to exit the application

有没有办法防止点击关闭按钮退出应用程序?以下代码仅隐藏最小化和最大化按钮,但不隐藏关闭按钮...

Atom window_type = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
long value = XInternAtom(display, "_NET_WM_WINDOW_TYPE_TOOLBAR", False);
XChangeProperty(display, window, window_type, XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );

我试图通过 google 搜索有关覆盖 _NET_CLOSE_WINDOW 的信息,但找不到真正的...或从 xprop 中删除 _NET_WM_ACTION_CLOSE 的方法...

阅读 ICCCM & EWMH. You might need months (or years) to understand all the details (and the relation to X11 and X protocols and architectures).

理论上你可以在原始 Xlib 中做你想做的事。但是细节是如此复杂,你真的应该使用一些工具包,比如 Qt or GTK (life is short), or maybe libSDL or SFML. See also this list.

在协议和Xlib 级别掌握X11 需要花费大量时间(相关文档有数千页)。你确定愿意花钱吗?

所以在原始 X11 级别编码就像在汇编程序中编码一样。今天没有人为真正的程序这样做,并且出于类似的原因(abstraction 级别太低;需要关心的细节太多......)。

请注意,当前趋势是用 Wayland 替换 X。在 X11 中,您可能需要数年时间从头开始开发您的东西,到您成功时,X 就会过时了。顺便说一句,Qt 和 GTK 的最新版本了解 Wayland(因此相同的代码可以在 X11 和 Wayland 上运行)。

所以 使用一些 GUI toolkit. They are monster software of millions of lines, and there is a reason for that complexity (also, graphics cards are very complex hardware today; see also & this)。他们使您能够禁用关闭 window(因为他们知道所有 ICCCM 和 EWMH 详细信息)。

既然你用 C++ 标记了你的问题,我强烈建议使用 Qt(或者 SFML)。 documentation of Qt太棒了

顺便说一句,你不清楚的问题看起来很奇怪(并且缺乏动机和背景)。看来您错误地认为您的应用程序是屏幕上唯一的应用程序,这与每个 windowing system (which are multi-tasking and multi-window, so multi-application, at heart). You should think your application as working with other ones (e.g. for copy & paste, which has no sense without thinking of several applications and several windows involved). And an advanced user could always "terminate" your application (e.g. with kill(1) or xkill) 的理念背道而驰。您可能希望在 window 关闭时收到通知(例如,在发生这种情况时显示一些对话框)。您甚至不应该设计一个不可关闭的应用程序(这违反了所有编码和界面指南)。