src/video/cocoa/SDL_cocoamousetap.m
changeset 7610 b043c5c726c1
parent 7607 7753a6f8cda8
child 7917 686df9c2b98a
equal deleted inserted replaced
7609:6e1abd05047c 7610:b043c5c726c1
   127             CGEventSetLocation(event, newLocation);
   127             CGEventSetLocation(event, newLocation);
   128         }
   128         }
   129     }
   129     }
   130 
   130 
   131     return event;
   131     return event;
       
   132 }
       
   133 
       
   134 static void
       
   135 SemaphorePostCallback(CFRunLoopTimerRef timer, void *info)
       
   136 {
       
   137     SDL_SemPost((SDL_sem*)info);
   132 }
   138 }
   133 
   139 
   134 static int
   140 static int
   135 Cocoa_MouseTapThread(void *data)
   141 Cocoa_MouseTapThread(void *data)
   136 {
   142 {
   161         return 1;
   167         return 1;
   162     }
   168     }
   163 
   169 
   164     tapdata->runloop = CFRunLoopGetCurrent();
   170     tapdata->runloop = CFRunLoopGetCurrent();
   165     CFRunLoopAddSource(tapdata->runloop, tapdata->runloopSource, kCFRunLoopCommonModes);
   171     CFRunLoopAddSource(tapdata->runloop, tapdata->runloopSource, kCFRunLoopCommonModes);
   166     CFRunLoopPerformBlock(tapdata->runloop, kCFRunLoopCommonModes, ^{
   172     CFRunLoopTimerContext context = {.info = tapdata->runloopStartedSemaphore};
   167         /* We signal this *after* the run loop has started, indicating it's safe to CFRunLoopStop it. */
   173     /* We signal the runloop started semaphore *after* the run loop has started, indicating it's safe to CFRunLoopStop it. */
   168         SDL_SemPost(tapdata->runloopStartedSemaphore);
   174     CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent(), 0, 0, 0, &SemaphorePostCallback, &context);
   169     });
   175     CFRunLoopAddTimer(tapdata->runloop, timer, kCFRunLoopCommonModes);
       
   176     CFRelease(timer);
   170 
   177 
   171     /* Run the event loop to handle events in the event tap. */
   178     /* Run the event loop to handle events in the event tap. */
   172     CFRunLoopRun();
   179     CFRunLoopRun();
   173     /* Make sure this is signaled so that SDL_QuitMouseEventTap knows it can safely SDL_WaitThread for us. */
   180     /* Make sure this is signaled so that SDL_QuitMouseEventTap knows it can safely SDL_WaitThread for us. */
   174     if (SDL_SemValue(tapdata->runloopStartedSemaphore) < 1) {
   181     if (SDL_SemValue(tapdata->runloopStartedSemaphore) < 1) {