jdk/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m
changeset 31170 4d414cfb92cc
parent 25859 3317bb8137f4
child 31654 9f95289d9553
--- a/jdk/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m	Thu Jun 04 15:24:30 2015 +0300
+++ b/jdk/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m	Thu Jun 04 16:18:14 2015 +0300
@@ -337,9 +337,13 @@
 
 - (void)sendEvent:(NSEvent *)event
 {
-    if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp)) {
+    if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp) && [event subtype] == 0) {
         [seenDummyEventLock lockWhenCondition:NO];
         [seenDummyEventLock unlockWithCondition:YES];
+    } else if ([event type] == NSApplicationDefined && [event subtype] == 777) {
+        void (^block)() = (void (^)()) [event data1];
+        block();
+        [block release];
     } else if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) {
         // Cocoa won't send us key up event when releasing a key while Cmd is down,
         // so we have to do it ourselves.
@@ -349,6 +353,33 @@
     }
 }
 
+/*
+ * Posts the block to the AppKit event queue which will be executed 
+ * on the main AppKit loop. 
+ * While running nested loops this event will be ignored. 
+ */
+- (void)postRunnableEvent:(void (^)())block 
+{
+    void (^copy)() = [block copy];
+    NSInteger encode = (NSInteger) copy;
+    [copy retain];
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    
+    NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
+                                        location: NSMakePoint(0,0)
+                                   modifierFlags: 0
+                                       timestamp: 0
+                                    windowNumber: 0
+                                         context: nil
+                                         subtype: 777
+                                           data1: encode
+                                           data2: 0];
+
+    [NSApp postEvent: event atStart: NO];
+    [pool drain];
+}
+
+
+
 - (void)postDummyEvent {
     seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO];
     dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime;