Fix potential wrong-over-optimization in math utilities
[carla.git] / data / patches / qt59-osx10.8-compat.patch
blobc555c091064a76c1336bea409f8c76c0c7fe7c57
1 diff --git a/mkspecs/common/clang-mac.conf b/mkspecs/common/clang-mac.conf
2 index cbae2e62..dc4694fa 100644
3 --- a/mkspecs/common/clang-mac.conf
4 +++ b/mkspecs/common/clang-mac.conf
5 @@ -10,4 +10,5 @@ QMAKE_CXXFLAGS += -stdlib=libc++
6 QMAKE_LFLAGS += -stdlib=libc++
7 QMAKE_AR_LTCG = libtool -static -o
9 -QMAKE_CFLAGS_APPLICATION_EXTENSION = -fapplication-extension
10 +QMAKE_CFLAGS_APPLICATION_EXTENSION =
11 +# -fapplication-extension
12 diff --git a/src/corelib/global/qoperatingsystemversion_darwin.mm b/src/corelib/global/qoperatingsystemversion_darwin.mm
13 index d8b927ff..9a690adc 100644
14 --- a/src/corelib/global/qoperatingsystemversion_darwin.mm
15 +++ b/src/corelib/global/qoperatingsystemversion_darwin.mm
16 @@ -40,16 +40,37 @@
17 #include "qoperatingsystemversion_p.h"
18 #import <Foundation/Foundation.h>
20 +typedef qint16 (*GestaltFunction)(quint32 selector, qint32 *response);
22 QT_BEGIN_NAMESPACE
24 QOperatingSystemVersion QOperatingSystemVersion::current()
26 - NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;
27 QOperatingSystemVersion v;
28 v.m_os = currentType();
29 - v.m_major = osv.majorVersion;
30 - v.m_minor = osv.minorVersion;
31 - v.m_micro = osv.patchVersion;
32 + v.m_major = -1;
33 + v.m_minor = -1;
34 + v.m_micro = -1;
35 + static GestaltFunction pGestalt = 0;
36 + if (!pGestalt) {
37 + CFBundleRef b = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.CoreServices"));
38 + pGestalt = reinterpret_cast<GestaltFunction>(CFBundleGetFunctionPointerForName(b,
39 + CFSTR("Gestalt")));
40 + }
41 + // Use temporary variables so we can return 0.0.0 (unknown version)
42 + // in case of an error partway through determining the OS version
43 + qint32 major = 0, minor = 0, patch = 0;
44 + if (!pGestalt)
45 + return v;
46 + if (pGestalt('sys1', &major) != 0)
47 + return v;
48 + if (pGestalt('sys2', &minor) != 0)
49 + return v;
50 + if (pGestalt('sys3', &patch) != 0)
51 + return v;
52 + v.m_major = major;
53 + v.m_minor = minor;
54 + v.m_micro = patch;
55 return v;
58 diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
59 index 7fed54f7..bbf5e6d6 100644
60 --- a/src/corelib/io/qfilesystemengine_unix.cpp
61 +++ b/src/corelib/io/qfilesystemengine_unix.cpp
62 @@ -126,8 +126,11 @@ static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &e
64 #ifdef Q_OS_MACOS
65 // Find if an application other than Finder claims to know how to handle the package
66 - QCFType<CFURLRef> application = LSCopyDefaultApplicationURLForURL(url,
67 - kLSRolesEditor | kLSRolesViewer, nullptr);
68 + QCFType<CFURLRef> application;
69 + LSGetApplicationForURL(url,
70 + kLSRolesEditor|kLSRolesViewer,
71 + NULL,
72 + &application);
74 if (application) {
75 QCFType<CFBundleRef> bundle = CFBundleCreate(kCFAllocatorDefault, application);
76 diff --git a/src/corelib/kernel/qcore_foundation.mm b/src/corelib/kernel/qcore_foundation.mm
77 index 56eabc4b..c48a7979 100644
78 --- a/src/corelib/kernel/qcore_foundation.mm
79 +++ b/src/corelib/kernel/qcore_foundation.mm
80 @@ -46,7 +46,7 @@
81 #include <QtCore/qbytearray.h>
82 #include <QtCore/qrect.h>
84 -#if QT_CONFIG(timezone) && !defined(QT_NO_SYSTEMLOCALE)
85 +#if 0
86 #include <QtCore/qtimezone.h>
87 #include <QtCore/private/qtimezoneprivate_p.h>
88 #include <QtCore/private/qcore_mac_p.h>
89 @@ -433,7 +433,7 @@ NSDate *QDateTime::toNSDate() const
91 // ----------------------------------------------------------------------------
93 -#if QT_CONFIG(timezone) && !defined(QT_NO_SYSTEMLOCALE)
94 +#if 0
95 /*!
96 \since 5.9
98 diff --git a/src/corelib/tools/qtimezone.h b/src/corelib/tools/qtimezone.h
99 index bd87139f..d154cbf9 100644
100 --- a/src/corelib/tools/qtimezone.h
101 +++ b/src/corelib/tools/qtimezone.h
102 @@ -47,7 +47,7 @@
104 QT_REQUIRE_CONFIG(timezone);
106 -#if (defined(Q_OS_DARWIN) || defined(Q_QDOC)) && !defined(QT_NO_SYSTEMLOCALE)
107 +#if 0
108 Q_FORWARD_DECLARE_CF_TYPE(CFTimeZone);
109 Q_FORWARD_DECLARE_OBJC_CLASS(NSTimeZone);
110 #endif
111 @@ -147,7 +147,7 @@ public:
112 static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId,
113 QLocale::Country country);
115 -#if (defined(Q_OS_DARWIN) || defined(Q_QDOC)) && !defined(QT_NO_SYSTEMLOCALE)
116 +#if 0
117 static QTimeZone fromCFTimeZone(CFTimeZoneRef timeZone);
118 CFTimeZoneRef toCFTimeZone() const Q_DECL_CF_RETURNS_RETAINED;
119 static QTimeZone fromNSTimeZone(const NSTimeZone *timeZone);
120 diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
121 index f8fe160e..3c350b3c 100644
122 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
123 +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
124 @@ -456,7 +456,6 @@ QFontEngine *QCoreTextFontDatabaseEngineFactory<QFontEngineFT>::fontEngine(const
125 return QFontEngineFT::create(*fontData, fontDef.pixelSize,
126 static_cast<QFont::HintingPreference>(fontDef.hintingPreference));
127 } else if (NSURL *url = descriptorAttribute<NSURL>(descriptor, kCTFontURLAttribute)) {
128 - Q_ASSERT(url.fileURL);
129 QFontEngine::FaceId faceId;
130 faceId.filename = QString::fromNSString(url.path).toUtf8();
131 return QFontEngineFT::create(fontDef, faceId);
132 diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm
133 index e41c70b8..815028b7 100644
134 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm
135 +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm
136 @@ -329,13 +329,6 @@ void QCocoaMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *
139 insertNative(cocoaItem, beforeItem);
141 - // Empty menus on a menubar are hidden by default. If the menu gets
142 - // added to the menubar before it contains any item, we need to sync.
143 - if (isVisible() && attachedItem().hidden) {
144 - if (auto *mb = qobject_cast<QCocoaMenuBar *>(menuParent()))
145 - mb->syncMenu(this);
149 void QCocoaMenu::insertNative(QCocoaMenuItem *item, QCocoaMenuItem *beforeItem)
150 diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm
151 index a4cd465d..06d63f7d 100644
152 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm
153 +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm
154 @@ -369,7 +369,7 @@ void QCocoaMenuBar::updateMenuBarImmediately()
155 QCocoaMenuLoader *loader = [QCocoaMenuLoader sharedMenuLoader];
156 [loader ensureAppMenuInMenu:mb->nsMenu()];
158 - NSMutableSet *mergedItems = [[NSMutableSet setWithCapacity:mb->merged().count()] retain];
159 + NSMutableSet *mergedItems = [[NSMutableSet setWithCapacity:0] retain];
160 foreach (QCocoaMenuItem *m, mb->merged()) {
161 [mergedItems addObject:m->nsItem()];
162 m->syncMerged();
163 diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
164 index 5504c242..fa0b7f71 100644
165 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
166 +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
167 @@ -172,12 +172,11 @@ void *QCocoaNativeInterface::NSPrintInfoForPrintEngine(QPrintEngine *printEngine
169 QPixmap QCocoaNativeInterface::defaultBackgroundPixmapForQWizard()
171 + QCFType<CFURLRef> url;
172 const int ExpectedImageWidth = 242;
173 const int ExpectedImageHeight = 414;
174 - QCFType<CFArrayRef> urls = LSCopyApplicationURLsForBundleIdentifier(
175 - CFSTR("com.apple.KeyboardSetupAssistant"), nullptr);
176 - if (urls && CFArrayGetCount(urls) > 0) {
177 - CFURLRef url = (CFURLRef)CFArrayGetValueAtIndex(urls, 0);
178 + if (LSFindApplicationForInfo(kLSUnknownCreator, CFSTR("com.apple.KeyboardSetupAssistant"),
179 + 0, 0, &url) == noErr) {
180 QCFType<CFBundleRef> bundle = CFBundleCreate(kCFAllocatorDefault, url);
181 if (bundle) {
182 url = CFBundleCopyResourceURL(bundle, CFSTR("Background"), CFSTR("png"), 0);
183 diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
184 index aa8fffdf..191553e6 100644
185 --- a/src/plugins/platforms/cocoa/qcocoawindow.h
186 +++ b/src/plugins/platforms/cocoa/qcocoawindow.h
187 @@ -316,6 +316,8 @@ public: // for QNSView
188 bool m_viewIsEmbedded; // true if the m_view is actually embedded in a "foreign" NSView hiearchy
189 bool m_viewIsToBeEmbedded; // true if the m_view is intended to be embedded in a "foreign" NSView hiearchy
191 + QCocoaWindow *m_parentCocoaWindow;
193 Qt::WindowFlags m_windowFlags;
194 Qt::WindowState m_lastReportedWindowState;
195 Qt::WindowModality m_windowModality;
196 diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
197 index 86fd7b8a..c7aa5792 100644
198 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm
199 +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
200 @@ -325,7 +325,7 @@ static void qt_closePopups()
201 + (void)applicationActivationChanged:(NSNotification*)notification
203 const id sender = self;
204 - NSEnumerator<NSWindow*> *windowEnumerator = nullptr;
205 + NSEnumerator* windowEnumerator = nullptr;
206 NSApplication *application = [NSApplication sharedApplication];
208 #if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_12)
209 @@ -526,6 +526,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw, WId nativeHandle)
210 , m_nsWindow(0)
211 , m_viewIsEmbedded(false)
212 , m_viewIsToBeEmbedded(false)
213 + , m_parentCocoaWindow(0)
214 , m_lastReportedWindowState(Qt::WindowNoState)
215 , m_windowModality(Qt::NonModal)
216 , m_windowUnderMouse(false)
217 @@ -594,10 +595,12 @@ QCocoaWindow::~QCocoaWindow()
218 [m_nsWindow makeFirstResponder:nil];
219 [m_nsWindow setContentView:nil];
220 [m_nsWindow.helper detachFromPlatformWindow];
221 - if (m_view.window.parentWindow)
222 - [m_view.window.parentWindow removeChildWindow:m_view.window];
223 - else if ([m_view superview])
224 + if (m_view.window.parentWindow) {
225 + if (m_parentCocoaWindow)
226 + m_parentCocoaWindow->removeChildWindow(this);
227 + } else if ([m_view superview]) {
228 [m_view removeFromSuperview];
231 removeMonitor();
233 @@ -614,6 +617,7 @@ QCocoaWindow::~QCocoaWindow()
235 foreachChildNSWindow(^(QCocoaWindow *childWindow) {
236 [m_nsWindow removeChildWindow:childWindow->m_nsWindow];
237 + childWindow->m_parentCocoaWindow = 0;
240 [m_view release];
241 @@ -690,7 +694,7 @@ void QCocoaWindow::setCocoaGeometry(const QRect &rect)
243 if (isChildNSWindow()) {
244 QPlatformWindow::setGeometry(rect);
245 - NSWindow *parentNSWindow = m_view.window.parentWindow;
246 + NSWindow *parentNSWindow = m_parentCocoaWindow->m_nsWindow;
247 NSRect parentWindowFrame = [parentNSWindow contentRectForFrameRect:parentNSWindow.frame];
248 clipWindow(parentWindowFrame);
250 @@ -744,7 +748,7 @@ void QCocoaWindow::clipWindow(const NSRect &clipRect)
251 m_hiddenByClipping = false;
252 if (!m_hiddenByAncestor) {
253 [m_nsWindow orderFront:nil];
254 - static_cast<QCocoaWindow *>(QPlatformWindow::parent())->reinsertChildWindow(this);
255 + m_parentCocoaWindow->reinsertChildWindow(this);
259 @@ -781,7 +785,7 @@ void QCocoaWindow::show(bool becauseOfAncestor)
260 if ([m_nsWindow isVisible])
261 return;
263 - if (m_view.window.parentWindow && !m_view.window.parentWindow.visible) {
264 + if (m_parentCocoaWindow && ![m_parentCocoaWindow->m_nsWindow isVisible]) {
265 m_hiddenByAncestor = true; // Parent still hidden, don't show now
266 } else if ((becauseOfAncestor == m_hiddenByAncestor) // Was NEITHER explicitly hidden
267 && !m_hiddenByClipping) { // ... NOR clipped
268 @@ -792,7 +796,7 @@ void QCocoaWindow::show(bool becauseOfAncestor)
269 if (!m_hiddenByClipping) { // setCocoaGeometry() can change the clipping status
270 [m_nsWindow orderFront:nil];
271 if (isChildNSWindow())
272 - static_cast<QCocoaWindow *>(QPlatformWindow::parent())->reinsertChildWindow(this);
273 + m_parentCocoaWindow->reinsertChildWindow(this);
274 foreachChildNSWindow(^(QCocoaWindow *childWindow) {
275 childWindow->show(true);
277 @@ -1190,7 +1194,7 @@ void QCocoaWindow::raise()
278 // -[NSWindow orderFront:] doesn't work with attached windows.
279 // The only solution is to remove and add the child window.
280 // This will place it on top of all the other NSWindows.
281 - NSWindow *parentNSWindow = m_view.window.parentWindow;
282 + NSWindow *parentNSWindow = m_parentCocoaWindow->m_nsWindow;
283 [parentNSWindow removeChildWindow:m_nsWindow];
284 [parentNSWindow addChildWindow:m_nsWindow ordered:NSWindowAbove];
285 } else {
286 @@ -1226,7 +1230,7 @@ void QCocoaWindow::lower()
287 // The only solution is to remove and add all the child windows except this one.
288 // This will keep the current window at the bottom while adding the others on top of it,
289 // hopefully in the same order (this is not documented anywhere in the Cocoa documentation).
290 - NSWindow *parentNSWindow = m_view.window.parentWindow;
291 + NSWindow *parentNSWindow = m_parentCocoaWindow->m_nsWindow;
292 NSArray *children = [parentNSWindow.childWindows copy];
293 for (NSWindow *child in children)
294 if (m_nsWindow != child) {
295 @@ -1698,14 +1702,15 @@ void QCocoaWindow::recreateWindowIfNeeded()
297 qCDebug(lcQpaCocoaWindow) << "Reconfiguring NSWindow due to" << recreateReason;
299 - QCocoaWindow *parentCocoaWindow = static_cast<QCocoaWindow *>(parentWindow);
300 + // FIXME: Replace member with direct parentWindow usage (possibly cast)
301 + m_parentCocoaWindow = static_cast<QCocoaWindow *>(parentWindow);
303 if (shouldBeChildNSWindow) {
304 QWindow *parentQWindow = parentWindow->window();
305 // Ensure that all parents in the hierarchy are also child NSWindows
306 if (!parentQWindow->property("_q_platform_MacUseNSWindow").toBool()) {
307 parentQWindow->setProperty("_q_platform_MacUseNSWindow", QVariant(true));
308 - parentCocoaWindow->recreateWindowIfNeeded();
309 + m_parentCocoaWindow->recreateWindowIfNeeded();
313 @@ -1713,8 +1718,8 @@ void QCocoaWindow::recreateWindowIfNeeded()
314 if ((isContentView() && !shouldBeContentView) || (recreateReason & PanelChanged)) {
315 qCDebug(lcQpaCocoaWindow) << "Getting rid of existing window" << m_nsWindow;
316 [m_nsWindow closeAndRelease];
317 - if (isChildNSWindow())
318 - [m_view.window.parentWindow removeChildWindow:m_view.window];
319 + if (isChildNSWindow() && oldParentCocoaWindow)
320 + oldParentCocoaWindow->removeChildWindow(this);
321 if (isContentView()) {
322 // We explicitly disassociate m_view from the window's contentView,
323 // as AppKit does not automatically do this in response to removing
324 @@ -1730,9 +1735,9 @@ void QCocoaWindow::recreateWindowIfNeeded()
325 if (noPreviousWindow)
326 m_nsWindow = createNSWindow(shouldBeChildNSWindow, shouldBePanel);
328 - if (m_view.window.parentWindow) {
329 - if (!shouldBeChildNSWindow || (recreateReason & ParentChanged))
330 - [m_view.window.parentWindow removeChildWindow:m_view.window];
331 + if (oldParentCocoaWindow) {
332 + if (!shouldBeChildNSWindow || oldParentCocoaWindow != m_parentCocoaWindow)
333 + oldParentCocoaWindow->removeChildWindow(this);
334 m_forwardWindow = oldParentCocoaWindow;
337 @@ -1759,8 +1764,8 @@ void QCocoaWindow::recreateWindowIfNeeded()
338 setWindowState(window()->windowState());
339 } else if (shouldBeChildNSWindow) {
340 if (!m_hiddenByClipping) {
341 - [parentCocoaWindow->m_nsWindow addChildWindow:m_nsWindow ordered:NSWindowAbove];
342 - parentCocoaWindow->reinsertChildWindow(this);
343 + [m_parentCocoaWindow->m_nsWindow addChildWindow:m_nsWindow ordered:NSWindowAbove];
344 + m_parentCocoaWindow->reinsertChildWindow(this);
347 // Set properties after the window has been made a child NSWindow
348 @@ -1771,7 +1776,7 @@ void QCocoaWindow::recreateWindowIfNeeded()
349 if ([m_view superview])
350 [m_view removeFromSuperview];
352 - [parentCocoaWindow->m_view addSubview:m_view];
353 + [m_parentCocoaWindow->m_view addSubview:m_view];
354 QRect rect = windowGeometry();
355 // Prevent setting a (0,0) window size; causes opengl context
356 // "Invalid Drawable" warnings.
357 @@ -1915,6 +1920,11 @@ bool QCocoaWindow::alwaysShowToolWindow() const
358 return qt_mac_resolveOption(false, window(), "_q_macAlwaysShowToolWindow", "");
361 +void QCocoaWindow::removeChildWindow(QCocoaWindow *child)
363 + [m_nsWindow removeChildWindow:child->m_nsWindow];
366 void QCocoaWindow::removeMonitor()
368 if (!monitor)
369 @@ -2046,12 +2056,14 @@ Qt::WindowState QCocoaWindow::windowState() const
370 // FIXME: Support compound states (Qt::WindowStates)
372 NSWindow *window = m_view.window;
373 + /*
374 if (window.miniaturized)
375 return Qt::WindowMinimized;
376 + */
377 if (window.qt_fullScreen)
378 return Qt::WindowFullScreen;
379 - if ((window.zoomed && !isTransitioningToFullScreen())
380 - || (m_lastReportedWindowState == Qt::WindowMaximized && isTransitioningToFullScreen()))
381 + if (/*(window.zoomed && !isTransitioningToFullScreen())
382 + ||*/ (m_lastReportedWindowState == Qt::WindowMaximized && isTransitioningToFullScreen()))
383 return Qt::WindowMaximized;
385 // Note: We do not report Qt::WindowActive, even if isActive()
386 @@ -2181,7 +2193,6 @@ void QCocoaWindow::applyContentBorderThickness(NSWindow *window)
387 if (!m_drawContentBorderGradient) {
388 [window setStyleMask:[window styleMask] & ~NSTexturedBackgroundWindowMask];
389 [[[window contentView] superview] setNeedsDisplay:YES];
390 - window.titlebarAppearsTransparent = NO;
391 return;
394 @@ -2206,7 +2217,6 @@ void QCocoaWindow::applyContentBorderThickness(NSWindow *window)
395 int effectiveBottomContentBorderThickness = m_bottomContentBorderThickness;
397 [window setStyleMask:[window styleMask] | NSTexturedBackgroundWindowMask];
398 - window.titlebarAppearsTransparent = YES;
400 [window setContentBorderThickness:effectiveTopContentBorderThickness forEdge:NSMaxYEdge];
401 [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];