diff options
Diffstat (limited to 'src/plugins/platforms/cocoa')
22 files changed, 411 insertions, 100 deletions
diff --git a/src/plugins/platforms/cocoa/.prev_CMakeLists.txt b/src/plugins/platforms/cocoa/.prev_CMakeLists.txt new file mode 100644 index 0000000000..1491340b65 --- /dev/null +++ b/src/plugins/platforms/cocoa/.prev_CMakeLists.txt @@ -0,0 +1,150 @@ +# Generated from cocoa.pro. + +##################################################################### +## QCocoaIntegrationPlugin Plugin: +##################################################################### + +qt_add_plugin(QCocoaIntegrationPlugin + OUTPUT_NAME qcocoa + TYPE platforms + SOURCES + main.mm + messages.cpp messages.h + qcocoaapplication.h qcocoaapplication.mm + qcocoaapplicationdelegate.h qcocoaapplicationdelegate.mm + qcocoabackingstore.h qcocoabackingstore.mm + qcocoaclipboard.h qcocoaclipboard.mm + qcocoacursor.h qcocoacursor.mm + qcocoadrag.h qcocoadrag.mm + qcocoaeventdispatcher.h qcocoaeventdispatcher.mm + qcocoahelpers.h qcocoahelpers.mm + qcocoainputcontext.h qcocoainputcontext.mm + qcocoaintegration.h qcocoaintegration.mm + qcocoaintrospection.h qcocoaintrospection.mm + qcocoakeymapper.h qcocoakeymapper.mm + qcocoamenu.h qcocoamenu.mm + qcocoamenubar.h qcocoamenubar.mm + qcocoamenuitem.h qcocoamenuitem.mm + qcocoamenuloader.h qcocoamenuloader.mm + qcocoamimetypes.h qcocoamimetypes.mm + qcocoanativeinterface.h qcocoanativeinterface.mm + qcocoansmenu.h qcocoansmenu.mm + qcocoascreen.h qcocoascreen.mm + qcocoaservices.h qcocoaservices.mm + qcocoasystemtrayicon.h qcocoasystemtrayicon.mm + qcocoatheme.h qcocoatheme.mm + qcocoawindow.h qcocoawindow.mm + qcocoawindowmanager.h qcocoawindowmanager.mm + qiosurfacegraphicsbuffer.h qiosurfacegraphicsbuffer.mm + qmacclipboard.h qmacclipboard.mm + qmultitouch_mac.mm qmultitouch_mac_p.h + qnsview.h qnsview.mm + qnswindow.h qnswindow.mm + qnswindowdelegate.h qnswindowdelegate.mm + PUBLIC_LIBRARIES + ${FWAppKit} + ${FWCarbon} + ${FWCoreServices} + ${FWCoreVideo} + ${FWIOKit} + ${FWIOSurface} + ${FWMetal} + ${FWQuartzCore} + Cups::Cups + Qt::ClipboardSupportPrivate + Qt::Core + Qt::CorePrivate + Qt::FontDatabaseSupportPrivate + Qt::GraphicsSupportPrivate + Qt::Gui + Qt::GuiPrivate + Qt::ThemeSupportPrivate +) + +# Resources: +set(qcocoaresources_resource_files + "images/sizeallcursor.png" + "images/spincursor.png" + "images/waitcursor.png" +) + +qt_add_resource(QCocoaIntegrationPlugin "qcocoaresources" + PREFIX + "/qt-project.org/mac/cursors" + FILES + ${qcocoaresources_resource_files} +) + + +#### Keys ignored in scope 1:.:.:cocoa.pro:<TRUE>: +# OTHER_FILES = "cocoa.json" + +## Scopes: +##################################################################### + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_opengl + SOURCES + qcocoaglcontext.h qcocoaglcontext.mm +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_vulkan + SOURCES + qcocoavulkaninstance.h qcocoavulkaninstance.mm + PUBLIC_LIBRARIES + Qt::VulkanSupportPrivate +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_accessibility + SOURCES + qcocoaaccessibility.h qcocoaaccessibility.mm + qcocoaaccessibilityelement.h qcocoaaccessibilityelement.mm + PUBLIC_LIBRARIES + Qt::AccessibilitySupportPrivate +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_sessionmanager + SOURCES + qcocoasessionmanager.cpp qcocoasessionmanager.h +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION TARGET Qt::PlatformCompositorSupportPrivate + PUBLIC_LIBRARIES + Qt::PlatformCompositorSupportPrivate +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION TARGET Qt::Widgets + SOURCES + qpaintengine_mac.mm qpaintengine_mac_p.h + PUBLIC_LIBRARIES + Qt::WidgetsPrivate +) + +#### Keys ignored in scope 8:.:.:cocoa.pro:TARGET Qt::Widgets: +# QT_FOR_CONFIG = "widgets" + +qt_extend_target(QCocoaIntegrationPlugin CONDITION TARGET Qt::PrintSupport AND TARGET Qt::Widgets + SOURCES + qcocoaprintdevice.h qcocoaprintdevice.mm + qcocoaprintersupport.h qcocoaprintersupport.mm + qprintengine_mac.mm qprintengine_mac_p.h + PUBLIC_LIBRARIES + Qt::PrintSupportPrivate +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_colordialog AND TARGET Qt::Widgets + SOURCES + qcocoacolordialoghelper.h qcocoacolordialoghelper.mm +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_filedialog AND TARGET Qt::Widgets + SOURCES + qcocoafiledialoghelper.h qcocoafiledialoghelper.mm +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_fontdialog AND TARGET Qt::Widgets + SOURCES + qcocoafontdialoghelper.h qcocoafontdialoghelper.mm +) + +#### Keys ignored in scope 13:.:.:cocoa.pro:NOT TARGET___equals____ss_QT_DEFAULT_QPA_PLUGIN: +# PLUGIN_EXTENDS = "-" diff --git a/src/plugins/platforms/cocoa/CMakeLists.txt b/src/plugins/platforms/cocoa/CMakeLists.txt new file mode 100644 index 0000000000..9e8b162aec --- /dev/null +++ b/src/plugins/platforms/cocoa/CMakeLists.txt @@ -0,0 +1,154 @@ +# Generated from cocoa.pro. + +# special case: +qt_find_package(Cups PROVIDED_TARGETS Cups::Cups) + +##################################################################### +## QCocoaIntegrationPlugin Plugin: +##################################################################### + +qt_add_plugin(QCocoaIntegrationPlugin + OUTPUT_NAME qcocoa + DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES cocoa # special case + TYPE platforms + SOURCES + main.mm + messages.cpp messages.h + qcocoaapplication.h qcocoaapplication.mm + qcocoaapplicationdelegate.h qcocoaapplicationdelegate.mm + qcocoabackingstore.h qcocoabackingstore.mm + qcocoaclipboard.h qcocoaclipboard.mm + qcocoacursor.h qcocoacursor.mm + qcocoadrag.h qcocoadrag.mm + qcocoaeventdispatcher.h qcocoaeventdispatcher.mm + qcocoahelpers.h qcocoahelpers.mm + qcocoainputcontext.h qcocoainputcontext.mm + qcocoaintegration.h qcocoaintegration.mm + qcocoaintrospection.h qcocoaintrospection.mm + qcocoakeymapper.h qcocoakeymapper.mm + qcocoamenu.h qcocoamenu.mm + qcocoamenubar.h qcocoamenubar.mm + qcocoamenuitem.h qcocoamenuitem.mm + qcocoamenuloader.h qcocoamenuloader.mm + qcocoamimetypes.h qcocoamimetypes.mm + qcocoanativeinterface.h qcocoanativeinterface.mm + qcocoansmenu.h qcocoansmenu.mm + qcocoascreen.h qcocoascreen.mm + qcocoaservices.h qcocoaservices.mm + qcocoasystemtrayicon.h qcocoasystemtrayicon.mm + qcocoatheme.h qcocoatheme.mm + qcocoawindow.h qcocoawindow.mm + qcocoawindowmanager.h qcocoawindowmanager.mm + qiosurfacegraphicsbuffer.h qiosurfacegraphicsbuffer.mm + qmacclipboard.h qmacclipboard.mm + qmultitouch_mac.mm qmultitouch_mac_p.h + qnsview.h qnsview.mm + qnswindow.h qnswindow.mm + qnswindowdelegate.h qnswindowdelegate.mm + PUBLIC_LIBRARIES + ${FWAppKit} + ${FWCarbon} + ${FWCoreServices} + ${FWCoreVideo} + ${FWIOKit} + ${FWIOSurface} + ${FWMetal} + ${FWQuartzCore} + Cups::Cups + Qt::ClipboardSupportPrivate + Qt::Core + Qt::CorePrivate + Qt::FontDatabaseSupportPrivate + Qt::GraphicsSupportPrivate + Qt::Gui + Qt::GuiPrivate + Qt::ThemeSupportPrivate +) + +# Resources: +set(qcocoaresources_resource_files + "images/sizeallcursor.png" + "images/spincursor.png" + "images/waitcursor.png" +) + +qt_add_resource(QCocoaIntegrationPlugin "qcocoaresources" + PREFIX + "/qt-project.org/mac/cursors" + FILES + ${qcocoaresources_resource_files} +) + + +#### Keys ignored in scope 1:.:.:cocoa.pro:<TRUE>: +# OTHER_FILES = "cocoa.json" + +## Scopes: +##################################################################### + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_opengl + SOURCES + qcocoaglcontext.h qcocoaglcontext.mm +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_vulkan + SOURCES + qcocoavulkaninstance.h qcocoavulkaninstance.mm + PUBLIC_LIBRARIES + Qt::VulkanSupportPrivate +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_accessibility + SOURCES + qcocoaaccessibility.h qcocoaaccessibility.mm + qcocoaaccessibilityelement.h qcocoaaccessibilityelement.mm + PUBLIC_LIBRARIES + Qt::AccessibilitySupportPrivate +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_sessionmanager + SOURCES + qcocoasessionmanager.cpp qcocoasessionmanager.h +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION TARGET Qt::PlatformCompositorSupportPrivate + PUBLIC_LIBRARIES + Qt::PlatformCompositorSupportPrivate +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION TARGET Qt::Widgets + SOURCES + qpaintengine_mac.mm qpaintengine_mac_p.h + PUBLIC_LIBRARIES + Qt::WidgetsPrivate +) + +#### Keys ignored in scope 8:.:.:cocoa.pro:TARGET Qt::Widgets: +# QT_FOR_CONFIG = "widgets" + +qt_extend_target(QCocoaIntegrationPlugin CONDITION TARGET Qt::PrintSupport AND TARGET Qt::Widgets + SOURCES + qcocoaprintdevice.h qcocoaprintdevice.mm + qcocoaprintersupport.h qcocoaprintersupport.mm + qprintengine_mac.mm qprintengine_mac_p.h + PUBLIC_LIBRARIES + Qt::PrintSupportPrivate +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_colordialog AND TARGET Qt::Widgets + SOURCES + qcocoacolordialoghelper.h qcocoacolordialoghelper.mm +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_filedialog AND TARGET Qt::Widgets + SOURCES + qcocoafiledialoghelper.h qcocoafiledialoghelper.mm +) + +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_fontdialog AND TARGET Qt::Widgets + SOURCES + qcocoafontdialoghelper.h qcocoafontdialoghelper.mm +) + +#### Keys ignored in scope 13:.:.:cocoa.pro:NOT TARGET___equals____ss_QT_DEFAULT_QPA_PLUGIN: +# PLUGIN_EXTENDS = "-" diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index a919963cf4..953346c56e 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -101,6 +101,8 @@ QT += \ qtConfig(vulkan): QT += vulkan_support-private +qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private + CONFIG += no_app_extension_api_only qtHaveModule(widgets) { diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index 2b4c71f279..102f00a25d 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -189,7 +189,7 @@ void QNSWindowBackingStore::flush(QWindow *window, const QRegion ®ion, const // its parent/ancestor, and the parent/ancestor being the one locked by AppKit. // In this case we also need to lock and unlock focus manually. const bool shouldHandleViewLockManually = [NSView focusView] != view; - if (shouldHandleViewLockManually && ![view lockFocusIfCanDraw]) { + if (shouldHandleViewLockManually && !QT_IGNORE_DEPRECATIONS([view lockFocusIfCanDraw])) { qWarning() << "failed to lock focus of" << view; return; } @@ -263,14 +263,13 @@ void QNSWindowBackingStore::flush(QWindow *window, const QRegion ®ion, const // ------------------------------------------------------------------------- if (shouldHandleViewLockManually) - [view unlockFocus]; + QT_IGNORE_DEPRECATIONS([view unlockFocus]); if (drawingOutsideOfDisplayCycle) { redrawRoundedBottomCorners([view convertRect:region.boundingRect().toCGRect() toView:nil]); - [view.window flushWindow]; + QT_IGNORE_DEPRECATIONS([view.window flushWindow]); } - // Done flushing to NSWindow backingstore QCocoaWindow *topLevelCocoaWindow = static_cast<QCocoaWindow *>(topLevelWindow->handle()); diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index c9fa035d87..ff08a306c4 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -44,6 +44,7 @@ #include "qcocoacolordialoghelper.h" #include "qcocoahelpers.h" #include "qcocoaeventdispatcher.h" +#include "private/qcoregraphics_p.h" #import <AppKit/AppKit.h> @@ -181,33 +182,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate); - (void)updateQtColor { NSColor *color = [mColorPanel color]; - NSString *colorSpaceName = [color colorSpaceName]; - if (colorSpaceName == NSDeviceCMYKColorSpace) { - CGFloat cyan = 0, magenta = 0, yellow = 0, black = 0, alpha = 0; - [color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; - mQtColor.setCmykF(cyan, magenta, yellow, black, alpha); - } else if (colorSpaceName == NSCalibratedRGBColorSpace || colorSpaceName == NSDeviceRGBColorSpace) { - CGFloat red = 0, green = 0, blue = 0, alpha = 0; - [color getRed:&red green:&green blue:&blue alpha:&alpha]; - mQtColor.setRgbF(red, green, blue, alpha); - } else if (colorSpaceName == NSNamedColorSpace) { - NSColor *tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; - CGFloat red = 0, green = 0, blue = 0, alpha = 0; - [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha]; - mQtColor.setRgbF(red, green, blue, alpha); - } else { - NSColorSpace *colorSpace = [color colorSpace]; - if ([colorSpace colorSpaceModel] == NSCMYKColorSpaceModel && [color numberOfComponents] == 5){ - CGFloat components[5]; - [color getComponents:components]; - mQtColor.setCmykF(components[0], components[1], components[2], components[3], components[4]); - } else { - NSColor *tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; - CGFloat red = 0, green = 0, blue = 0, alpha = 0; - [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha]; - mQtColor.setRgbF(red, green, blue, alpha); - } - } + mQtColor = qt_mac_toQColor(color); if (mHelper) emit mHelper->currentColorChanged(mQtColor); } diff --git a/src/plugins/platforms/cocoa/qcocoacursor.h b/src/plugins/platforms/cocoa/qcocoacursor.h index 5b008eff35..6589891ef2 100644 --- a/src/plugins/platforms/cocoa/qcocoacursor.h +++ b/src/plugins/platforms/cocoa/qcocoacursor.h @@ -63,8 +63,8 @@ private: QHash<Qt::CursorShape, NSCursor *> m_cursors; NSCursor *convertCursor(QCursor *cursor); NSCursor *createCursorData(QCursor * cursor); - NSCursor *createCursorFromBitmap(const QBitmap *bitmap, const QBitmap *mask, const QPoint hotspot = QPoint()); - NSCursor *createCursorFromPixmap(const QPixmap pixmap, const QPoint hotspot = QPoint()); + NSCursor *createCursorFromBitmap(const QBitmap &bitmap, const QBitmap &mask, const QPoint hotspot = QPoint()); + NSCursor *createCursorFromPixmap(const QPixmap &pixmap, const QPoint hotspot = QPoint()); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoacursor.mm b/src/plugins/platforms/cocoa/qcocoacursor.mm index c10ada1ada..8ca72ec619 100644 --- a/src/plugins/platforms/cocoa/qcocoacursor.mm +++ b/src/plugins/platforms/cocoa/qcocoacursor.mm @@ -243,7 +243,7 @@ NSCursor *QCocoaCursor::createCursorData(QCursor *cursor) switch (cursor->shape()) { case Qt::BitmapCursor: { if (cursor->pixmap().isNull()) - return createCursorFromBitmap(cursor->bitmap(), cursor->mask(), hotspot); + return createCursorFromBitmap(cursor->bitmap(Qt::ReturnByValue), cursor->mask(Qt::ReturnByValue), hotspot); else return createCursorFromPixmap(cursor->pixmap(), hotspot); break; } @@ -301,17 +301,17 @@ NSCursor *QCocoaCursor::createCursorData(QCursor *cursor) if (cursorData) { QBitmap bitmap(QBitmap::fromData(QSize(16, 16), cursorData, QImage::Format_Mono)); QBitmap mask(QBitmap::fromData(QSize(16, 16), cursorMaskData, QImage::Format_Mono)); - return (createCursorFromBitmap(&bitmap, &mask, hotspot)); + return (createCursorFromBitmap(bitmap, mask, hotspot)); } return nil; // should not happen, all cases covered above } -NSCursor *QCocoaCursor::createCursorFromBitmap(const QBitmap *bitmap, const QBitmap *mask, const QPoint hotspot) +NSCursor *QCocoaCursor::createCursorFromBitmap(const QBitmap &bitmap, const QBitmap &mask, const QPoint hotspot) { - QImage finalCursor(bitmap->size(), QImage::Format_ARGB32); - QImage bmi = bitmap->toImage().convertToFormat(QImage::Format_RGB32); - QImage bmmi = mask->toImage().convertToFormat(QImage::Format_RGB32); + QImage finalCursor(bitmap.size(), QImage::Format_ARGB32); + QImage bmi = bitmap.toImage().convertToFormat(QImage::Format_RGB32); + QImage bmmi = mask.toImage().convertToFormat(QImage::Format_RGB32); for (int row = 0; row < finalCursor.height(); ++row) { QRgb *bmData = reinterpret_cast<QRgb *>(bmi.scanLine(row)); QRgb *bmmData = reinterpret_cast<QRgb *>(bmmi.scanLine(row)); @@ -332,7 +332,7 @@ NSCursor *QCocoaCursor::createCursorFromBitmap(const QBitmap *bitmap, const QBit return createCursorFromPixmap(QPixmap::fromImage(finalCursor), hotspot); } -NSCursor *QCocoaCursor::createCursorFromPixmap(const QPixmap pixmap, const QPoint hotspot) +NSCursor *QCocoaCursor::createCursorFromPixmap(const QPixmap &pixmap, const QPoint hotspot) { NSPoint hotSpot = NSMakePoint(hotspot.x(), hotspot.y()); auto *image = [NSImage imageFromQImage:pixmap.toImage()]; diff --git a/src/plugins/platforms/cocoa/qcocoadrag.mm b/src/plugins/platforms/cocoa/qcocoadrag.mm index b4a16ab912..3525fddfd1 100644 --- a/src/plugins/platforms/cocoa/qcocoadrag.mm +++ b/src/plugins/platforms/cocoa/qcocoadrag.mm @@ -40,9 +40,6 @@ #include "qcocoadrag.h" #include "qmacclipboard.h" #include "qcocoahelpers.h" -#ifndef QT_NO_WIDGETS -#include <QtWidgets/qwidget.h> -#endif #include <QtGui/private/qcoregraphics_p.h> QT_BEGIN_NAMESPACE @@ -189,19 +186,17 @@ QPixmap QCocoaDrag::dragPixmap(QDrag *drag, QPoint &hotSpot) const const int height = fm.height(); if (width > 0 && height > 0) { qreal dpr = 1.0; - if (const QWindow *sourceWindow = qobject_cast<QWindow *>(drag->source())) { - dpr = sourceWindow->devicePixelRatio(); - } -#ifndef QT_NO_WIDGETS - else if (const QWidget *sourceWidget = qobject_cast<QWidget *>(drag->source())) { - if (const QWindow *sourceWindow = sourceWidget->window()->windowHandle()) - dpr = sourceWindow->devicePixelRatio(); - } -#endif - else { - if (const QWindow *focusWindow = qApp->focusWindow()) - dpr = focusWindow->devicePixelRatio(); + QWindow *window = qobject_cast<QWindow *>(drag->source()); + if (!window && drag->source()->metaObject()->indexOfMethod("_q_closestWindowHandle()") != -1) { + QMetaObject::invokeMethod(drag->source(), "_q_closestWindowHandle", + Q_RETURN_ARG(QWindow *, window)); } + if (!window) + window = qApp->focusWindow(); + + if (window) + dpr = window->devicePixelRatio(); + pm = QPixmap(width * dpr, height * dpr); pm.setDevicePixelRatio(dpr); QPainter p(&pm); diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index ccb6e20071..9ca3892cbb 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -145,17 +145,17 @@ void QCocoaGLContext::initialize() // --------------------- Set NSOpenGLContext properties --------------------- const GLint interval = m_format.swapInterval() >= 0 ? m_format.swapInterval() : 1; - [m_context setValues:&interval forParameter:NSOpenGLCPSwapInterval]; + [m_context setValues:&interval forParameter:NSOpenGLContextParameterSwapInterval]; if (m_format.alphaBufferSize() > 0) { int zeroOpacity = 0; - [m_context setValues:&zeroOpacity forParameter:NSOpenGLCPSurfaceOpacity]; + [m_context setValues:&zeroOpacity forParameter:NSOpenGLContextParameterSurfaceOpacity]; } // OpenGL surfaces can be ordered either above(default) or below the NSWindow // FIXME: Promote to QSurfaceFormat option or property const GLint order = qt_mac_resolveOption(1, "QT_MAC_OPENGL_SURFACE_ORDER"); - [m_context setValues:&order forParameter:NSOpenGLCPSurfaceOrder]; + [m_context setValues:&order forParameter:NSOpenGLContextParameterSurfaceOrder]; updateSurfaceFormat(); @@ -342,7 +342,7 @@ void QCocoaGLContext::updateSurfaceFormat() return value; }; - m_format.setSwapInterval(glContextParameter(NSOpenGLCPSwapInterval)); + m_format.setSwapInterval(glContextParameter(NSOpenGLContextParameterSwapInterval)); if (oldContext) [oldContext makeCurrentContext]; @@ -390,7 +390,7 @@ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface) // Clear the current drawable and reset the active window, so that GL // commands that don't target a specific FBO will not end up stomping // on the previously set drawable. - qCDebug(lcQpaOpenGLContext) << "Clearing current drawable" << m_context.view << "for" << m_context; + qCDebug(lcQpaOpenGLContext) << "Clearing current drawable" << QT_IGNORE_DEPRECATIONS(m_context.view) << "for" << m_context; [m_context clearDrawable]; return true; } @@ -399,7 +399,7 @@ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface) auto *cocoaWindow = static_cast<QCocoaWindow *>(surface); QNSView *view = qnsview_cast(cocoaWindow->view()); - if (view == m_context.view) + if (view == QT_IGNORE_DEPRECATIONS(m_context.view)) return true; prepareDrawable(cocoaWindow); @@ -412,7 +412,7 @@ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface) auto updateCallback = [this, view]() { Q_ASSERT(QThread::currentThread() == qApp->thread()); - if (m_context.view != view) + if (QT_IGNORE_DEPRECATIONS(m_context.view) != view) return; m_needsUpdate = true; }; @@ -423,7 +423,7 @@ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface) m_updateObservers.append(QMacNotificationObserver(view, NSViewFrameDidChangeNotification, updateCallback)); m_updateObservers.append(QMacNotificationObserver(view.window, NSWindowDidChangeScreenNotification, updateCallback)); } else { - m_updateObservers.append(QMacNotificationObserver(view, NSViewGlobalFrameDidChangeNotification, updateCallback)); + m_updateObservers.append(QMacNotificationObserver(view, QT_IGNORE_DEPRECATIONS(NSViewGlobalFrameDidChangeNotification), updateCallback)); } m_updateObservers.append(QMacNotificationObserver([NSApplication sharedApplication], @@ -435,14 +435,14 @@ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface) // have the same effect as an update. // Now we are ready to associate the view with the context - m_context.view = view; - if (m_context.view != view) { + QT_IGNORE_DEPRECATIONS(m_context.view) = view; + if (QT_IGNORE_DEPRECATIONS(m_context.view) != view) { qCInfo(lcQpaOpenGLContext) << "Failed to set" << view << "as drawable for" << m_context; m_updateObservers.clear(); return false; } - qCInfo(lcQpaOpenGLContext) << "Set drawable for" << m_context << "to" << m_context.view; + qCInfo(lcQpaOpenGLContext) << "Set drawable for" << m_context << "to" << QT_IGNORE_DEPRECATIONS(m_context.view); return true; } @@ -467,7 +467,7 @@ void QCocoaGLContext::prepareDrawable(QCocoaWindow *platformWindow) } } - view.wantsBestResolutionOpenGLSurface = prefersBestResolutionOpenGLSurface; + QT_IGNORE_DEPRECATIONS(view.wantsBestResolutionOpenGLSurface) = prefersBestResolutionOpenGLSurface; } // NSOpenGLContext is not re-entrant. Even when using separate contexts per thread, @@ -483,7 +483,7 @@ void QCocoaGLContext::update() QMacAutoReleasePool pool; QMutexLocker locker(&s_reentrancyMutex); - qCInfo(lcQpaOpenGLContext) << "Updating" << m_context << "for" << m_context.view; + qCInfo(lcQpaOpenGLContext) << "Updating" << m_context << "for" << QT_IGNORE_DEPRECATIONS(m_context.view); [m_context update]; } @@ -501,7 +501,7 @@ void QCocoaGLContext::swapBuffers(QPlatformSurface *surface) return; } - if (m_context.view.layer) { + if (QT_IGNORE_DEPRECATIONS(m_context.view).layer) { // Flushing an NSOpenGLContext will hit the screen immediately, ignoring // any Core Animation transactions in place. This may result in major // visual artifacts if the flush happens out of sync with the size diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 95351f688b..1a718975d1 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -70,6 +70,14 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaDrawing) Q_DECLARE_LOGGING_CATEGORY(lcQpaMouse) Q_DECLARE_LOGGING_CATEGORY(lcQpaScreen) +#ifndef QT_IGNORE_DEPRECATIONS +#define QT_IGNORE_DEPRECATIONS(statement) \ + QT_WARNING_PUSH \ + QT_WARNING_DISABLE_DEPRECATED \ + statement \ + QT_WARNING_POP +#endif + class QPixmap; class QString; diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index c9eafa81d0..dab67268e3 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -514,8 +514,8 @@ QT_END_NAMESPACE - (NSButton *)createButtonWithTitle:(const char *)title { NSButton *button = [[NSButton alloc] initWithFrame:NSZeroRect]; - button.buttonType = NSMomentaryLightButton; - button.bezelStyle = NSRoundedBezelStyle; + button.buttonType = NSButtonTypeMomentaryLight; + button.bezelStyle = NSBezelStyleRounded; const QString &cleanTitle = QPlatformTheme::removeMnemonics(QCoreApplication::translate("QDialogButtonBox", title)); // FIXME: Not obvious, from Cocoa's documentation, that QString::toNSString() makes a deep copy button.title = (NSString *)cleanTitle.toCFString(); diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index 0c14e07551..30838ba254 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -128,6 +128,8 @@ public: void beep() const override; + void closePopups(QWindow *forWindow = nullptr); + private Q_SLOTS: void focusWindowChanged(QWindow *); diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index deddcd3f98..1fb250317d 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -68,6 +68,10 @@ #include <QtFontDatabaseSupport/private/qfontengine_coretext_p.h> +#if QT_CONFIG(opengl) +#include <QtPlatformCompositorSupport/qpa/qplatformbackingstoreopenglsupport.h> +#endif + #ifdef QT_WIDGETS_LIB #include <QtWidgets/qtwidgetsglobal.h> #if QT_CONFIG(filedialog) @@ -324,10 +328,16 @@ QPlatformBackingStore *QCocoaIntegration::createPlatformBackingStore(QWindow *wi return nullptr; } + QPlatformBackingStore *backingStore = nullptr; if (platformWindow->view().layer) - return new QCALayerBackingStore(window); + backingStore = new QCALayerBackingStore(window); else - return new QNSWindowBackingStore(window); + backingStore = new QNSWindowBackingStore(window); + +#if QT_CONFIG(opengl) + backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore)); +#endif + return backingStore; } QAbstractEventDispatcher *QCocoaIntegration::createEventDispatcher() const @@ -480,6 +490,19 @@ void QCocoaIntegration::beep() const NSBeep(); } +void QCocoaIntegration::closePopups(QWindow *forWindow) +{ + for (auto it = m_popupWindowStack.begin(); it != m_popupWindowStack.end();) { + auto *popup = *it; + if (!forWindow || popup->window()->transientParent() == forWindow) { + it = m_popupWindowStack.erase(it); + QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::SynchronousDelivery>(popup->window()); + } else { + ++it; + } + } +} + void QCocoaIntegration::focusWindowChanged(QWindow *focusWindow) { // Don't revert icon just because we lost focus diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 5aa41eeb22..cba2babb8d 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -53,7 +53,6 @@ #include <QtGui/private/qcoregraphics_p.h> #include <QtCore/QDebug> -#include <QtCore/QRegExp> QT_BEGIN_NAMESPACE @@ -343,7 +342,7 @@ NSMenuItem *QCocoaMenuItem::sync() m_native.image = [NSImage imageFromQIcon:m_icon withSize:m_iconSize]; - m_native.state = m_checked ? NSOnState : NSOffState; + m_native.state = m_checked ? NSControlStateValueOn : NSControlStateValueOff; return m_native; } diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index 8e7c86a0ef..bb1b1fc02e 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -282,7 +282,7 @@ void QCocoaSystemTrayIcon::statusItemClicked() emit activated(activationReason); if (NSMenu *menu = m_menu ? m_menu->nsMenu() : nil) - [m_statusItem popUpStatusItemMenu:menu]; + QT_IGNORE_DEPRECATIONS([m_statusItem popUpStatusItemMenu:menu]); } QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index b15c0ac31c..4bff1de515 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -151,6 +151,7 @@ public: Q_NOTIFICATION_HANDLER(NSWindowDidEndLiveResizeNotification) void windowDidEndLiveResize(); Q_NOTIFICATION_HANDLER(NSWindowDidBecomeKeyNotification) void windowDidBecomeKey(); Q_NOTIFICATION_HANDLER(NSWindowDidResignKeyNotification) void windowDidResignKey(); + Q_NOTIFICATION_HANDLER(NSWindowWillMiniaturizeNotification) void windowWillMiniaturize(); Q_NOTIFICATION_HANDLER(NSWindowDidMiniaturizeNotification) void windowDidMiniaturize(); Q_NOTIFICATION_HANDLER(NSWindowDidDeminiaturizeNotification) void windowDidDeminiaturize(); Q_NOTIFICATION_HANDLER(NSWindowWillEnterFullScreenNotification) void windowWillEnterFullScreen(); diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index c539afbfcd..35b0ec2d40 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -71,14 +71,6 @@ enum { defaultWindowHeight = 160 }; -static void qt_closePopups() -{ - while (QCocoaWindow *popup = QCocoaIntegration::instance()->popPopupWindow()) { - QWindowSystemInterface::handleCloseEvent(popup->window()); - QWindowSystemInterface::flushWindowSystemEvents(); - } -} - Q_LOGGING_CATEGORY(lcCocoaNotifications, "qt.qpa.cocoa.notifications"); static void qRegisterNotificationCallbacks() @@ -819,6 +811,11 @@ void QCocoaWindow::windowDidExitFullScreen() } } +void QCocoaWindow::windowWillMiniaturize() +{ + QCocoaIntegration::instance()->closePopups(window()); +} + void QCocoaWindow::windowDidMiniaturize() { if (!isContentView()) @@ -1153,7 +1150,7 @@ void QCocoaWindow::viewDidChangeGlobalFrame() void QCocoaWindow::windowWillMove() { // Close any open popups on window move - qt_closePopups(); + QCocoaIntegration::instance()->closePopups(); } void QCocoaWindow::windowDidMove() @@ -1284,7 +1281,7 @@ void QCocoaWindow::windowWillClose() { // Close any open popups on window closing. if (window() && !windowIsPopupType(window()->type())) - qt_closePopups(); + QCocoaIntegration::instance()->closePopups(); } // ----------------------- NSWindowDelegate callbacks ----------------------- diff --git a/src/plugins/platforms/cocoa/qmacclipboard.mm b/src/plugins/platforms/cocoa/qmacclipboard.mm index 654647b35a..c5d823693c 100644 --- a/src/plugins/platforms/cocoa/qmacclipboard.mm +++ b/src/plugins/platforms/cocoa/qmacclipboard.mm @@ -594,7 +594,7 @@ QString qt_mac_get_pasteboardString(PasteboardRef paste) pb = [NSPasteboard generalPasteboard]; } if (pb) { - NSString *text = [pb stringForType:NSStringPboardType]; + NSString *text = [pb stringForType:NSPasteboardTypeString]; if (text) return QString::fromNSString(text); } diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac_p.h b/src/plugins/platforms/cocoa/qmultitouch_mac_p.h index 044bcd1882..dff289f746 100644 --- a/src/plugins/platforms/cocoa/qmultitouch_mac_p.h +++ b/src/plugins/platforms/cocoa/qmultitouch_mac_p.h @@ -58,6 +58,7 @@ #include <qpa/qwindowsysteminterface.h> #include <qhash.h> #include <QtCore> +#include <QtGui/qtouchdevice.h> QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qnsview_dragging.mm b/src/plugins/platforms/cocoa/qnsview_dragging.mm index 463e3c5579..2e88b6a08f 100644 --- a/src/plugins/platforms/cocoa/qnsview_dragging.mm +++ b/src/plugins/platforms/cocoa/qnsview_dragging.mm @@ -47,15 +47,14 @@ NSString * const mimeTypeGeneric = @"com.trolltech.qt.MimeTypeName"; NSMutableArray<NSString *> *supportedTypes = [NSMutableArray<NSString *> arrayWithArray:@[ - NSColorPboardType, - NSFilenamesPboardType, NSStringPboardType, - NSFilenamesPboardType, NSPostScriptPboardType, NSTIFFPboardType, - NSRTFPboardType, NSTabularTextPboardType, NSFontPboardType, - NSRulerPboardType, NSFileContentsPboardType, NSColorPboardType, - NSRTFDPboardType, NSHTMLPboardType, - NSURLPboardType, NSPDFPboardType, NSVCardPboardType, - NSFilesPromisePboardType, NSInkTextPboardType, - NSMultipleTextSelectionPboardType, mimeTypeGeneric]]; + NSPasteboardTypeColor, NSPasteboardTypeString, + NSPasteboardTypeFileURL, @"com.adobe.encapsulated-postscript", NSPasteboardTypeTIFF, + NSPasteboardTypeRTF, NSPasteboardTypeTabularText, NSPasteboardTypeFont, + NSPasteboardTypeRuler, NSFileContentsPboardType, + NSPasteboardTypeRTFD , NSPasteboardTypeHTML, + NSPasteboardTypeURL, NSPasteboardTypePDF, (NSString *)kUTTypeVCard, + (NSString *)kPasteboardTypeFileURLPromise, (NSString *)kUTTypeInkText, + NSPasteboardTypeMultipleTextSelection, mimeTypeGeneric]]; // Add custom types supported by the application for (const QString &customType : qt_mac_enabledDraggedTypes()) diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm index 9502a315d8..3ad9085dea 100644 --- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm +++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm @@ -47,7 +47,13 @@ #include <qpa/qplatformscreen.h> #include <qpa/qwindowsysteminterface.h> -static QRegExp whitespaceRegex = QRegExp(QStringLiteral("\\s*")); +static inline bool isWhiteSpace(const QString &s) +{ + for (int i = 0; i < s.size(); ++i) + if (!s.at(i).isSpace()) + return false; + return true; +} static QCocoaWindow *toPlatformWindow(NSWindow *window) { @@ -113,7 +119,7 @@ static QCocoaWindow *toPlatformWindow(NSWindow *window) // Only pop up document path if the filename is non-empty. We allow whitespace, to // allow faking a window icon by setting the file path to a single space character. - return !whitespaceRegex.exactMatch(platformWindow->window()->filePath()); + return !isWhiteSpace(platformWindow->window()->filePath()); } - (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard @@ -127,6 +133,6 @@ static QCocoaWindow *toPlatformWindow(NSWindow *window) // Only allow drag if the filename is non-empty. We allow whitespace, to // allow faking a window icon by setting the file path to a single space. - return !whitespaceRegex.exactMatch(platformWindow->window()->filePath()); + return !isWhiteSpace(platformWindow->window()->filePath()); } @end diff --git a/src/plugins/platforms/cocoa/qpaintengine_mac.mm b/src/plugins/platforms/cocoa/qpaintengine_mac.mm index df71f76644..429c47dc3b 100644 --- a/src/plugins/platforms/cocoa/qpaintengine_mac.mm +++ b/src/plugins/platforms/cocoa/qpaintengine_mac.mm @@ -90,7 +90,7 @@ CGImageRef qt_mac_create_imagemask(const QPixmap &pixmap, const QRectF &sr) image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); const int sx = qRound(sr.x()), sy = qRound(sr.y()), sw = qRound(sr.width()), sh = qRound(sr.height()); - const int sbpr = image.bytesPerLine(); + const qsizetype sbpr = image.bytesPerLine(); const uint nbytes = sw * sh; // alpha is always 255 for bitmaps, ignore it in this case. const quint32 mask = pixmap.depth() == 1 ? 0x00ffffff : 0xffffffff; |