c++ - XOpenDisplay(0) 和 XOpenDisplay(NULL) 有什么区别?

标签 c++ linux x11 xlib

Display XOpenDisplay(0) 和 XOpenDisplay(NULL) 有什么区别?

#include <X11/Xlib.h>

struct MwmHints
{
    unsigned long flags;
    unsigned long functions;
    unsigned long decorations;
    long input_mode;
    unsigned long status;
};
enum
{
    MWM_HINTS_FUNCTIONS = (1L << 0),
    MWM_HINTS_DECORATIONS =  (1L << 1),

    MWM_FUNC_ALL = (1L << 0),
    MWM_FUNC_RESIZE = (1L << 1),
    MWM_FUNC_MOVE = (1L << 2),
    MWM_FUNC_MINIMIZE = (1L << 3),
    MWM_FUNC_MAXIMIZE = (1L << 4),
    MWM_FUNC_CLOSE = (1L << 5)
};

extern "C"
{
    void borderless(Window window)
    {
        Display *display = XOpenDisplay(0);
        Atom mwmHintsProperty = XInternAtom(display,"_MOTIF_WM_HINTS",0);
        struct MwmHints hints;
        hints.flags = MWM_HINTS_DECORATIONS;
        hints.decorations = 0;
        XChangeProperty(display,window,mwmHintsProperty,mwmHintsProperty,32,
        PropModeReplace,(unsigned char *)&hints,5);
        XCloseDisplay(display);
    }
}

在上面的代码中,我为 Linux 编写了一个 *.SO 库,在调用时删除指定窗口的窗口装饰。在该代码行中显示:

Display *display = XOpenDisplay(0);

我试过将其替换为:

Display *display = XOpenDisplay(NULL);

这两种用法似乎都成功地移除了我正在测试的 Ubuntu 16.04 LTS 笔记本电脑上的窗口装饰。

我在某处(我不记得在哪里)读到过,根据您使用 XOpenDisplay 的方式,如果有多个显示器连接到您的计算机,它会有不同的 react 。我没有多个显示器可以测试,所以我需要知道使用 0 与使用 NULL 是否有任何不同,这引出了我的下一个问题,我将把它作为一个单独的问题发布。

谢谢。

最佳答案

没有任何区别

NULL is defined as 0 (possibly casted to void * in C, but not in C++) .这两个调用实际上是相同的。

关于c++ - XOpenDisplay(0) 和 XOpenDisplay(NULL) 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45002305/

相关文章:

unicode - 如何将 X11 键符映射到 Unicode 字符?

c++ - DirectX 后处理着色器

linux - 如何将一行 Bash 脚本分隔成多行?

linux - 在ath9k_htc模块中处理接收到的ACK帧

c++ - 在 Linux 中确定程序是 GUI 还是控制台应用程序

c++ - X 的错误处理程序抛出异常是否安全?

c++ - 尝试为所有 std 容器打印重载运算符 << 时出错,为什么?

c++ - 从文件对象到文件名

c++ - 有没有一种方法可以将 char "+"的运算符转换为实际的算术运算符?

linux - 如何在 Linux 中向应用程序发出信号而不杀死它?