XOpenDisplay(0)和XOpenDisplay(NULL)之间的区别是什么?

时间:2017-07-10 00:27:05

标签: c++ linux x11 xlib

显示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的方式,如果有多台显示器连接到您的计算机,它会有不同的反应。我没有多个显示器要测试,所以我需要知道使用0是否与使用NULL有任何不同,这导致我的下一个问题,我将作为一个单独的问题发布。

感谢。

1 个答案:

答案 0 :(得分:3)

没有任何区别

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

相关问题