summaryrefslogtreecommitdiff
path: root/patches/qt4/patch-qeventdispatcher.diff
blob: 89ed4788d4112a59e68b12180e560874e3f0e2d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
--- src/gui/kernel/qeventdispatcher_mac_p.h	2013-06-07 01:16:59.000000000 -0400
+++ src/gui/kernel/qeventdispatcher_mac_p_new-8184b49c12d887928921ed5b695c8c6f04a07514.h	2013-12-08 14:31:01.000000000 -0500
@@ -173,6 +173,7 @@
 #ifdef QT_MAC_USE_COCOA
     // The following variables help organizing modal sessions:
     static QStack<QCocoaModalSessionInfo> cocoaModalSessionStack;
+    static QStack<QCocoaModalSessionInfo> cocoaModalSessionStackPendingEnd;
     static bool currentExecIsNSAppRun;
     static bool nsAppRunCalledByQt;
     static bool cleanupModalSessionsNeeded;
@@ -180,6 +181,7 @@
     static NSModalSession currentModalSession();
     static void updateChildrenWorksWhenModal();
     static void temporarilyStopAllModalSessions();
+    static void stopAllPendingEndModalSessions();
     static void beginModalSession(QWidget *widget);
     static void endModalSession(QWidget *widget);
     static void cancelWaitForMoreEvents();
--- src/gui/kernel/qeventdispatcher_mac.mm	2013-06-07 01:16:59.000000000 -0400
+++ src/gui/kernel/qeventdispatcher_mac_new-833e02de99494686f8dd7a567f6e19e847508f11.mm	2013-12-08 14:30:59.000000000 -0500
@@ -603,6 +603,9 @@
                 while ([NSApp runModalSession:session] == NSRunContinuesResponse && !d->interrupt)
                     qt_mac_waitForMoreModalSessionEvents();
 
+                // stop all pending end modal sessions
+                d->stopAllPendingEndModalSessions();
+
                 if (!d->interrupt && session == d->currentModalSessionCached) {
                     // Someone called [NSApp stopModal:] from outside the event
                     // dispatcher (e.g to stop a native dialog). But that call wrongly stopped
@@ -678,6 +681,9 @@
             if (!d->interrupt)
                 QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData);
 
+            // stop all pending end modal sessions
+            d->stopAllPendingEndModalSessions();
+
             // Since the window that holds modality might have changed while processing
             // events, we we need to interrupt when we return back the previous process
             // event recursion to ensure that we spin the correct modal session.
@@ -781,6 +787,7 @@
 
 #ifdef QT_MAC_USE_COCOA
 QStack<QCocoaModalSessionInfo> QEventDispatcherMacPrivate::cocoaModalSessionStack;
+QStack<QCocoaModalSessionInfo> QEventDispatcherMacPrivate::cocoaModalSessionStackPendingEnd;
 bool QEventDispatcherMacPrivate::currentExecIsNSAppRun = false;
 bool QEventDispatcherMacPrivate::nsAppRunCalledByQt = false;
 bool QEventDispatcherMacPrivate::cleanupModalSessionsNeeded = false;
@@ -828,6 +835,20 @@
     currentModalSessionCached = 0;
 }
 
+void QEventDispatcherMacPrivate::stopAllPendingEndModalSessions()
+{
+    // stop all modal sessions pending end
+    int stackSize = cocoaModalSessionStackPendingEnd.size();
+    for (int i=stackSize-1; i>=0; --i) {
+        QCocoaModalSessionInfo &info = cocoaModalSessionStackPendingEnd[i];
+        cocoaModalSessionStackPendingEnd.remove(i);
+        if (info.session) {
+            [NSApp endModalSession:info.session];
+            [(NSWindow *)info.nswindow release];
+        }
+    }
+}
+
 NSModalSession QEventDispatcherMacPrivate::currentModalSession()
 {
     // If we have one or more modal windows, this function will create
@@ -925,10 +946,12 @@
         }
         cocoaModalSessionStack.remove(i);
         currentModalSessionCached = 0;
-        if (info.session) {
-            [NSApp endModalSession:info.session];
-            [(NSWindow *)info.nswindow release];
-        }
+
+        // Cannot stop the sessions here since we might still be inside a
+        // [NSApp runModalSession:] call. Add the session to the pending end stack and
+        // process the stack after the call to [NSApp runModalSession:] returns.
+        if (info.session)
+            cocoaModalSessionStackPendingEnd.push(info);
     }
 
     updateChildrenWorksWhenModal();
contact: Jan Huwald // Impressum