Commit e7d5f329 authored by Ken Thomases's avatar Ken Thomases Committed by Alexandre Julliard

winemac: Refactor WineApplication class to separate most logic into a controller class.

parent 304463b4
......@@ -35,7 +35,7 @@ enum {
@class WineWindow;
@interface WineApplication : NSApplication <NSApplicationDelegate>
@interface WineApplicationController : NSObject <NSApplicationDelegate>
{
CFRunLoopSourceRef requestSource;
NSMutableArray* requests;
......@@ -84,6 +84,8 @@ enum {
@property (readonly, nonatomic) NSArray* orderedWineWindows;
@property (readonly, nonatomic) BOOL areDisplaysCaptured;
+ (WineApplicationController*) sharedController;
- (void) transformProcessToForeground;
- (BOOL) registerEventQueue:(WineEventQueue*)queue;
......@@ -104,8 +106,22 @@ enum {
ordered:(NSWindowOrderingMode)order
relativeTo:(WineWindow*)otherWindow;
- (BOOL) handleEvent:(NSEvent*)anEvent;
- (void) didSendEvent:(NSEvent*)anEvent;
@end
@interface WineApplication : NSApplication
{
WineApplicationController* wineController;
}
@property (readwrite, assign, nonatomic) WineApplicationController* wineController;
@end
void OnMainThreadAsync(dispatch_block_t block);
void LogError(const char* func, NSString* format, ...);
......
......@@ -269,7 +269,9 @@ static NSString* const WineEventQueueThreadDictionaryKey = @"WineEventQueueThrea
[self postEvent:event];
macdrv_release_event(event);
timedout = ![NSApp waitUntilQueryDone:&query->done timeout:timeoutDate processEvents:processEvents];
timedout = ![[WineApplicationController sharedController] waitUntilQueryDone:&query->done
timeout:timeoutDate
processEvents:processEvents];
return !timedout && query->status;
}
......@@ -347,7 +349,7 @@ macdrv_event_queue macdrv_create_event_queue(macdrv_event_handler handler)
queue = [[[WineEventQueue alloc] initWithEventHandler:handler] autorelease];
if (queue)
{
if ([NSApp registerEventQueue:queue])
if ([[WineApplicationController sharedController] registerEventQueue:queue])
[threadDict setObject:queue forKey:WineEventQueueThreadDictionaryKey];
else
queue = nil;
......@@ -370,7 +372,7 @@ void macdrv_destroy_event_queue(macdrv_event_queue queue)
WineEventQueue* q = (WineEventQueue*)queue;
NSMutableDictionary* threadDict = [[NSThread currentThread] threadDictionary];
[NSApp unregisterEventQueue:q];
[[WineApplicationController sharedController] unregisterEventQueue:q];
[threadDict removeObjectForKey:WineEventQueueThreadDictionaryKey];
[pool release];
......
......@@ -39,6 +39,7 @@ struct cocoa_app_startup_info {
NSConditionLock* lock;
unsigned long long tickcount;
uint64_t uptime_ns;
BOOL success;
};
......@@ -61,12 +62,23 @@ static void run_cocoa_app(void* info)
{
struct cocoa_app_startup_info* startup_info = info;
NSConditionLock* lock = startup_info->lock;
BOOL created_app = FALSE;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[WineApplication sharedApplication];
[NSApp setDelegate:(WineApplication*)NSApp];
[NSApp computeEventTimeAdjustmentFromTicks:startup_info->tickcount uptime:startup_info->uptime_ns];
if (!NSApp)
{
[WineApplication sharedApplication];
created_app = TRUE;
}
if ([NSApp respondsToSelector:@selector(setWineController:)])
{
WineApplicationController* controller = [WineApplicationController sharedController];
[NSApp setWineController:controller];
[controller computeEventTimeAdjustmentFromTicks:startup_info->tickcount uptime:startup_info->uptime_ns];
startup_info->success = TRUE;
}
/* Retain the lock while we're using it, so macdrv_start_cocoa_app()
doesn't deallocate it in the middle of us unlocking it. */
......@@ -77,8 +89,11 @@ static void run_cocoa_app(void* info)
[pool release];
/* Never returns */
[NSApp run];
if (created_app && startup_info->success)
{
/* Never returns */
[NSApp run];
}
}
......@@ -109,6 +124,7 @@ int macdrv_start_cocoa_app(unsigned long long tickcount)
startup_info.lock = [[NSConditionLock alloc] initWithCondition:COCOA_APP_NOT_RUNNING];
startup_info.tickcount = tickcount;
startup_info.success = FALSE;
mach_timebase_info(&mach_timebase);
startup_info.uptime_ns = uptime_mach * mach_timebase.numer / mach_timebase.denom;
......@@ -128,7 +144,7 @@ int macdrv_start_cocoa_app(unsigned long long tickcount)
if ([startup_info.lock lockWhenCondition:COCOA_APP_RUNNING beforeDate:timeLimit])
{
[startup_info.lock unlock];
ret = 0;
ret = !startup_info.success;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment