c++ - `XSetWMNormalHints` 和 `XSetWMSizeHints`

标签 c++ c x11 xlib

我对 XSetWMNormalHintsXSetWMSizeHints 感到困惑。我想将窗口设置为不可调整大小,并且调用 XSetWMNormalHints 可以正确完成此操作。但如果我改为调用 XSetWMSizeHints,则什么也不会发生;窗口的大小仍然可以调整。这两个函数如何用于我的目的?XSetWMSizeHints 到底有什么作用?我已经阅读了多次文档,但我仍然很困惑,所以在这里提问。

sh = XAllocSizeHints();
sh->flags = PMinSize | PMaxSize;
sh->min_width = sh->max_width = 100;
sh->min_height = sh->max_height = 100;
XSetWMNormalHints(d, w, sh);
//XSetWMSizeHints(d, w, sh, PMinSize | PMaxSize);
XFree(sh);

最佳答案

这个问题已经有近 4 年历史了,但这也许可以为其他有类似问题的人澄清。

使用 WM_NORMAL_HINTS 属性调用 XSetWMSizeHints 与 XSetWMNormalHints 执行相同的操作。调用 XSetWMSizeHints 的问题在于“PminSize | PMaxSize”是一个值而不是属性。以下是修改为使用带有属性的 XSetWMSizeHints 的代码。

#include <X11/Xatom.h>  // XA_WM_NORMAL_HINTS
...
sh = XAllocSizeHints();
sh->flags = PMinSize | PMaxSize;
sh->min_width = sh->max_width = 100;
sh->min_height = sh->max_height = 100;
//XSetWMNormalHints(d, w, sh);
XSetWMSizeHints(d, w, sh, XA_WM_NORMAL_HINTS);
XFree(sh);

关于c++ - `XSetWMNormalHints` 和 `XSetWMSizeHints`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30994485/

相关文章:

c++ - 在 X11 上设置 OpenGL

r - 重新连接到 tmux/screen 后键盘 IO 损坏

c++ - 在 C 中循环遍历十六进制变量

c++ - vector<float> 写入文件

c++ - 将 char 类型转换为 int 以用作 vector C++ 的索引

c - 从 C 运行命令行

c - 我在哪里可以了解微 Controller (例如 ARMv7)上 C 语言的最佳数学运算?

c++ - #在c++中定义一个特殊的运算符

c - 删除打开的 TCP 连接而不发送 RST

perl - X11::Xlib 模块安装在 Devel/CheckLib.pm 出现语法错误