【问题标题】:What's the difference between XOpenDisplay(0) and XOpenDisplay(NULL)?XOpenDisplay(0) 和 XOpenDisplay(NULL) 有什么区别?
【发布时间】:2017-07-10 00:27:04
【问题描述】:

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

谢谢。

【问题讨论】:

标签: c++ linux x11 xlib


【解决方案1】:

没有任何区别

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

【讨论】:

  • 酷,我有一种感觉,我只是想要一些验证。谢谢! :D
  • 如果你想表达一个空指针nullptr,现在可能想补充一点。
猜你喜欢
  • 1970-01-01
  • 2021-06-16
  • 2017-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-09
  • 2016-08-19
相关资源
最近更新 更多