PDA

View Full Version : Mapping QScreen to X11 display number



nurtsi
7th January 2016, 12:49
Is there a way to map QScreen to X11 display number on Linux?

We have a visualization software that renders large scenes using a single process that opens multiple windows on different X displays. Xinerama is disabled so that you can not move windows between X displays. I can query the available screens using QApplication::screens() and get a QScreen for each configured display. My problem is that all QScreens have identical parameters (displays are identical, so all resolutions are same and virtual desktop coordinates are same because of separate X displays) so I can't differentiate between them.

Is there any way to get X11 DISPLAY handle from QScreen so I could determine the relative positioning of QScreens?

anda_skoa
7th January 2016, 13:28
You can get that through the QPlatformNativeInterface (http://code.woboq.org/qt5/qtbase/src/gui/kernel/qplatformnativeinterface.h.html#QPlatformNativeInt erface) which you can get through QGuiApplication::platformNativeInterface().

The XCB plugin implements the nativeResourceForScreen (http://code.woboq.org/qt5/qtbase/src/plugins/platforms/xcb/qxcbnativeinterface.cpp.html#_ZN19QXcbNativeInterf ace23nativeResourceForScreenERK10QByteArrayP7QScre en) such that querying for "display" returns the X11 Display of the screen.

The nativeResourceForIntegration (http://code.woboq.org/qt5/qtbase/src/plugins/platforms/xcb/qxcbnativeinterface.cpp.html#_ZN19QXcbNativeInterf ace28nativeResourceForIntegrationERK10QByteArray) function can also be used to query for some of the X11 internals.

Cheers,
_

nurtsi
8th January 2016, 13:55
Hi,

I tried your suggestion but it doesn't seem to work. I'm not familiar with Qt internals, but the "display" returned for both QScreens is the same (it gets queried from QXcbConnection which is shared for both QScreen instances).

Here's my sample test app:


#include <QApplication>
#include <QDebug>
#include <qpa/qplatformnativeinterface.h>
#include <X11/Xlib.h>

int main(int argc, char **argv)
{
QApplication app(argc, argv);

foreach (QScreen *screen, QGuiApplication::screens()) {

QPlatformNativeInterface* platformInterface = QApplication::platformNativeInterface();
void* x11Display = platformInterface->nativeResourceForScreen("display", screen);

Display* dpy = (Display*)x11Display;
auto dpyString = DisplayString(dpy);

qDebug() << screen << " display " << dpyString;
}

return 0;
}

My test setup is such that I have two X screens: :0.1 on the left and :0.0 on the right. When I run my test app, I get the following:



0x147b5c0 display :0.1
0x147b6d0 display :0.1


If I open a QWindow with QScreen as constructor parameter, the windows do get opened properly on different X screens, so internally Qt seems to work correctly.

Looking at Qt source it looks like QXcbScreen::screenNumber() would return what I need. Is there any way to access this information? I don't see it (or anything about virtual desktops) in QPlatformNativeInterface.

anda_skoa
8th January 2016, 15:34
My test setup is such that I have two X screens: :0.1 on the left and :0.0 on the right. When I run my test app, I get the following:



0x147b5c0 display :0.1
0x147b6d0 display :0.1


Isn't that the information you are looking for?



Looking at Qt source it looks like QXcbScreen::screenNumber() would return what I need. Is there any way to access this information? I don't see it (or anything about virtual desktops) in QPlatformNativeInterface.

Hmm.

A bit hackish but you could include qxcbscreen.h and then cast the QScreen::handle() to that and access the function.

Cheers,
_

nurtsi
11th January 2016, 08:29
Isn't that the information you are looking for?

I'd expect it to return :0.1 for one of the QScreens and :0.0 for the other.


A bit hackish but you could include qxcbscreen.h and then cast the QScreen::handle() to that and access the function.

Unfortunately qxcbscreen.h isn't shipped with the Qt headers, so I can't include it. Only the plugin binary (libqxcb.so) seems to be available.

anda_skoa
11th January 2016, 09:10
I'd expect it to return :0.1 for one of the QScreens and :0.0 for the other.

Ah, my mistake, it thought that what the debug output said, but it has :0.1 twice.
Could be a bug in the XCB plugin.



Unfortunately qxcbscreen.h isn't shipped with the Qt headers, so I can't include it. Only the plugin binary (libqxcb.so) seems to be available.
Hence the "hackish" in my comment. You would need to copy the header.

Cheers,
_