One Quickie


Making a custom event tracking runloop (NSView->General)
Sometimes in your mouse tracking code you want to use the NSEventTrackingRunLoopMode, such as you wanting to use an NSNotificationQueue to coalesce updates for your own mouse tracking code. I've been sticking a call to this in my mouseDown: handler for the cases when I want the secondary run loop
- (void) runEventTrackingRunLoop
{
    NSEventType eventType = NSLeftMouseDown;

    unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
        | NSLeftMouseDraggedMask | NSMouseMovedMask;

    while (eventType != NSLeftMouseUp) {
        NSEvent *event;
        event = [NSApp nextEventMatchingMask: eventMask
                       untilDate: [NSDate distantFuture]
                       inMode: NSEventTrackingRunLoopMode
                       dequeue: YES];

        eventType = [event type];

        if (eventType == NSLeftMouseDragged) {
            [self mouseDragged: event];
        }
    }

} // runEventTrackingRunLoop
(and thanks to Rainer Brockerhof for pointing out a no-op line of code from the original version of this)



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com