使用多个显示器 - XOpenDisplay(NULL) 有时会无法获得 window 的当前显示吗?

Working with multiple displays - will XOpenDisplay(NULL) sometimes fail to get current display of a window?

我有一个 *.SO 库,当从应用程序调用时,它会从指定的 window 中删除 window 个装饰。这是我的代码:

#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(NULL);
        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);
    }
}

我的问题 - 使用我当前的代码设置 - 它是否有时无法删除 window 装饰取决于 window 当前显示在哪个显示器上?我的印象是 XOpenDisplay(NULL) 将 return 默认显示或第一个显示,以两者为准。如果 window 是在第二个(或非默认)显示器上创建的,XOpenDisplay(NULL) 将 return 显示 window 未打开,并且 window装饰不会被移除 - 这是正确的吗?

我没有多台显示器可供测试,所以我需要知道无论最终用户是否设置了多台显示器,我的 *.SO 库都能正常工作。

Windows 无法在显示之间移动。您可能混淆了显示器和监视器,它们在 X Window 系统中是非常不同的东西。

没有"current display"这样的东西。您使用 XOpenDisplay(NULL) 打开的显示由 DISPLAY 环境变量决定,该变量应由用户的环境设置或由用户手动设置,绝不是您(应用程序编写者)的责任。

一个显示器可以连接多个显示器。 Windows 可以在显示器之间自由移动。这对大多数应用程序都是透明的,包括您的应用程序。在任何情况下,您都在处理单个显示器。

总之,你担心的不是问题。

还有一个叫"screen"的东西,跟display和monitor都不一样。你也不用担心。