macOS: fix menu positioning on high-DPI

The target position is passed in physical native pixels, so call
QPlatformScreen::availableGeometry() and QPlatformWindow::mapToGlobal()
instead of QScreen::availableSize() and QWindow::mapToGlobal(). The
latter two operate on logical pixels.

Task-number: QTBUG-55251
Change-Id: I281f47baee727bc0f4738fd6d6cdf12c9f462b0f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
J-P Nurmi 2018-02-02 08:50:15 +01:00
parent 57f4521c99
commit 1ffc6ba402

View File

@ -46,6 +46,7 @@
#include <QtCore/private/qthread_p.h>
#include <QtGui/private/qguiapplication_p.h>
#include "qcocoaapplication.h"
#include "qcocoaintegration.h"
#include "qcocoamenuloader.h"
#include "qcocoamenubar.h"
#include "qcocoawindow.h"
@ -573,8 +574,9 @@ void QCocoaMenu::showPopup(const QWindow *parentWindow, const QRect &targetRect,
[popupCell setMenu:m_nativeMenu];
[popupCell selectItem:nsItem];
int availableHeight = screen->availableSize().height();
const QPoint &globalPos = parentWindow->mapToGlobal(pos);
QCocoaScreen *cocoaScreen = static_cast<QCocoaScreen *>(screen->handle());
int availableHeight = cocoaScreen->availableGeometry().height();
const QPoint &globalPos = cocoaWindow->mapToGlobal(pos);
int menuHeight = m_nativeMenu.size.height;
if (globalPos.y() + menuHeight > availableHeight) {
// Maybe we need to fix the vertical popup position but we don't know the