|
@@ -166,33 +166,23 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
bool IMainLoopDriver.EventsPending (bool wait)
|
|
|
{
|
|
|
- long now = DateTime.UtcNow.Ticks;
|
|
|
-
|
|
|
- int pollTimeout, n;
|
|
|
- if (mainLoop.timeouts.Count > 0) {
|
|
|
- pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
|
|
|
- if (pollTimeout < 0)
|
|
|
- return true;
|
|
|
+ int pollTimeout = 0;
|
|
|
+ int n;
|
|
|
|
|
|
- } else
|
|
|
- pollTimeout = -1;
|
|
|
-
|
|
|
- if (!wait)
|
|
|
- pollTimeout = 0;
|
|
|
+ if (CkeckTimeout (wait, ref pollTimeout))
|
|
|
+ return true;
|
|
|
|
|
|
UpdatePollMap ();
|
|
|
|
|
|
while (true) {
|
|
|
- if (wait && pollTimeout == -1) {
|
|
|
- pollTimeout = 0;
|
|
|
- }
|
|
|
- n = poll (pollmap, (uint)pollmap.Length, pollTimeout);
|
|
|
+ n = poll (pollmap, (uint)pollmap.Length, 0);
|
|
|
if (n > 0) {
|
|
|
break;
|
|
|
}
|
|
|
- if (mainLoop.timeouts.Count > 0 || mainLoop.idleHandlers.Count > 0) {
|
|
|
+ if (mainLoop.idleHandlers.Count > 0 || CkeckTimeout (wait, ref pollTimeout)) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -202,6 +192,24 @@ namespace Terminal.Gui {
|
|
|
return n > 0 || mainLoop.timeouts.Count > 0 && ((mainLoop.timeouts.Keys [0] - DateTime.UtcNow.Ticks) < 0) || ic > 0;
|
|
|
}
|
|
|
|
|
|
+ bool CkeckTimeout (bool wait, ref int pollTimeout)
|
|
|
+ {
|
|
|
+ long now = DateTime.UtcNow.Ticks;
|
|
|
+
|
|
|
+ if (mainLoop.timeouts.Count > 0) {
|
|
|
+ pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
|
|
|
+ if (pollTimeout < 0)
|
|
|
+ return true;
|
|
|
+
|
|
|
+ } else
|
|
|
+ pollTimeout = -1;
|
|
|
+
|
|
|
+ if (!wait)
|
|
|
+ pollTimeout = 0;
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
void IMainLoopDriver.MainIteration ()
|
|
|
{
|
|
|
if (pollmap != null) {
|