Where does the RunLoop run?


#1

I have created a NSBorderless Window that I can drag around. To do this, I created a tight loop in my view’s mousedown selector so that I can query the view’s window’s nextEventMatchingMask: selector and constantly query for mouse movement until I sense a mouseup event. Since I assume that my mousedown selector is run on the main thread, where does the runloop run? Does it run on the main thread? If so, why does my mousedown selector not have to return for the runloop to process the next event? It must obviously run on another thread.


#2

Are you running your own event loop, polling for mouse events, or falling out the bottom of mouseDown: ? (or, of course, none of the above :slight_smile: )


#3

I am running the following in my mouseDown: waiting for a mouseup event. I have not created a second thread. All of this happens on the main thread. As I understand, all UI updates are done on the main thread, so why would this work? I assume I should have to return out of the mousedown: before [window…] gets a chance to catch the next event, no?

while (YES)
{

    NSEvent *newEvent = [window nextEventMatchingMask:(NSLeftMouseDraggedMask | NSLeftMouseUpMask)];

    if ([newEvent type] == NSLeftMouseUp)
	{
		break;
	}
	
	//Do magical stuff
	
	[window setFrame:newFrame display:YES animate:NO];
}

#4

ahh. nextEventMatchingMask will be spinning a runloop inside of it before it returns. It’s not shifting stuff to other threads. A “runloop” is actually just a data structure sitting in thread-local memory that has sets of input sources. Then someone explicilty makes a call to check the input sources. Things like nextEventMatchingMask, or explicitly doing a run / runUntilDate.


#5

Ok that clears it up. :smiley: