From 3f44ba59eb50132970c1cc51aaab1785ffd6045d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 7 Jun 2016 18:02:37 +0200 Subject: [PATCH] Add pending_events function callback --- ui/drivers/cocoa/ui_cocoa_application.m | 9 +++++++++ ui/drivers/null/ui_null_application.c | 6 ++++++ ui/drivers/win32/ui_win32_application.c | 17 +++++++++++------ ui/ui_companion_driver.h | 1 + 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ui/drivers/cocoa/ui_cocoa_application.m b/ui/drivers/cocoa/ui_cocoa_application.m index 63af3b67ee..4ca526a099 100644 --- a/ui/drivers/cocoa/ui_cocoa_application.m +++ b/ui/drivers/cocoa/ui_cocoa_application.m @@ -23,6 +23,14 @@ #include "cocoa_common.h" #include "../../ui_companion_driver.h" +static bool ui_application_cocoa_pending_events(void) +{ + NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; + if (!event) + return false; + return true; +} + static void ui_application_cocoa_process_events(void) { while (1) @@ -37,6 +45,7 @@ static void ui_application_cocoa_process_events(void) } const ui_application_t ui_application_cocoa = { + ui_application_cocoa_pending_events, ui_application_cocoa_process_events, "cocoa" }; diff --git a/ui/drivers/null/ui_null_application.c b/ui/drivers/null/ui_null_application.c index 6d49b0878c..7f90a10d60 100644 --- a/ui/drivers/null/ui_null_application.c +++ b/ui/drivers/null/ui_null_application.c @@ -21,11 +21,17 @@ #include "../../ui_companion_driver.h" +static bool ui_application_null_pending_events(void) +{ + return true; +} + static void ui_application_null_process_events(void) { } const ui_application_t ui_application_null = { + ui_application_null_pending_events, ui_application_null_process_events, "null" }; diff --git a/ui/drivers/win32/ui_win32_application.c b/ui/drivers/win32/ui_win32_application.c index 6c0a673fd9..9603469aad 100644 --- a/ui/drivers/win32/ui_win32_application.c +++ b/ui/drivers/win32/ui_win32_application.c @@ -23,23 +23,28 @@ #include "../../ui_companion_driver.h" -static void ui_application_win32_process_events(void) +static bool ui_application_win32_pending_events(void) { MSG msg; + return PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); +} - while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) +static void ui_application_win32_process_events(void) +{ + while (ui_application_win32_pending_events()) { - MSG msg2; + MSG msg; - if (PeekMessage(&msg2, 0, 0, 0, PM_REMOVE)) + if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg2); - DispatchMessage (&msg2); + TranslateMessage(&msg); + DispatchMessage (&msg); } } } const ui_application_t ui_application_win32 = { + ui_application_win32_pending_events, ui_application_win32_process_events, "win32" }; diff --git a/ui/ui_companion_driver.h b/ui/ui_companion_driver.h index 131b01e0e4..a1bf3a6752 100644 --- a/ui/ui_companion_driver.h +++ b/ui/ui_companion_driver.h @@ -33,6 +33,7 @@ RETRO_BEGIN_DECLS typedef struct ui_application { + bool (*pending_events)(void); void (*process_events)(void); const char *ident; } ui_application_t;