changed all event handling to always filter events
[rocksndiamonds.git] / src / events.c
index 10b866d433f5d72a8cbde3275db3516317af5a0e..2998066b98230577aae3198ddbc0b861877646bc 100644 (file)
@@ -128,6 +128,19 @@ static boolean SkipPressedMouseMotionEvent(const Event *event)
   return FALSE;
 }
 
+static boolean WaitEventFiltered(Event *event)
+{
+  WaitEvent(event);
+
+  if (!FilterEvents(event))
+    return FALSE;
+
+  if (SkipPressedMouseMotionEvent(event))
+    return FALSE;
+
+  return TRUE;
+}
+
 /* this is especially needed for event modifications for the Android target:
    if mouse coordinates should be modified in the event filter function,
    using a properly installed SDL event filter does not work, because in
@@ -139,20 +152,8 @@ static boolean SkipPressedMouseMotionEvent(const Event *event)
 boolean NextValidEvent(Event *event)
 {
   while (PendingEvent())
-  {
-    boolean handle_this_event = FALSE;
-
-    WaitEvent(event);
-
-    if (FilterEvents(event))
-      handle_this_event = TRUE;
-
-    if (SkipPressedMouseMotionEvent(event))
-      handle_this_event = FALSE;
-
-    if (handle_this_event)
+    if (WaitEventFiltered(event))
       return TRUE;
-  }
 
   return FALSE;
 }
@@ -340,12 +341,10 @@ void EventLoop(void)
 
 void ClearEventQueue()
 {
-  while (PendingEvent())
-  {
-    Event event;
-
-    WaitEvent(&event);
+  Event event;
 
+  while (NextValidEvent(&event))
+  {
     switch (event.type)
     {
       case EVENT_BUTTONRELEASE:
@@ -392,7 +391,8 @@ void SleepWhileUnmapped()
   {
     Event event;
 
-    WaitEvent(&event);
+    if (!WaitEventFiltered(&event))
+      continue;
 
     switch (event.type)
     {