Ticket #62964: patch-mavericks-compatibility.diff

File patch-mavericks-compatibility.diff, 17.1 KB (added by Wowfunhappy (Jonathan), 3 years ago)
  • src/corelib/global/qoperatingsystemversion_darwin.mm

    From 2f0271392a5cd6f7064c2db96f74ccfc6cc13d2e Mon Sep 17 00:00:00 2001
    From: Wowfunhappy <Wowfunhappy@gmail.com>
    Date: Mon, 24 May 2021 16:45:00 -0400
    Subject: [PATCH] Initial Mavericks Compat Fixes
    
    ---
     .../global/qoperatingsystemversion_darwin.mm       |  53 +++++++-
     src/corelib/io/qfilesystemengine_unix.cpp          |   4 +-
     src/corelib/kernel/qcore_foundation.mm             |   8 +-
     src/gui/painting/qcoregraphics.mm                  | 133 +++++++++++----------
     .../platforms/cocoa/images/copyarrowcursor.png     | Bin 0 -> 1976 bytes
     .../platforms/cocoa/images/forbiddencursor.png     | Bin 0 -> 1745 bytes
     .../cocoa/images/leopard-unified-toolbar-on.png    | Bin 0 -> 356 bytes
     src/plugins/platforms/cocoa/qcocoaresources.qrc    |  17 ++-
     src/plugins/platforms/cocoa/qcocoawindow.mm        |   8 +-
     9 files changed, 138 insertions(+), 85 deletions(-)
     create mode 100644 src/plugins/platforms/cocoa/images/copyarrowcursor.png
     create mode 100644 src/plugins/platforms/cocoa/images/forbiddencursor.png
     create mode 100644 src/plugins/platforms/cocoa/images/leopard-unified-toolbar-on.png
    
    diff --git src/corelib/global/qoperatingsystemversion_darwin.mm src/corelib/global/qoperatingsystemversion_darwin.mm
    index d8b927ff5d..3dd007cbb3 100644
     
    4040#include "qoperatingsystemversion_p.h"
    4141#import <Foundation/Foundation.h>
    4242
     43#ifdef Q_OS_IOS
     44#import <UIKit/UIKit.h>
     45#endif
     46
    4347QT_BEGIN_NAMESPACE
    4448
     49typedef qint16 (*GestaltFunction)(quint32 selector, qint32 *response);
     50
    4551QOperatingSystemVersion QOperatingSystemVersion::current()
    4652{
    47     NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;
    4853    QOperatingSystemVersion v;
    4954    v.m_os = currentType();
    50     v.m_major = osv.majorVersion;
    51     v.m_minor = osv.minorVersion;
    52     v.m_micro = osv.patchVersion;
     55    v.m_major = -1;
     56    v.m_minor = -1;
     57    v.m_micro = -1;
     58#if QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_10, __IPHONE_8_0) || defined(Q_OS_TVOS) || defined(Q_OS_WATCHOS)
     59    if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) {
     60        NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;
     61        v.m_major = osv.majorVersion;
     62        v.m_minor = osv.minorVersion;
     63        v.m_micro = osv.patchVersion;
     64        return v;
     65    }
     66#endif
     67    // Use temporary variables so we can return 0.0.0 (unknown version)
     68    // in case of an error partway through determining the OS version
     69    qint32 major = 0, minor = 0, patch = 0;
     70#if QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(__MAC_10_10, __IPHONE_8_0)
     71#if defined(Q_OS_IOS)
     72    @autoreleasepool {
     73        NSArray *parts = [UIDevice.currentDevice.systemVersion componentsSeparatedByString:@"."];
     74        major = parts.count > 0 ? [[parts objectAtIndex:0] intValue] : 0;
     75        minor = parts.count > 1 ? [[parts objectAtIndex:1] intValue] : 0;
     76        patch = parts.count > 2 ? [[parts objectAtIndex:2] intValue] : 0;
     77    }
     78#elif defined(Q_OS_MACOS)
     79    static GestaltFunction pGestalt = 0;
     80    if (!pGestalt) {
     81        CFBundleRef b = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.CoreServices"));
     82        pGestalt = reinterpret_cast<GestaltFunction>(CFBundleGetFunctionPointerForName(b,
     83                                                     CFSTR("Gestalt")));
     84    }
     85    if (!pGestalt)
     86        return v;
     87    if (pGestalt('sys1', &major) != 0)
     88        return v;
     89    if (pGestalt('sys2', &minor) != 0)
     90        return v;
     91    if (pGestalt('sys3', &patch) != 0)
     92        return v;
     93#endif
     94#endif
     95    v.m_major = major;
     96    v.m_minor = minor;
     97    v.m_micro = patch;
    5398    return v;
    5499}
    55100
  • src/corelib/io/qfilesystemengine_unix.cpp

    diff --git src/corelib/io/qfilesystemengine_unix.cpp src/corelib/io/qfilesystemengine_unix.cpp
    index 7fed54f733..9e43da8b0d 100644
    static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &e 
    126126
    127127#ifdef Q_OS_MACOS
    128128        // Find if an application other than Finder claims to know how to handle the package
    129         QCFType<CFURLRef> application = LSCopyDefaultApplicationURLForURL(url,
     129        /*QCFType<CFURLRef> application = LSCopyDefaultApplicationURLForURL(url,
    130130            kLSRolesEditor | kLSRolesViewer, nullptr);
    131131
    132132        if (application) {
    static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &e 
    135135            QString applicationId = QString::fromCFString(identifier);
    136136            if (applicationId != QLatin1String("com.apple.finder"))
    137137                return true;
    138         }
     138        }*/
    139139#endif
    140140    }
    141141
  • src/corelib/kernel/qcore_foundation.mm

    diff --git src/corelib/kernel/qcore_foundation.mm src/corelib/kernel/qcore_foundation.mm
    index 56eabc4b8c..fc448be38f 100644
    QTimeZone QTimeZone::fromNSTimeZone(const NSTimeZone *timeZone) 
    486486
    487487    \sa fromNSTimeZone()
    488488*/
    489 NSTimeZone *QTimeZone::toNSTimeZone() const
    490 {
    491     return [static_cast<NSTimeZone *>(toCFTimeZone()) autorelease];
    492 }
     489//NSTimeZone *QTimeZone::toNSTimeZone() const
     490//{
     491//    return [static_cast<NSTimeZone *>(toCFTimeZone()) autorelease];
     492//}
    493493#endif
    494494
    495495// ----------------------------------------------------------------------------
  • src/gui/painting/qcoregraphics.mm

    diff --git src/gui/painting/qcoregraphics.mm src/gui/painting/qcoregraphics.mm
    index c4fb8afc64..bf2d028b99 100644
    CGImageRef qt_mac_toCGImageMask(const QImage &image) 
    6565{
    6666    static const auto deleter = [](void *image, const void *, size_t) { delete static_cast<QImage *>(image); };
    6767    QCFType<CGDataProviderRef> dataProvider =
    68             CGDataProviderCreateWithData(new QImage(image), image.bits(),
    69                                                     image.byteCount(), deleter);
    70 
     68    CGDataProviderCreateWithData(new QImage(image), image.bits(),
     69                                 image.byteCount(), deleter);
     70   
    7171    return CGImageMaskCreate(image.width(), image.height(), 8, image.depth(),
    72                               image.bytesPerLine(), dataProvider, NULL, false);
     72                             image.bytesPerLine(), dataProvider, NULL, false);
    7373}
    7474
    7575void qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage)
    void qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageR 
    7777    CGContextSaveGState( inContext );
    7878    CGContextTranslateCTM (inContext, 0, inBounds->origin.y + CGRectGetMaxY(*inBounds));
    7979    CGContextScaleCTM(inContext, 1, -1);
    80 
     80   
    8181    CGContextDrawImage(inContext, *inBounds, inImage);
    82 
     82   
    8383    CGContextRestoreGState(inContext);
    8484}
    8585
    8686QImage qt_mac_toQImage(CGImageRef image)
    8787{
    8888    const size_t w = CGImageGetWidth(image),
    89                  h = CGImageGetHeight(image);
     89    h = CGImageGetHeight(image);
    9090    QImage ret(w, h, QImage::Format_ARGB32_Premultiplied);
    9191    ret.fill(Qt::transparent);
    9292    CGRect rect = CGRectMake(0, 0, w, h);
    QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size) 
    147147    QMacCGContext ctx(&pixmap);
    148148    if (!ctx)
    149149        return QPixmap();
    150     NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES];
     150   
     151    //NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES];
     152    NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES];
     153   
    151154    if (!gc)
    152155        return QPixmap();
    153156    [NSGraphicsContext saveGraphicsState];
    static CGColorSpaceRef qt_mac_displayColorSpace(const QWindow *window) 
    324327    } else {
    325328        displayID = CGMainDisplayID();
    326329        /*
    327         ### get correct display
    328         const QRect &qrect = window->geometry();
    329         CGRect rect = CGRectMake(qrect.x(), qrect.y(), qrect.width(), qrect.height());
    330         CGDisplayCount throwAway;
    331         CGDisplayErr dErr = CGGetDisplaysWithRect(rect, 1, &displayID, &throwAway);
    332         if (dErr != kCGErrorSuccess)
    333             return macDisplayColorSpace(0); // fall back on main display
    334         */
     330         ### get correct display
     331         const QRect &qrect = window->geometry();
     332         CGRect rect = CGRectMake(qrect.x(), qrect.y(), qrect.width(), qrect.height());
     333         CGDisplayCount throwAway;
     334         CGDisplayErr dErr = CGGetDisplaysWithRect(rect, 1, &displayID, &throwAway);
     335         if (dErr != kCGErrorSuccess)
     336         return macDisplayColorSpace(0); // fall back on main display
     337         */
    335338    }
    336339    if ((colorSpace = m_displayColorSpaceHash.value(displayID)))
    337340        return colorSpace;
    QMacCGContext::QMacCGContext(QPaintDevice *paintDevice) : context(0) 
    442445    if (paintDevice->devType() == QInternal::Image) {
    443446        image = static_cast<QImage *>(paintDevice);
    444447    } else if (paintDevice->devType() == QInternal::Pixmap) {
    445 
     448       
    446449        const QPixmap *pm = static_cast<const QPixmap*>(paintDevice);
    447450        QPlatformPixmap *data = const_cast<QPixmap *>(pm)->data_ptr().data();
    448451        if (data && data->classId() == QPlatformPixmap::RasterClass) {
    QMacCGContext::QMacCGContext(QPaintDevice *paintDevice) : context(0) 
    463466    flags |= kCGBitmapByteOrder32Host;
    464467
    465468    context = CGBitmapContextCreate(image->bits(), image->width(), image->height(),
    466                                 8, image->bytesPerLine(), colorspace, flags);
     469                                    8, image->bytesPerLine(), colorspace, flags);
    467470    CGContextTranslateCTM(context, 0, image->height());
    468471    const qreal devicePixelRatio = paintDevice->devicePixelRatioF();
    469472    CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio);
    QMacCGContext::QMacCGContext(QPainter *painter) : context(0) 
    477480    // Handle the case of QMacPrintEngine, which has an internal QCoreGraphicsPaintEngine
    478481    while (QPaintEngine *aggregateEngine = QPaintEnginePrivate::get(paintEngine)->aggregateEngine())
    479482        paintEngine = aggregateEngine;
    480 
     483   
    481484    paintEngine->syncState();
    482 
     485   
    483486    if (Qt::HANDLE handle = QPaintEnginePrivate::get(paintEngine)->nativeHandle()) {
    484487        context = static_cast<CGContextRef>(handle);
    485488        return;
    486489    }
    487 
     490   
    488491    int devType = painter->device()->devType();
    489492    if (paintEngine->type() == QPaintEngine::Raster
    490             && (devType == QInternal::Widget ||
    491                 devType == QInternal::Pixmap ||
    492                 devType == QInternal::Image)) {
    493 
    494         CGColorSpaceRef colorspace = qt_mac_colorSpaceForDeviceType(paintEngine->paintDevice());
    495         uint flags = kCGImageAlphaPremultipliedFirst;
     493        && (devType == QInternal::Widget ||
     494            devType == QInternal::Pixmap ||
     495            devType == QInternal::Image)) {
     496           
     497            CGColorSpaceRef colorspace = qt_mac_colorSpaceForDeviceType(paintEngine->paintDevice());
     498            uint flags = kCGImageAlphaPremultipliedFirst;
    496499#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
    497         flags |= kCGBitmapByteOrder32Host;
     500            flags |= kCGBitmapByteOrder32Host;
    498501#endif
    499         const QImage *image = static_cast<const QImage *>(paintEngine->paintDevice());
    500 
    501         context = CGBitmapContextCreate((void *)image->bits(), image->width(), image->height(),
    502                                         8, image->bytesPerLine(), colorspace, flags);
    503 
    504         // Invert y axis
    505         CGContextTranslateCTM(context, 0, image->height());
    506         CGContextScaleCTM(context, 1, -1);
    507 
    508         const qreal devicePixelRatio = image->devicePixelRatio();
    509 
    510         if (devType == QInternal::Widget) {
    511             // Set the clip rect which is an intersection of the system clip
    512             // and the painter clip. To make matters more interesting these
    513             // are in device pixels and device-independent pixels, respectively.
    514             QRegion clip = painter->paintEngine()->systemClip(); // get system clip in device pixels
    515             QTransform native = painter->deviceTransform();      // get device transform. dx/dy is in device pixels
    516 
    517             if (painter->hasClipping()) {
    518                 QRegion r = painter->clipRegion();               // get painter clip, which is in device-independent pixels
    519                 qt_mac_scale_region(&r, devicePixelRatio); // scale painter clip to device pixels
    520                 r.translate(native.dx(), native.dy());
    521                 if (clip.isEmpty())
    522                     clip = r;
    523                 else
    524                     clip &= r;
     502            const QImage *image = static_cast<const QImage *>(paintEngine->paintDevice());
     503           
     504            context = CGBitmapContextCreate((void *)image->bits(), image->width(), image->height(),
     505                                            8, image->bytesPerLine(), colorspace, flags);
     506           
     507            // Invert y axis
     508            CGContextTranslateCTM(context, 0, image->height());
     509            CGContextScaleCTM(context, 1, -1);
     510           
     511            const qreal devicePixelRatio = image->devicePixelRatio();
     512           
     513            if (devType == QInternal::Widget) {
     514                // Set the clip rect which is an intersection of the system clip
     515                // and the painter clip. To make matters more interesting these
     516                // are in device pixels and device-independent pixels, respectively.
     517                QRegion clip = painter->paintEngine()->systemClip(); // get system clip in device pixels
     518                QTransform native = painter->deviceTransform();      // get device transform. dx/dy is in device pixels
     519               
     520                if (painter->hasClipping()) {
     521                    QRegion r = painter->clipRegion();               // get painter clip, which is in device-independent pixels
     522                    qt_mac_scale_region(&r, devicePixelRatio); // scale painter clip to device pixels
     523                    r.translate(native.dx(), native.dy());
     524                    if (clip.isEmpty())
     525                        clip = r;
     526                    else
     527                        clip &= r;
     528                }
     529                qt_mac_clip_cg(context, clip, 0); // clip in device pixels
     530               
     531                // Scale the context so that painting happens in device-independent pixels
     532                CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio);
     533                CGContextTranslateCTM(context, native.dx() / devicePixelRatio, native.dy() / devicePixelRatio);
     534            } else {
     535                // Scale to paint in device-independent pixels
     536                CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio);
    525537            }
    526             qt_mac_clip_cg(context, clip, 0); // clip in device pixels
    527 
    528             // Scale the context so that painting happens in device-independent pixels
    529             CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio);
    530             CGContextTranslateCTM(context, native.dx() / devicePixelRatio, native.dy() / devicePixelRatio);
    531538        } else {
    532             // Scale to paint in device-independent pixels
    533             CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio);
     539            qDebug() << "QMacCGContext:: Unsupported painter devtype type" << devType;
    534540        }
    535     } else {
    536         qDebug() << "QMacCGContext:: Unsupported painter devtype type" << devType;
    537     }
    538541}
    539542
    540 QT_END_NAMESPACE
     543QT_END_NAMESPACE
     544 No newline at end of file
  • src/plugins/platforms/cocoa/qcocoawindow.mm

    diff --git src/plugins/platforms/cocoa/qcocoawindow.mm src/plugins/platforms/cocoa/qcocoawindow.mm
    index 86fd7b8a9f..2f45347127 100644
    static void qt_closePopups() 
    324324
    325325+ (void)applicationActivationChanged:(NSNotification*)notification
    326326{
    327     const id sender = self;
     327    /*const id sender = self;
    328328    NSEnumerator<NSWindow*> *windowEnumerator = nullptr;
    329329    NSApplication *application = [NSApplication sharedApplication];
    330330
    static void qt_closePopups() 
    384384        // end up triggering a bug in AppKit where the tool windows would disappear behind
    385385        // the application window.
    386386        [window orderFront:sender];
    387     }
     387    }*/
    388388}
    389389
    390390- (id)initWithContentRect:(NSRect)contentRect
    void QCocoaWindow::applyContentBorderThickness(NSWindow *window) 
    21812181    if (!m_drawContentBorderGradient) {
    21822182        [window setStyleMask:[window styleMask] & ~NSTexturedBackgroundWindowMask];
    21832183        [[[window contentView] superview] setNeedsDisplay:YES];
    2184         window.titlebarAppearsTransparent = NO;
     2184        //window.titlebarAppearsTransparent = NO;
    21852185        return;
    21862186    }
    21872187
    void QCocoaWindow::applyContentBorderThickness(NSWindow *window) 
    22062206    int effectiveBottomContentBorderThickness = m_bottomContentBorderThickness;
    22072207
    22082208    [window setStyleMask:[window styleMask] | NSTexturedBackgroundWindowMask];
    2209     window.titlebarAppearsTransparent = YES;
     2209    //window.titlebarAppearsTransparent = YES;
    22102210
    22112211    [window setContentBorderThickness:effectiveTopContentBorderThickness forEdge:NSMaxYEdge];
    22122212    [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];