320 }
321
322 #define DRAGMASK (NSMouseMovedMask | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseDraggedMask | NSLeftMouseUpMask | NSRightMouseUpMask | NSFlagsChangedMask | NSKeyDownMask)
323
324 - (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag {
325 if (mask == DRAGMASK && [((NSString *)kCFRunLoopDefaultMode) isEqual:mode]) {
326 postEventDuringEventSynthesis = YES;
327 }
328
329 NSEvent *event = [super nextEventMatchingMask:mask untilDate:expiration inMode:mode dequeue: deqFlag];
330 postEventDuringEventSynthesis = NO;
331
332 return event;
333 }
334
335 // NSTimeInterval has microseconds precision
336 #define TS_EQUAL(ts1, ts2) (fabs((ts1) - (ts2)) < 1e-6)
337
338 - (void)sendEvent:(NSEvent *)event
339 {
340 if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp)) {
341 [seenDummyEventLock lockWhenCondition:NO];
342 [seenDummyEventLock unlockWithCondition:YES];
343 } else if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) {
344 // Cocoa won't send us key up event when releasing a key while Cmd is down,
345 // so we have to do it ourselves.
346 [[self keyWindow] sendEvent:event];
347 } else {
348 [super sendEvent:event];
349 }
350 }
351
352 - (void)postDummyEvent {
353 seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO];
354 dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime;
355
356 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
357 NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
358 location: NSMakePoint(0,0)
359 modifierFlags: 0
360 timestamp: dummyEventTimestamp
361 windowNumber: 0
362 context: nil
363 subtype: 0
364 data1: 0
365 data2: 0];
366 [NSApp postEvent: event atStart: NO];
367 [pool drain];
368 }
369
370 - (void)waitForDummyEvent {
|
320 }
321
322 #define DRAGMASK (NSMouseMovedMask | NSLeftMouseDraggedMask | NSRightMouseDownMask | NSRightMouseDraggedMask | NSLeftMouseUpMask | NSRightMouseUpMask | NSFlagsChangedMask | NSKeyDownMask)
323
324 - (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag {
325 if (mask == DRAGMASK && [((NSString *)kCFRunLoopDefaultMode) isEqual:mode]) {
326 postEventDuringEventSynthesis = YES;
327 }
328
329 NSEvent *event = [super nextEventMatchingMask:mask untilDate:expiration inMode:mode dequeue: deqFlag];
330 postEventDuringEventSynthesis = NO;
331
332 return event;
333 }
334
335 // NSTimeInterval has microseconds precision
336 #define TS_EQUAL(ts1, ts2) (fabs((ts1) - (ts2)) < 1e-6)
337
338 - (void)sendEvent:(NSEvent *)event
339 {
340 if ([event type] == NSApplicationDefined && TS_EQUAL([event timestamp], dummyEventTimestamp) && [event subtype] == 0) {
341 [seenDummyEventLock lockWhenCondition:NO];
342 [seenDummyEventLock unlockWithCondition:YES];
343 } else if ([event type] == NSApplicationDefined && [event subtype] == 777) {
344 void (^block)() = (void (^)()) [event data1];
345 block();
346 [block release];
347 } else if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) {
348 // Cocoa won't send us key up event when releasing a key while Cmd is down,
349 // so we have to do it ourselves.
350 [[self keyWindow] sendEvent:event];
351 } else {
352 [super sendEvent:event];
353 }
354 }
355
356 - (void)postRunnableEvent:(void (^)())block
357 {
358 void (^copy)() = [block copy];
359 NSInteger encode = (NSInteger) copy;
360 [copy retain];
361 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
362 NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
363 location: NSMakePoint(0,0)
364 modifierFlags: 0
365 timestamp: 0
366 windowNumber: 0
367 context: nil
368 subtype: 777
369 data1: encode
370 data2: 0];
371
372 [NSApp postEvent: event atStart: NO];
373 [pool drain];
374 }
375
376
377
378 - (void)postDummyEvent {
379 seenDummyEventLock = [[NSConditionLock alloc] initWithCondition:NO];
380 dummyEventTimestamp = [NSProcessInfo processInfo].systemUptime;
381
382 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
383 NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
384 location: NSMakePoint(0,0)
385 modifierFlags: 0
386 timestamp: dummyEventTimestamp
387 windowNumber: 0
388 context: nil
389 subtype: 0
390 data1: 0
391 data2: 0];
392 [NSApp postEvent: event atStart: NO];
393 [pool drain];
394 }
395
396 - (void)waitForDummyEvent {
|