Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-50788

QApplication::desktop()->screenNumber returns wrong screen during startup

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.5.1
    • Fix Version/s: None
    • Component/s: QPA: X11/XCB
    • Labels:
      None
    • Environment:
      openSUSE Tumbleweed, Plasma 5.5.3, Qt 5.5.1
      ATI Radeon 7850

      Description

      Given the following RandR setup:

      • Screen 0 - 1680x1050, right of
      • Screen 1 - 1280x1024,

      QDesktopWidget::screenNumber always returns screen 1 during startup,
      even if it is started on screen 0.

      This behavior already existed with KDE 4, and it persists with Plasma 5.5.3 and Qt 5.5.1. The reason I noticed it is that the KDE feature to restore window sizes on startup seems to depend on that screenNumber call during application startup as well - and it does not work screen 0.

      In the attached test program, the following method is called both in the main window constructor and manually through a button:

      void MainWindow::logCurrentScreenInfo() {
          const int scnum = QApplication::desktop()->screenNumber(window());
          QRect desk = QApplication::desktop()->screenGeometry(scnum);
      
          qDebug() << "Screen #" << scnum
                   << ",\nDesktop=" << desk
                   << ",\nWindow=" << window()->pos() << " " << window()->geometry();
      }
      

      MainWindow constructor:

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          qDebug() << "Screen info during main window construction:\n";
          logCurrentScreenInfo();
      }
      

      When I start the attached project in QtCreator on screen #0, the output looks like the following:

      Screen info during main window construction:
      
      Screen # 1 ,
      Desktop= QRect(0,0 1280x1024) ,
      Window= QPoint(0,0)   QRect(0,0 258x96)
      
      Screen info on button click:
      
      Screen # 0 ,
      Desktop= QRect(1280,0 1680x1050) ,
      Window= QPoint(2625,0)   QRect(2629,29 258x96)
      

      When I launch the program on screen #1, the output is as expected (screen 1 is returned from both calls).

      I don't know if the Qt behavior is expected and the issue is with KDE (or KWin), or if this behaviour is indeed a bug that should be fixed.

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              liaqi Liang Qi
              Reporter:
              dlichtenberger Daniel
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes