jdk/src/macosx/native/sun/osxapp/NSApplicationAWT.m
changeset 13991 e62879b84a14
parent 13539 2a658e96e769
child 13992 d1b65c4e924c
equal deleted inserted replaced
13990:3e72145fd93a 13991:e62879b84a14
    50     // Multiple Calls: NO
    50     // Multiple Calls: NO
    51     //  Caller: +[NSApplication sharedApplication]
    51     //  Caller: +[NSApplication sharedApplication]
    52 
    52 
    53 AWT_ASSERT_APPKIT_THREAD;
    53 AWT_ASSERT_APPKIT_THREAD;
    54     fApplicationName = nil;
    54     fApplicationName = nil;
       
    55     dummyEventTimestamp = 0.0;
       
    56     seenDummyEventLock = nil;
       
    57 
    55 
    58 
    56     // NSApplication will call _RegisterApplication with the application's bundle, but there may not be one.
    59     // NSApplication will call _RegisterApplication with the application's bundle, but there may not be one.
    57     // So, we need to call it ourselves to ensure the app is set up properly.
    60     // So, we need to call it ourselves to ensure the app is set up properly.
    58     [self registerWithProcessManager];
    61     [self registerWithProcessManager];
    59 
    62 
   326     postEventDuringEventSynthesis = NO;
   329     postEventDuringEventSynthesis = NO;
   327 
   330 
   328     return event;
   331     return event;
   329 }
   332 }
   330 
   333 
       
   334 // NSTimeInterval has microseconds precision
       
   335 #define TS_EQUAL(ts1, ts2) (fabs((ts1) - (ts2)) < 1e-6)
       
   336 
       
   337 - (void)sendEvent:(NSEvent *)event
       
   338 {
       
   339     if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp)) {
       
   340         [seenDummyEventLock lockWhenCondition:NO];
       
   341         [seenDummyEventLock unlockWithCondition:YES];
       
   342     } else {
       
   343         [super sendEvent:event];
       
   344     }
       
   345 }
       
   346 
       
   347 - (void)postDummyEvent {
       
   348     seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO];
       
   349     dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime;
       
   350     
       
   351     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    
       
   352     NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
       
   353                                         location: NSMakePoint(0,0)
       
   354                                    modifierFlags: 0
       
   355                                        timestamp: dummyEventTimestamp
       
   356                                     windowNumber: 0
       
   357                                          context: nil
       
   358                                          subtype: 0
       
   359                                            data1: 0
       
   360                                            data2: 0];
       
   361     [NSApp postEvent: event atStart: NO];
       
   362     [pool drain];
       
   363 }
       
   364 
       
   365 - (void)waitForDummyEvent {
       
   366     [seenDummyEventLock lockWhenCondition:YES];
       
   367     [seenDummyEventLock unlock];
       
   368     [seenDummyEventLock release];
       
   369 
       
   370     seenDummyEventLock = nil;
       
   371 }
       
   372 
   331 @end
   373 @end
   332 
   374 
   333 
   375 
   334 void OSXAPP_SetApplicationDelegate(id <NSApplicationDelegate> delegate)
   376 void OSXAPP_SetApplicationDelegate(id <NSApplicationDelegate> delegate)
   335 {
   377 {