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

Wrong math in QCocoaWindow::windowGeometry()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 5.11.2
    • 5.5.0
    • QPA
    • OS X 10.10.4, two displays with different screen resolutions
    • macOS

      Found this issue during testing full screen mode on system with 2 displays.
      Switching back from full screen mode on 2nd display leads to wrong window position (window title bar overlapped by OS X menu bar). Full screen mode is a game like - no Qt::WindowFullscreenButtonHint flag set.
      Screens have different resolutions and bottom lines are not aligned one to another (this is important).
      In the code below QPlatformScreen *onScreen has width and height as the sum of widths and heights of all screens (empiric finding). In case bottom lines of both screens are not aligned the calculated "flippedY" contains wrong value.

      QCocoaWindow.mm
      // Returns the current global screen geometry for the nswindow associated with this window.
      QRect QCocoaWindow::windowGeometry() const
      {
          if (!m_nsWindow || m_isNSWindowChild)
              return geometry();
      
          NSRect rect = [m_nsWindow frame];
          QPlatformScreen *onScreen = PlatformScreen::platformScreenForWindow(window());
          int flippedY = onScreen->geometry().height() - rect.origin.y - rect.size.height;  // account for nswindow inverted y.
          QRect qRect = QRect(rect.origin.x, flippedY, rect.size.width, rect.size.height);
          return qRect;
      }
      

      Replacing code:

          QPlatformScreen *onScreen = PlatformScreen::platformScreenForWindow(window());
          int flippedY = onScreen->geometry().height() - rect.origin.y - rect.size.height;  // account for nswindow inverted y.
      

      with this:

          NSScreen* primaryScreen = [[NSScreen screens] objectAtIndex:0];
          int flippedY = [primaryScreen frame].size.height - rect.origin.y - rect.size.height; // account for nswindow inverted y.
      

      Made everything working fine.

        For Gerrit Dashboard: QTBUG-47462
        # Subject Branch Project Status CR V

            vestbo Tor Arne Vestbø
            oleg.synelnykov Oleg Synelnykov
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes