Results 1 to 6 of 6

Thread: Mapping QScreen to X11 display number

  1. #1
    Join Date
    Sep 2007
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Mapping QScreen to X11 display number

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mapping QScreen to X11 display number

    You can get that through the QPlatformNativeInterface which you can get through QGuiApplication::platformNativeInterface().

    The XCB plugin implements the nativeResourceForScreen such that querying for "display" returns the X11 Display of the screen.

    The nativeResourceForIntegration function can also be used to query for some of the X11 internals.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2007
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Mapping QScreen to X11 display number

    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:

    Qt Code:
    1. #include <QApplication>
    2. #include <QDebug>
    3. #include <qpa/qplatformnativeinterface.h>
    4. #include <X11/Xlib.h>
    5.  
    6. int main(int argc, char **argv)
    7. {
    8. QApplication app(argc, argv);
    9.  
    10. foreach (QScreen *screen, QGuiApplication::screens()) {
    11.  
    12. QPlatformNativeInterface* platformInterface = QApplication::platformNativeInterface();
    13. void* x11Display = platformInterface->nativeResourceForScreen("display", screen);
    14.  
    15. Display* dpy = (Display*)x11Display;
    16. auto dpyString = DisplayString(dpy);
    17.  
    18. qDebug() << screen << " display " << dpyString;
    19. }
    20.  
    21. return 0;
    22. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. 0x147b5c0 display :0.1
    2. 0x147b6d0 display :0.1
    To copy to clipboard, switch view to plain text mode 

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mapping QScreen to X11 display number

    Quote Originally Posted by nurtsi View Post
    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:

    Qt Code:
    1. 0x147b5c0 display :0.1
    2. 0x147b6d0 display :0.1
    To copy to clipboard, switch view to plain text mode 
    Isn't that the information you are looking for?

    Quote Originally Posted by nurtsi View Post
    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,
    _

  5. #5
    Join Date
    Sep 2007
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Mapping QScreen to X11 display number

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Mapping QScreen to X11 display number

    Quote Originally Posted by nurtsi View Post
    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.

    Quote Originally Posted by nurtsi View Post
    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,
    _

Similar Threads

  1. Replies: 13
    Last Post: 12th November 2013, 20:35
  2. display the number of every node in 3d surfaceplot
    By panagiotisss in forum Newbie
    Replies: 0
    Last Post: 8th October 2012, 12:31
  3. MAC DOCK display number in icon
    By migel in forum Newbie
    Replies: 0
    Last Post: 6th September 2011, 09:58
  4. display number on label
    By aj2903 in forum Qt Programming
    Replies: 4
    Last Post: 12th March 2009, 07:24
  5. Display row Number in QMessageBox
    By arunvv in forum Newbie
    Replies: 6
    Last Post: 1st May 2008, 23:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.