macOS: remove the popup stack from QCocoaIntegration

Since popup handling is now done exclusively by Q(Gui)Application, we
don't need to keep track of the popup stack in the Cocoa plugin anymore.

Fixes: QTBUG-96450
Change-Id: I869f36f52bc2210b6c92efd9425502de4122c553
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Volker Hilsheimer 2021-09-15 14:38:22 +02:00
parent 1e5249bfa4
commit 65c9acc5f5
5 changed files with 2 additions and 77 deletions

View File

@ -124,11 +124,6 @@ public:
NSToolbar *toolbar(QWindow *window) const;
void clearToolbars();
void pushPopupWindow(QCocoaWindow *window);
QCocoaWindow *popPopupWindow();
QCocoaWindow *activePopupWindow() const;
QList<QCocoaWindow *> *popupWindowStack();
void setApplicationIcon(const QIcon &icon) const override;
void beep() const override;
@ -160,7 +155,6 @@ private:
mutable QCocoaVulkanInstance *mCocoaVulkanInstance = nullptr;
#endif
QHash<QWindow *, NSToolbar *> mToolbars;
QList<QCocoaWindow *> m_popupWindowStack;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QCocoaIntegration::Options)

View File

@ -454,30 +454,6 @@ void QCocoaIntegration::clearToolbars()
mToolbars.clear();
}
void QCocoaIntegration::pushPopupWindow(QCocoaWindow *window)
{
m_popupWindowStack.append(window);
}
QCocoaWindow *QCocoaIntegration::popPopupWindow()
{
if (m_popupWindowStack.isEmpty())
return nullptr;
return m_popupWindowStack.takeLast();
}
QCocoaWindow *QCocoaIntegration::activePopupWindow() const
{
if (m_popupWindowStack.isEmpty())
return nullptr;
return m_popupWindowStack.front();
}
QList<QCocoaWindow *> *QCocoaIntegration::popupWindowStack()
{
return &m_popupWindowStack;
}
void QCocoaIntegration::setApplicationIcon(const QIcon &icon) const
{
// Fall back to a size that looks good on the highest resolution screen available

View File

@ -204,17 +204,13 @@ QCocoaWindow::~QCocoaWindow()
if (!isForeignWindow())
[[NSNotificationCenter defaultCenter] removeObserver:m_view];
if (QCocoaIntegration *cocoaIntegration = QCocoaIntegration::instance()) {
// While it is unlikely that this window will be in the popup stack
// during deletetion we clear any pointers here to make sure.
cocoaIntegration->popupWindowStack()->removeAll(this);
#if QT_CONFIG(vulkan)
if (QCocoaIntegration *cocoaIntegration = QCocoaIntegration::instance()) {
auto vulcanInstance = cocoaIntegration->getCocoaVulkanInstance();
if (vulcanInstance)
vulcanInstance->destroySurface(m_vulkanSurface);
#endif
}
#endif
[m_view release];
[m_nsWindow close];
@ -336,11 +332,6 @@ void QCocoaWindow::setVisible(bool visible)
// so we can send the geometry change. FIXME: Get rid of this workaround.
handleGeometryChange();
// Register popup windows. The Cocoa platform plugin will forward mouse events
// to them and close them when needed.
if (window()->type() == Qt::Popup || window()->type() == Qt::ToolTip)
QCocoaIntegration::instance()->pushPopupWindow(this);
if (parentCocoaWindow) {
// The parent window might have moved while this window was hidden,
// update the window geometry if there is a parent.
@ -449,9 +440,6 @@ void QCocoaWindow::setVisible(bool visible)
removeMonitor();
if (window()->type() == Qt::Popup || window()->type() == Qt::ToolTip)
QCocoaIntegration::instance()->popupWindowStack()->removeAll(this);
if (parentCocoaWindow && window()->type() == Qt::Popup) {
NSWindow *nativeParentWindow = parentCocoaWindow->nativeWindow();
if (m_resizableTransientParent

View File

@ -58,7 +58,6 @@ QT_DECLARE_NAMESPACED_OBJC_INTERFACE(QNSView, NSView
@interface QNSView (MouseAPI)
- (void)handleMouseEvent:(NSEvent *)theEvent;
- (void)handleFrameStrutMouseEvent:(NSEvent *)theEvent;
- (bool)closePopups:(NSEvent *)theEvent;
- (void)resetMouseButtons;
@end

View File

@ -259,38 +259,6 @@ static const QPointingDevice *pointingDeviceFor(qint64 deviceID)
QWindowSystemInterface::handleFrameStrutMouseEvent(m_platformWindow->window(),
timestamp, qtWindowPoint, qtScreenPoint, m_frameStrutButtons, button, eventType);
}
- (bool)closePopups:(NSEvent *)theEvent
{
QList<QCocoaWindow *> *popups = QCocoaIntegration::instance()->popupWindowStack();
if (!popups->isEmpty()) {
// Check if the click is outside all popups.
bool inside = false;
QPointF qtScreenPoint = QCocoaScreen::mapFromNative([self screenMousePoint:theEvent]);
for (QList<QCocoaWindow *>::const_iterator it = popups->begin(); it != popups->end(); ++it) {
if ((*it)->geometry().contains(qtScreenPoint.toPoint())) {
inside = true;
break;
}
}
// Close the popups if the click was outside.
if (!inside) {
bool selfClosed = false;
Qt::WindowType type = QCocoaIntegration::instance()->activePopupWindow()->window()->type();
while (QCocoaWindow *popup = QCocoaIntegration::instance()->popPopupWindow()) {
selfClosed = self == popup->view();
QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::SynchronousDelivery>(popup->window());
if (!m_platformWindow)
return true; // Bail out if window was destroyed
}
// Consume the mouse event when closing the popup, except for tool tips
// were it's expected that the event is processed normally.
if (type != Qt::ToolTip || selfClosed)
return true;
}
}
return false;
}
@end
@implementation QNSView (Mouse)