diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2014-02-18 14:32:33 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-26 12:58:00 +0100 |
commit | 9d2d4ad4833ac815eda9c99eb97d421234a0c4cd (patch) | |
tree | dee975784115d0b09feccb3faea555c0b679b290 /src/plugins/platforms/cocoa/qcocoahelpers.mm | |
parent | 66e5f8e9dcd11d136b707d13c7597019c99c54b8 (diff) |
Cocoa: Fix popup window positioning.
Popup window positions where offset on retina MacBooks
with an connected external monitor.
Fix this by cleaning up the coordinate conversion
functions:
Remove the qt_mac_flipRect overload which tries
to position the window according screen size. This
functionality does not belong inside a coordinate/
type conversion function. Also, it was using the windows's
screen instead of the main screen which is incorrect.
"Y flipping": Use the height of the first screen in
[NSScreen screens], which is documented to always
be the screen that contains the coordinate system
origin. Remove the usages of QApplication::primaryScreen()
("Don't use Qt to implement Qt").
Task-number: QTBUG-36672
Change-Id: I2354d31361f5a4c2c80035cf4c7def939218406f
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoahelpers.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 9b3198224e..8975605e5c 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -595,44 +595,42 @@ QString qt_mac_applicationName() return appName; } -NSRect qt_mac_flipRect(const QRect &rect) +int qt_mac_mainScreenHeight() { - int flippedY = qt_mac_flipYCoordinate(rect.y() + rect.height()); - return NSMakeRect(rect.x(), flippedY, rect.width(), rect.height()); + // The first screen in the screens array is documented + // to have the (0,0) origin. + NSRect screenFrame = [[[NSScreen screens] firstObject] frame]; + return screenFrame.size.height; } -/* - Mac window coordinates are in the first quadrant: 0, 0 is at the lower-left - corner of the primary screen. This function converts the given rect to an - NSRect for the window geometry, flipping from 4th quadrant to 1st quadrant - and simultaneously ensuring that as much of the window as possible will be - onscreen. If the rect is too tall for the screen, the OS will reduce the - window's height anyway; but by moving the window upwards we can have more - of it onscreen. But the application can still control the y coordinate - in case it really wants the window to be positioned partially offscreen. -*/ -NSRect qt_mac_flipRect(const QRect &rect, QWindow *window) -{ - QPlatformScreen *onScreen = QPlatformScreen::platformScreenForWindow(window); - int flippedY = onScreen->geometry().height() - (rect.y() + rect.height()); - QList<QScreen *> screens = QGuiApplication::screens(); - if (screens.size() > 1) { - int height = 0; - foreach (QScreen *scr, screens) - height = qMax(height, scr->size().height()); - int difference = height - onScreen->geometry().height(); - if (difference > 0) - flippedY += difference; - else - flippedY -= difference; - } - // In case of automatic positioning, try to put as much of the window onscreen as possible. - if (window->isTopLevel() && qt_window_private(const_cast<QWindow*>(window))->positionAutomatic && flippedY < 0) - flippedY = onScreen->geometry().height() - onScreen->availableGeometry().height() - onScreen->availableGeometry().y(); -#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG - qDebug() << Q_FUNC_INFO << rect << "flippedY" << flippedY << - "screen" << onScreen->geometry() << "available" << onScreen->availableGeometry(); -#endif +int qt_mac_flipYCoordinate(int y) +{ + return qt_mac_mainScreenHeight() - y; +} + +qreal qt_mac_flipYCoordinate(qreal y) +{ + return qt_mac_mainScreenHeight() - y; +} + +QPointF qt_mac_flipPoint(const NSPoint &p) +{ + return QPointF(p.x, qt_mac_flipYCoordinate(p.y)); +} + +NSPoint qt_mac_flipPoint(const QPoint &p) +{ + return NSMakePoint(p.x(), qt_mac_flipYCoordinate(p.y())); +} + +NSPoint qt_mac_flipPoint(const QPointF &p) +{ + return NSMakePoint(p.x(), qt_mac_flipYCoordinate(p.y())); +} + +NSRect qt_mac_flipRect(const QRect &rect) +{ + int flippedY = qt_mac_flipYCoordinate(rect.y() + rect.height()); return NSMakeRect(rect.x(), flippedY, rect.width(), rect.height()); } |