Fix exit conditions in the WinAPI event loop.

This commit is contained in:
Sönke Ludwig 2017-02-22 17:34:44 +01:00
parent f84139ba63
commit 578065f70a

View file

@ -35,6 +35,9 @@ final class WinAPIEventDriverCore : EventDriverCore {
override size_t waiterCount() { return m_waiterCount; } override size_t waiterCount() { return m_waiterCount; }
package void addWaiter() { m_waiterCount++; }
package void removeWaiter() { m_waiterCount--; }
override ExitReason processEvents(Duration timeout = Duration.max) override ExitReason processEvents(Duration timeout = Duration.max)
{ {
import std.algorithm : min; import std.algorithm : min;
@ -63,7 +66,7 @@ final class WinAPIEventDriverCore : EventDriverCore {
if (m_exit) { if (m_exit) {
m_exit = false; m_exit = false;
return ExitReason.exited; return ExitReason.exited;
} } else if (got_event) break;
if (timeout != Duration.max) if (timeout != Duration.max)
timeout -= (now - prev_step).hnsecs; timeout -= (now - prev_step).hnsecs;
} while (timeout > 0.seconds); } while (timeout > 0.seconds);
@ -108,8 +111,10 @@ final class WinAPIEventDriverCore : EventDriverCore {
timeout_msecs, QS_ALLEVENTS, MWMO_ALERTABLE|MWMO_INPUTAVAILABLE); } (); timeout_msecs, QS_ALLEVENTS, MWMO_ALERTABLE|MWMO_INPUTAVAILABLE); } ();
if (ret >= WAIT_OBJECT_0 && ret < WAIT_OBJECT_0 + m_registeredEvents.length) { if (ret >= WAIT_OBJECT_0 && ret < WAIT_OBJECT_0 + m_registeredEvents.length) {
if (auto pc = m_registeredEvents[ret - WAIT_OBJECT_0] in m_eventCallbacks) if (auto pc = m_registeredEvents[ret - WAIT_OBJECT_0] in m_eventCallbacks) {
(*pc)(); (*pc)();
got_event = true;
}
} }
/*if (ret == WAIT_OBJECT_0) { /*if (ret == WAIT_OBJECT_0) {
got_event = true; got_event = true;
@ -125,10 +130,9 @@ final class WinAPIEventDriverCore : EventDriverCore {
MSG msg; MSG msg;
//uint cnt = 0; //uint cnt = 0;
while (() @trusted { return PeekMessageW(&msg, null, 0, 0, PM_REMOVE); } ()) { while (() @trusted { return PeekMessageW(&msg, null, 0, 0, PM_REMOVE); } ()) {
if( msg.message == WM_QUIT ) { if (msg.message == WM_QUIT && m_exit)
m_exit = true; break;
return false;
}
() @trusted { () @trusted {
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessageW(&msg); DispatchMessageW(&msg);