324 325 - (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag { 326 if (mask == DRAGMASK && [((NSString *)kCFRunLoopDefaultMode) isEqual:mode]) { 327 postEventDuringEventSynthesis = YES; 328 } 329 330 NSEvent *event = [super nextEventMatchingMask:mask untilDate:expiration inMode:mode dequeue: deqFlag]; 331 postEventDuringEventSynthesis = NO; 332 333 return event; 334 } 335 336 // NSTimeInterval has microseconds precision 337 #define TS_EQUAL(ts1, ts2) (fabs((ts1) - (ts2)) < 1e-6) 338 339 - (void)sendEvent:(NSEvent *)event 340 { 341 if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp)) { 342 [seenDummyEventLock lockWhenCondition:NO]; 343 [seenDummyEventLock unlockWithCondition:YES]; 344 } else { 345 [super sendEvent:event]; 346 } 347 } 348 349 - (void)postDummyEvent { 350 seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO]; 351 dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime; 352 353 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 354 NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined 355 location: NSMakePoint(0,0) 356 modifierFlags: 0 357 timestamp: dummyEventTimestamp 358 windowNumber: 0 359 context: nil 360 subtype: 0 361 data1: 0 362 data2: 0]; 363 [NSApp postEvent: event atStart: NO]; | 324 325 - (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag { 326 if (mask == DRAGMASK && [((NSString *)kCFRunLoopDefaultMode) isEqual:mode]) { 327 postEventDuringEventSynthesis = YES; 328 } 329 330 NSEvent *event = [super nextEventMatchingMask:mask untilDate:expiration inMode:mode dequeue: deqFlag]; 331 postEventDuringEventSynthesis = NO; 332 333 return event; 334 } 335 336 // NSTimeInterval has microseconds precision 337 #define TS_EQUAL(ts1, ts2) (fabs((ts1) - (ts2)) < 1e-6) 338 339 - (void)sendEvent:(NSEvent *)event 340 { 341 if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp)) { 342 [seenDummyEventLock lockWhenCondition:NO]; 343 [seenDummyEventLock unlockWithCondition:YES]; 344 } else if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) { 345 // Cocoa won't send us key up event when releasing a key while Cmd is down, 346 // so we have to do it ourselves. 347 [[self keyWindow] sendEvent:event]; 348 } else { 349 [super sendEvent:event]; 350 } 351 } 352 353 - (void)postDummyEvent { 354 seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO]; 355 dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime; 356 357 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 358 NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined 359 location: NSMakePoint(0,0) 360 modifierFlags: 0 361 timestamp: dummyEventTimestamp 362 windowNumber: 0 363 context: nil 364 subtype: 0 365 data1: 0 366 data2: 0]; 367 [NSApp postEvent: event atStart: NO]; |