diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h index 76624835a7..5ec2ecb2e0 100644 --- a/src/gui/kernel/qplatformwindow.h +++ b/src/gui/kernel/qplatformwindow.h @@ -170,6 +170,20 @@ protected: QScopedPointer d_ptr; }; +// ----------------- QPlatformInterface ----------------- + +namespace QPlatformInterface::Private { + +#if defined(Q_OS_MACOS) +struct Q_GUI_EXPORT QCocoaWindow +{ + QT_DECLARE_PLATFORM_INTERFACE(QCocoaWindow) + virtual void setContentBorderEnabled(bool enable) = 0; +}; +#endif + +} // QPlatformInterface::Private + QT_END_NAMESPACE #endif //QPLATFORMWINDOW_H diff --git a/src/gui/platform/macos/qcocoaplatforminterface.mm b/src/gui/platform/macos/qcocoaplatforminterface.mm index 2fc9228ab1..a14335e077 100644 --- a/src/gui/platform/macos/qcocoaplatforminterface.mm +++ b/src/gui/platform/macos/qcocoaplatforminterface.mm @@ -41,6 +41,7 @@ #include #include #include +#include #include @@ -52,6 +53,7 @@ using namespace QPlatformInterface::Private; QT_DEFINE_PLATFORM_INTERFACE(QCocoaGLContext, QOpenGLContext); QT_DEFINE_PRIVATE_PLATFORM_INTERFACE(QCocoaGLIntegration); +QT_DEFINE_PRIVATE_PLATFORM_INTERFACE(QCocoaWindow); QOpenGLContext *QPlatformInterface::QCocoaGLContext::fromNative(NSOpenGLContext *nativeContext, QOpenGLContext *shareContext) { diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h index 7d4c5884b3..4f82faf39b 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h @@ -105,9 +105,6 @@ private: // deregisters. static void registerTouchWindow(QWindow *window, bool enable); - // Enable the unified title and toolbar area for a window. - static void setContentBorderEnabled(QWindow *window, bool enable); - // Set the size of the unified title and toolbar area. static void setContentBorderThickness(QWindow *window, int topThickness, int bottomThickness); diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index 426e413a86..77187f2d20 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -118,8 +118,6 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter return NativeResourceForIntegrationFunction(QCocoaNativeInterface::registerContentBorderArea); if (resource.toLower() == "setcontentborderareaenabled") return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderAreaEnabled); - if (resource.toLower() == "setcontentborderenabled") - return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderEnabled); if (resource.toLower() == "setnstoolbar") return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setNSToolbar); if (resource.toLower() == "testcontentborderposition") @@ -260,16 +258,6 @@ void QCocoaNativeInterface::setContentBorderAreaEnabled(QWindow *window, quintpt cocoaWindow->setContentBorderAreaEnabled(identifier, enable); } -void QCocoaNativeInterface::setContentBorderEnabled(QWindow *window, bool enable) -{ - if (!window) - return; - - QCocoaWindow *cocoaWindow = static_cast(window->handle()); - if (cocoaWindow) - cocoaWindow->setContentBorderEnabled(enable); -} - void QCocoaNativeInterface::setNSToolbar(QWindow *window, void *nsToolbar) { QCocoaIntegration::instance()->setToolbar(window, static_cast(nsToolbar)); diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index e4debd669d..0c607320f8 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -98,7 +98,8 @@ class QDebug; class QCocoaMenuBar; -class QCocoaWindow : public QObject, public QPlatformWindow +class QCocoaWindow : public QObject, public QPlatformWindow, + public QPlatformInterface::Private::QCocoaWindow { Q_OBJECT public: @@ -192,7 +193,7 @@ public: void setContentBorderThickness(int topThickness, int bottomThickness); void registerContentBorderArea(quintptr identifier, int upper, int lower); void setContentBorderAreaEnabled(quintptr identifier, bool enable); - void setContentBorderEnabled(bool enable); + void setContentBorderEnabled(bool enable) override; bool testContentBorderAreaPosition(int position) const; void applyContentBorderThickness(NSWindow *window = nullptr); void updateNSToolbar(); diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index 7fabb4ae7c..9379fb04ef 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.cpp @@ -67,9 +67,7 @@ #include "qtoolbar_p.h" #endif #include "qwidgetanimator_p.h" -#ifdef Q_OS_MACOS -#include -#endif +#include QT_BEGIN_NAMESPACE @@ -1351,28 +1349,23 @@ bool QMainWindow::event(QEvent *event) \since 5.2 */ -void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool set) +void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool enabled) { #ifdef Q_OS_MACOS + if (!isWindow()) + return; + Q_D(QMainWindow); - if (isWindow()) { - d->useUnifiedToolBar = set; - createWinId(); + d->useUnifiedToolBar = enabled; + createWinId(); - QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); - if (!nativeInterface) - return; // Not Cocoa platform plugin. - QPlatformNativeInterface::NativeResourceForIntegrationFunction function = - nativeInterface->nativeResourceFunctionForIntegration("setContentBorderEnabled"); - if (!function) - return; // Not Cocoa platform plugin. + using namespace QPlatformInterface::Private; + if (auto *platformWindow = dynamic_cast(window()->windowHandle()->handle())) + platformWindow->setContentBorderEnabled(enabled); - typedef void (*SetContentBorderEnabledFunction)(QWindow *window, bool enable); - (reinterpret_cast(function))(window()->windowHandle(), set); - update(); - } + update(); #else - Q_UNUSED(set) + Q_UNUSED(enabled) #endif }