bypass NSApp
bypass NSApp
- Subject: bypass NSApp
- From: Julien Isorce <email@hidden>
- Date: Wed, 8 Jul 2009 10:34:21 +0200
Hi,
I am in a case where I have no access to the main thread since I am making a
plugin which consists of a dynamic library loaded by a third party program.
This third party program has nothing to deal with Cocoa and only uses
standard C API. And it has it's own main loop.
In the plugin I create a NSWindow and a NSRunLoop in a pthread. Then I run
the NSRunLoop in this thread in order to not block the C main loop from the
thrid party program loader. I am also calling [NSApp sharedApplication] in
this pthread just after creating it.
To update the window, I am calling periodically (i.e. the external programm
ask an update) a perfomSelectorOnThread.
And it's ok because the pthread seems to be converted to a NSThread when he
is created.
Then the problem is that the [NSApp run] (or using nextEventMatching..) is
never called in the main thread. (same about [NSApp sharedApplication])
The result is there is this circle icon over the window which means that the
application is busy.
But I am able to move the window and the content is correctly updated.
So I think some basic application events are not perfomed.
According to
http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW11:
"What especially distinguishes the main event loop is an input source called
the event source, which is constructed when the global
NSApplication<http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html#//apple_ref/occ/cl/NSApplication>object
(
NSApp<http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html#//apple_ref/c/data/NSApp>)
is initialized. The event source consists of a port for receiving events
from the window server and a FIFO queue—the event queue—for holding those
events until the application can process them"
So in a NSThread I could use addPort from the current run loop.
Do you know how to retrieve this port associated to the event source ?
Actually I am trying to make a NSRunLoop be equivalent to the NSApp in order
the run a NSLoopRun in a NSThread while the NSApp is never running.
I know that "NSApp must be run in the main thread", but I hope there is a
way to bypass this sentence. If it's not possible, what a such limitation on
MacOSX because this limitation does not exists on X11 and gdi32(win32). And
even GNUstep has not this limitation.
Any kind of comment or suggestion would be appreciated.
Sincerely
Julien
_______________________________________________
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