From 761ad810d978168edf3fce62dd8aa12f9e945292 Mon Sep 17 00:00:00 2001 From: Ken Thomases Date: Wed, 13 Mar 2013 16:52:57 -0500 Subject: [PATCH] winemac: Allow for processing Cocoa events while waiting for query results. --- dlls/winemac.drv/cocoa_app.h | 7 ++++++- dlls/winemac.drv/cocoa_app.m | 16 ++++++++++++++-- dlls/winemac.drv/cocoa_event.h | 1 + dlls/winemac.drv/cocoa_event.m | 22 ++++++++++++++++++++-- dlls/winemac.drv/event.c | 3 ++- 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/dlls/winemac.drv/cocoa_app.h b/dlls/winemac.drv/cocoa_app.h index 67f75e1c098..e15d734da3d 100644 --- a/dlls/winemac.drv/cocoa_app.h +++ b/dlls/winemac.drv/cocoa_app.h @@ -26,6 +26,11 @@ #define ERR(...) do { if (macdrv_err_on) LogError(__func__, __VA_ARGS__); } while (false) +enum { + WineApplicationEventWakeQuery, +}; + + @class WineEventQueue; @class WineWindow; @@ -87,7 +92,7 @@ - (void) windowGotFocus:(WineWindow*)window; - - (BOOL) waitUntilQueryDone:(int*)done timeout:(NSDate*)timeout; + - (BOOL) waitUntilQueryDone:(int*)done timeout:(NSDate*)timeout processEvents:(BOOL)processEvents; - (void) keyboardSelectionDidChange; diff --git a/dlls/winemac.drv/cocoa_app.m b/dlls/winemac.drv/cocoa_app.m index 5dc30089887..7ee009dc6f4 100644 --- a/dlls/winemac.drv/cocoa_app.m +++ b/dlls/winemac.drv/cocoa_app.m @@ -172,13 +172,25 @@ int macdrv_err_on; } } - - (BOOL) waitUntilQueryDone:(int*)done timeout:(NSDate*)timeout + - (BOOL) waitUntilQueryDone:(int*)done timeout:(NSDate*)timeout processEvents:(BOOL)processEvents { PerformRequest(NULL); do { - [[NSRunLoop currentRunLoop] runMode:WineAppWaitQueryResponseMode beforeDate:timeout]; + if (processEvents) + { + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:timeout + inMode:NSDefaultRunLoopMode + dequeue:YES]; + if (event) + [NSApp sendEvent:event]; + [pool release]; + } + else + [[NSRunLoop currentRunLoop] runMode:WineAppWaitQueryResponseMode beforeDate:timeout]; } while (!*done && [timeout timeIntervalSinceNow] >= 0); return *done; diff --git a/dlls/winemac.drv/cocoa_event.h b/dlls/winemac.drv/cocoa_event.h index 56964da326f..e74875ec5f0 100644 --- a/dlls/winemac.drv/cocoa_event.h +++ b/dlls/winemac.drv/cocoa_event.h @@ -36,6 +36,7 @@ - (void) postEvent:(const macdrv_event*)inEvent; - (void) discardEventsMatchingMask:(macdrv_event_mask)mask forWindow:(NSWindow*)window; + - (BOOL) query:(macdrv_query*)query timeout:(NSTimeInterval)timeout processEvents:(BOOL)processEvents; - (BOOL) query:(macdrv_query*)query timeout:(NSTimeInterval)timeout; @end diff --git a/dlls/winemac.drv/cocoa_event.m b/dlls/winemac.drv/cocoa_event.m index a5f1c1b6fb8..c95fac66735 100644 --- a/dlls/winemac.drv/cocoa_event.m +++ b/dlls/winemac.drv/cocoa_event.m @@ -252,7 +252,7 @@ static NSString* const WineEventQueueThreadDictionaryKey = @"WineEventQueueThrea [eventsLock unlock]; } - - (BOOL) query:(macdrv_query*)query timeout:(NSTimeInterval)timeout + - (BOOL) query:(macdrv_query*)query timeout:(NSTimeInterval)timeout processEvents:(BOOL)processEvents { macdrv_event event; NSDate* timeoutDate = [NSDate dateWithTimeIntervalSinceNow:timeout]; @@ -264,10 +264,15 @@ static NSString* const WineEventQueueThreadDictionaryKey = @"WineEventQueueThrea query->done = FALSE; [self postEvent:&event]; - timedout = ![NSApp waitUntilQueryDone:&query->done timeout:timeoutDate]; + timedout = ![NSApp waitUntilQueryDone:&query->done timeout:timeoutDate processEvents:processEvents]; return !timedout && query->status; } + - (BOOL) query:(macdrv_query*)query timeout:(NSTimeInterval)timeout + { + return [self query:query timeout:timeout processEvents:FALSE]; + } + /*********************************************************************** * OnMainThread @@ -470,8 +475,21 @@ void macdrv_set_query_done(macdrv_query *query) macdrv_retain_query(query); OnMainThreadAsync(^{ + NSEvent* event; + query->done = TRUE; macdrv_release_query(query); + + event = [NSEvent otherEventWithType:NSApplicationDefined + location:NSZeroPoint + modifierFlags:0 + timestamp:[[NSProcessInfo processInfo] systemUptime] + windowNumber:0 + context:nil + subtype:WineApplicationEventWakeQuery + data1:0 + data2:0]; + [NSApp postEvent:event atStart:TRUE]; }); } diff --git a/dlls/winemac.drv/event.c b/dlls/winemac.drv/event.c index 512d99ef964..1fba68195ae 100644 --- a/dlls/winemac.drv/event.c +++ b/dlls/winemac.drv/event.c @@ -240,7 +240,8 @@ DWORD CDECL macdrv_MsgWaitForMultipleObjectsEx(DWORD count, const HANDLE *handle timeout, flags & MWMO_ALERTABLE); } - if (data->current_event) event_mask = 0; /* don't process nested events */ + if (data->current_event && data->current_event->type != QUERY_EVENT) + event_mask = 0; /* don't process nested events */ if (process_events(data->queue, event_mask)) ret = count - 1; else if (count || timeout) -- 2.11.4.GIT