summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-02-16 08:54:58 +0100
committerLiang Qi <liang.qi@qt.io>2018-02-16 08:54:58 +0100
commit942ab490724fcc9544e786e5783718e1a07aa50b (patch)
treefeb7d3ff716edb37b2ca60e33c05adf8777bd964 /src/plugins/platforms/cocoa
parent0fb8271a467202990c90321066e40faed640a7a8 (diff)
parent24adaa9a742e6f95ff897d0eb9a2bce0527dd042 (diff)
Merge remote-tracking branch 'origin/5.11' into dev
Conflicts: src/corelib/tools/tools.pri Change-Id: I705630f9cecbf0ce51a22fc6116b8c49611259e9
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm18
-rw-r--r--src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm12
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenu.mm7
-rw-r--r--src/plugins/platforms/cocoa/qcocoansmenu.mm15
-rw-r--r--src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm2
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm24
-rw-r--r--src/plugins/platforms/cocoa/qnsview.h3
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm48
8 files changed, 92 insertions, 37 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
index 32be9ad4ee..a94e0dc517 100644
--- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
+++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
@@ -311,6 +311,24 @@ QT_USE_NAMESPACE
return NO; // Someday qApp->quitOnLastWindowClosed(); when QApp and NSApp work closer together.
}
+- (void)applicationWillHide:(NSNotification *)notification
+{
+ if (reflectionDelegate
+ && [reflectionDelegate respondsToSelector:@selector(applicationWillHide:)]) {
+ [reflectionDelegate applicationWillHide:notification];
+ }
+
+ // When the application is hidden Qt will hide the popup windows associated with
+ // it when it has lost the activation for the application. However, when it gets
+ // to this point it believes the popup windows to be hidden already due to the
+ // fact that the application itself is hidden, which will cause a problem when
+ // the application is made visible again.
+ const QWindowList topLevelWindows = QGuiApplication::topLevelWindows();
+ for (QWindow *topLevelWindow : qAsConst(topLevelWindows)) {
+ if ((topLevelWindow->type() & Qt::Popup) == Qt::Popup && topLevelWindow->isVisible())
+ topLevelWindow->hide();
+ }
+}
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
index 00bfc8bef5..94f2125bad 100644
--- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
@@ -415,6 +415,13 @@ static QString strippedText(QString s)
} else {
QList<QUrl> result;
QString filename = QString::fromNSString([[mSavePanel URL] path]).normalized(QString::NormalizationForm_C);
+ const QString defaultSuffix = mOptions->defaultSuffix();
+ const QFileInfo fileInfo(filename);
+ // If neither the user or the NSSavePanel have provided a suffix, use
+ // the default suffix (if it exists).
+ if (fileInfo.suffix().isEmpty() && !defaultSuffix.isEmpty()) {
+ filename.append('.').append(defaultSuffix);
+ }
result << QUrl::fromLocalFile(filename.remove(QLatin1String("___qt_very_unlikely_prefix_")));
return result;
}
@@ -442,10 +449,7 @@ static QString strippedText(QString s)
[mPopUpButton setHidden:chooseDirsOnly]; // TODO hide the whole sunken pane instead?
if (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) {
- QStringList ext = [self acceptableExtensionsForSave];
- const QString defaultSuffix = mOptions->defaultSuffix();
- if (!ext.isEmpty() && !defaultSuffix.isEmpty())
- ext.prepend(defaultSuffix);
+ const QStringList ext = [self acceptableExtensionsForSave];
[mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : qt_mac_QStringListToNSMutableArray(ext)];
} else {
[mOpenPanel setAllowedFileTypes:nil]; // delegate panel:shouldEnableURL: does the file filtering for NSOpenPanel
diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm
index 7a550b163b..b3c2d5ae90 100644
--- a/src/plugins/platforms/cocoa/qcocoamenu.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenu.mm
@@ -44,9 +44,11 @@
#include <QtCore/QtDebug>
#include "qcocoaapplication.h"
+#include "qcocoaintegration.h"
#include "qcocoamenuloader.h"
#include "qcocoamenubar.h"
#include "qcocoawindow.h"
+#include "qcocoascreen.h"
QT_BEGIN_NAMESPACE
@@ -364,8 +366,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
diff --git a/src/plugins/platforms/cocoa/qcocoansmenu.mm b/src/plugins/platforms/cocoa/qcocoansmenu.mm
index 996a4ff194..6be2569dbc 100644
--- a/src/plugins/platforms/cocoa/qcocoansmenu.mm
+++ b/src/plugins/platforms/cocoa/qcocoansmenu.mm
@@ -40,6 +40,8 @@
#import "qcocoansmenu.h"
#include "qcocoamenu.h"
#include "qcocoamenuitem.h"
+#include "qcocoamenubar.h"
+#include "qcocoawindow.h"
#import "qnsview.h"
#include <QtCore/qmetaobject.h>
@@ -291,6 +293,19 @@ static NSString *qt_mac_removePrivateUnicode(NSString* string)
return nil;
}
+// Cocoa will query the menu item's target for the worksWhenModal selector.
+// So we need to implement this to allow the items to be handled correctly
+// when a modal dialog is visible.
+- (BOOL)worksWhenModal
+{
+ if (!QGuiApplication::modalWindow())
+ return YES;
+ const auto &qpaMenu = static_cast<QCocoaNSMenu *>(self).qpaMenu;
+ if (auto *mb = qobject_cast<QCocoaMenuBar *>(qpaMenu->menuParent()))
+ return QGuiApplication::modalWindow()->handle() == mb->cocoaWindow() ? YES : NO;
+ return YES;
+}
+
@end
#undef CHECK_MENU_CLASS
diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
index e756f0aeb0..f4c968ab57 100644
--- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
+++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm
@@ -72,8 +72,6 @@
**
****************************************************************************/
-#define QT_MAC_SYSTEMTRAY_USE_GROWL
-
#include "qcocoasystemtrayicon.h"
#ifndef QT_NO_SYSTEMTRAYICON
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index e4dd71f01b..471a19adb0 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -498,9 +498,10 @@ NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags)
{
const Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
const bool frameless = (flags & Qt::FramelessWindowHint) || windowIsPopupType(type);
+ const bool resizeable = type != Qt::Dialog; // Dialogs: remove zoom button by disabling resize
- // Select base window type.
- NSUInteger styleMask = frameless ? NSBorderlessWindowMask : NSResizableWindowMask;
+ // Select base window type. Note that the value of NSBorderlessWindowMask is 0.
+ NSUInteger styleMask = (frameless || !resizeable) ? NSBorderlessWindowMask : NSResizableWindowMask;
if (frameless) {
// No further customizations for frameless since there are no window decorations.
@@ -1151,23 +1152,6 @@ void QCocoaWindow::handleExposeEvent(const QRegion &region)
m_exposedRect = QRect();
}
- QWindowPrivate *windowPrivate = qt_window_private(window());
- if (windowPrivate->updateRequestPending) {
- // We can only deliver update request events when the window is exposed,
- // and we also have to make sure we deliver any change to the exposed
- // rect as a real expose event (including going from non-exposed to
- // exposed). FIXME: Should this logic live in QGuiApplication?
- if (isExposed() && m_exposedRect == previouslyExposedRect) {
- qCDebug(lcQpaCocoaDrawing) << "QCocoaWindow::handleExposeEvent" << window() << region << "as update request";
- windowPrivate->deliverUpdateRequest();
- return;
- } else {
- // Since updateRequestPending is still set, we will issue a deferred setNeedsDisplay
- // from drawRect and get back into this code on the next display cycle, delivering
- // the pending update request.
- }
- }
-
qCDebug(lcQpaCocoaDrawing) << "QCocoaWindow::handleExposeEvent" << window() << region << "isExposed" << isExposed();
QWindowSystemInterface::handleExposeEvent<QWindowSystemInterface::SynchronousDelivery>(window(), region);
}
@@ -1342,7 +1326,7 @@ void QCocoaWindow::recreateWindowIfNeeded()
void QCocoaWindow::requestUpdate()
{
qCDebug(lcQpaCocoaDrawing) << "QCocoaWindow::requestUpdate" << window();
- [m_view setNeedsDisplay:YES];
+ [m_view requestUpdate];
}
void QCocoaWindow::requestActivateWindow()
diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h
index f8903725a6..e2ea862cd5 100644
--- a/src/plugins/platforms/cocoa/qnsview.h
+++ b/src/plugins/platforms/cocoa/qnsview.h
@@ -81,6 +81,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper));
NSEvent *m_currentlyInterpretedKeyEvent;
bool m_isMenuView;
QSet<quint32> m_acceptedKeyDowns;
+ bool m_updateRequested;
}
@property (nonatomic, retain) NSCursor *cursor;
@@ -105,6 +106,8 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper));
- (void)resetMouseButtons;
+- (void)requestUpdate;
+
- (void)handleMouseEvent:(NSEvent *)theEvent;
- (bool)handleMouseDownEvent:(NSEvent *)theEvent withButton:(int)buttonNumber;
- (bool)handleMouseDraggedEvent:(NSEvent *)theEvent withButton:(int)buttonNumber;
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index f9c28542a9..fd7f216e10 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -148,6 +148,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
m_isMenuView = false;
self.focusRingType = NSFocusRingTypeNone;
self.cursor = nil;
+ m_updateRequested = false;
}
return self;
}
@@ -300,6 +301,25 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
return m_platformWindow->isOpaque();
}
+- (void)requestUpdate
+{
+ if (self.needsDisplay) {
+ // If the view already has needsDisplay set it means that there may be code waiting for
+ // a real expose event, so we can't issue setNeedsDisplay now as a way to trigger an
+ // update request. We will re-trigger requestUpdate from drawRect.
+ return;
+ }
+
+ [self setNeedsDisplay:YES];
+ m_updateRequested = true;
+}
+
+- (void)setNeedsDisplayInRect:(NSRect)rect
+{
+ [super setNeedsDisplayInRect:rect];
+ m_updateRequested = false;
+}
+
- (void)drawRect:(NSRect)dirtyRect
{
Q_UNUSED(dirtyRect);
@@ -315,7 +335,11 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
exposedRegion += QRectF::fromCGRect(dirtyRects[i]).toRect();
qCDebug(lcQpaCocoaDrawing) << "[QNSView drawRect:]" << m_platformWindow->window() << exposedRegion;
+ [self updateRegion:exposedRegion];
+}
+- (void)updateRegion:(QRegion)dirtyRegion
+{
#ifndef QT_NO_OPENGL
if (m_glContext && m_shouldSetGLContextinDrawRect) {
[m_glContext->nsOpenGLContext() setView:self];
@@ -323,18 +347,24 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
}
#endif
- m_platformWindow->handleExposeEvent(exposedRegion);
+ QWindowPrivate *windowPrivate = qt_window_private(m_platformWindow->window());
+
+ if (m_updateRequested) {
+ Q_ASSERT(windowPrivate->updateRequestPending);
+ qCDebug(lcQpaCocoaWindow) << "Delivering update request to" << m_platformWindow->window();
+ windowPrivate->deliverUpdateRequest();
+ m_updateRequested = false;
+ } else {
+ m_platformWindow->handleExposeEvent(dirtyRegion);
+ }
- if (qt_window_private(m_platformWindow->window())->updateRequestPending) {
- // A call to QWindow::requestUpdate was issued during the expose event, or we
- // had to deliver a real expose event and still need to deliver the update.
- // But AppKit will reset the needsDisplay state of the view after completing
+ if (windowPrivate->updateRequestPending) {
+ // A call to QWindow::requestUpdate was issued during event delivery above,
+ // but AppKit will reset the needsDisplay state of the view after completing
// the current display cycle, so we need to defer the request to redisplay.
// FIXME: Perhaps this should be a trigger to enable CADisplayLink?
qCDebug(lcQpaCocoaDrawing) << "[QNSView drawRect:] issuing deferred setNeedsDisplay due to pending update request";
- dispatch_async(dispatch_get_main_queue (), ^{
- [self setNeedsDisplay:YES];
- });
+ dispatch_async(dispatch_get_main_queue (), ^{ [self requestUpdate]; });
}
}
@@ -351,7 +381,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
qCDebug(lcQpaCocoaDrawing) << "[QNSView updateLayer]" << m_platformWindow->window();
// FIXME: Find out if there's a way to resolve the dirty rect like in drawRect:
- m_platformWindow->handleExposeEvent(QRectF::fromCGRect(self.bounds).toRect());
+ [self updateRegion:QRectF::fromCGRect(self.bounds).toRect()];
}
- (void)viewDidChangeBackingProperties