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