Skip to content
Advertisement

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

I have an *.SO library, which when called from an application, removes window decorations from the specified window. Here is my code:

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

My question – with my current code set up – will it sometimes fail to remove window decorations depending on which display the window is currently displayed on? My impression is that XOpenDisplay(NULL) will return the default or first display, whichever one that is. If the window was created on the second (or non-default) display, XOpenDisplay(NULL) will return a display the window isn’t on, and the window decorations won’t be removed – is this correct?

I don’t have multiple monitors to test with, so I need to know that my *.SO Library will work regardless of whether the end user has a multiple monitor setup.

Advertisement

Answer

Windows cannot move between displays. You are probably confusing displays and monitors, which are very different things in the X Window system.

There is no such thing as “current display”. A display that you open with XOpenDisplay(NULL) is determined by DISPLAY environment variable which should be set by user’s environment or manually by the user, and is never your (application writer) responsibility.

A display can have several monitors attached to it. Windows can move between monitors freely. This is transparent to most applications, including yours. You are dealing with a single display in any case.

In short, you are worrying about a non-problem.

There’s also a thing called “screen”, which is different from both display and monitor. You shouldn’t worry about it either.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement