• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Non-blocking custom event loop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Non-blocking custom event loop?


  • Subject: Non-blocking custom event loop?
  • From: Daniel Furrer <email@hidden>
  • Date: Mon, 3 Aug 2009 17:30:02 +0200

I have my own event-loop where I call nextEventMatchingMask: repeatedly.
Many examples I found just pass a untilDate of [NSDate distantPast] to get
this behaviour as stated in the documentation but this doesn't seem to work
for me - even in a very simple setting.
Can anyone see what's wrong?

int main(int argc, char **args){
    NSRect frame = NSMakeRect(100, 100, 500, 400);

    NSApplication *application = [NSApplication sharedApplication];
    NSWindow* window  = [[NSWindow alloc] initWithContentRect:frame

styleMask:NSBorderlessWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
                                        backing:NSBackingStoreBuffered
                                        defer:NO];


    // Start the main event loop:
    [application finishLaunching];
    while(true) {
        NSEvent *event;
        while ( event =
                [application
                    nextEventMatchingMask:NSAnyEventMask
                    untilDate: [NSDate distantPast] // nil
                    inMode:NSDefaultRunLoopMode
                    dequeue:YES] )
                {
                    NSLog(@"Event: %@", (id)event);
                    [application sendEvent:event];
                    [application updateWindows];
                }
    }

    return 0;
}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: [IB] - can't assign keyboard shortcut to a menu item
  • Next by Date: Re: Table view data source methods order?
  • Previous by thread: Re: Adding more and more key/value observers is much too slow - workaround needed.
  • Next by thread: NSSound play often fails
  • Index(es):
    • Date
    • Thread