src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m
Print this page
*** 335,356 ****
// NSTimeInterval has microseconds precision
#define TS_EQUAL(ts1, ts2) (fabs((ts1) - (ts2)) < 1e-6)
- (void)sendEvent:(NSEvent *)event
{
! if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp)) {
[seenDummyEventLock lockWhenCondition:NO];
[seenDummyEventLock unlockWithCondition:YES];
} 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.
[[self keyWindow] sendEvent:event];
} else {
[super sendEvent:event];
}
}
- (void)postDummyEvent {
seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO];
dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
--- 335,382 ----
// NSTimeInterval has microseconds precision
#define TS_EQUAL(ts1, ts2) (fabs((ts1) - (ts2)) < 1e-6)
- (void)sendEvent:(NSEvent *)event
{
! 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.
[[self keyWindow] sendEvent:event];
} else {
[super sendEvent:event];
}
}
+ - (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;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];