cocoa event wip

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1859 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
tmator 2009-01-12 23:59:27 +00:00
parent c0d29add82
commit 4fd0f3035a
3 changed files with 123 additions and 7 deletions

View File

@ -7,19 +7,20 @@
#else #else
#endif #endif
#include "Common.h"
#if defined(HAVE_COCOA) && HAVE_COCOA
#import "cocoaApp.h"
#endif
#include "Globals.h" #include "Globals.h"
#include "Host.h" #include "Host.h"
#include "Common.h"
#include "ISOFile.h" #include "ISOFile.h"
#include "CPUDetect.h" #include "CPUDetect.h"
#include "cmdline.h" #include "cmdline.h"
#include "Thread.h" #include "Thread.h"
#include "PowerPC/PowerPC.h" #include "PowerPC/PowerPC.h"
#if defined(HAVE_COCOA) && HAVE_COCOA
#include "cocoaApp.h"
#endif
#include "BootManager.h" #include "BootManager.h"
void* g_pCodeWindow = NULL; void* g_pCodeWindow = NULL;
@ -93,14 +94,83 @@ void Host_SetWiiMoteConnectionState(int _State) {}
//for cocoa we need to hijack the main to get event //for cocoa we need to hijack the main to get event
#if defined(HAVE_COCOA) && HAVE_COCOA #if defined(HAVE_COCOA) && HAVE_COCOA
@interface CocoaThread : NSObject
{
}
- (void)cocoaThreadStart;
- (void)cocoaThreadRun:(id)sender;
- (void)cocoaThreadQuit:(NSNotification*)note;
@end
static NSString *CocoaThreadHaveFinish = @"CocoaThreadHaveFinish";
int cocoaArgc;
char **cocoaArgv;
int appleMain(int argc, char *argv[]); int appleMain(int argc, char *argv[]);
@implementation CocoaThread
- (void)cocoaThreadStart
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cocoaThreadQuit:) name:CocoaThreadHaveFinish object:nil];
[NSThread detachNewThreadSelector:@selector(cocoaThreadRun:) toTarget:self withObject:nil];
}
- (void)cocoaThreadRun:(id)sender
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//launch main
appleMain(cocoaArgc,cocoaArgv);
[[NSNotificationCenter defaultCenter] postNotificationName:CocoaThreadHaveFinish object:nil];
[pool release];
}
- (void)cocoaThreadQuit:(NSNotification*)note
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cocoaCreateApp(); cocoaArgc = argc;
return appleMain(argc, argv); cocoaArgv = argv;
cocoaCreateApp();
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CocoaThread *thread = [[CocoaThread alloc] init];
NSEvent *event = [[NSEvent alloc] init];
[thread cocoaThreadStart];
//cocoa event loop
while(true)
{
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
cocoaSendEvent(event);
}
[event release];
[thread release];
[pool release];
} }

View File

@ -1,11 +1,15 @@
#import <Cocoa/Cocoa.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
void cocoaSendEvent(NSEvent *event);
void cocoaCreateApp(); void cocoaCreateApp();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,5 +1,4 @@
#import "cocoaApp.h" #import "cocoaApp.h"
#import <Cocoa/Cocoa.h>
@implementation NSApplication(i) @implementation NSApplication(i)
- (void)appRunning - (void)appRunning
@ -47,3 +46,46 @@ void cocoaCreateApp()
} }
void cocoaKeyCode(NSEvent *event)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSConnection *connec = [NSConnection defaultConnection];
[connec setRootObject: event];
if ([connec registerName: @"DolphinCocoaEvent"] == NO)
{
printf("error creating nsconnection\n");
}
[pool release];
}
void cocoaSendEvent(NSEvent *event)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
if ( event != nil ) {
switch ([event type]) {
case NSKeyDown:
cocoaKeyCode(event);
break;
case NSKeyUp:
cocoaKeyCode(nil);
break;
default:
[NSApp sendEvent:event];
break;
}
}
[pool release];
}