rnd-20131209-1-src
[rocksndiamonds.git] / src / events.c
index d583d87305b3165cbc6663963f273d43391c79ae..75e32c717c3a82ff48c8797f4b59bad65db6b868 100644 (file)
@@ -36,10 +36,21 @@ static unsigned int playfield_cursor_delay = 0;
    delay problems with lots of mouse motion events when mouse button
    not pressed (X11 can handle this with 'PointerMotionHintMask') */
 
-int FilterMouseMotionEvents(const Event *event)
+/* event filter addition for SDL2: as SDL2 does not have a function to enable
+   or disable keyboard auto-repeat, filter repeated keyboard events instead */
+
+static int FilterEventsExt(const Event *event)
 {
   MotionEvent *motion;
 
+#if defined(TARGET_SDL2)
+  /* skip repeated key press events if keyboard auto-repeat is disabled */
+  if (event->type == EVENT_KEYPRESS &&
+      event->key.repeat &&
+      !keyrepeat_status)
+    return 0;
+#endif
+
   /* non-motion events are directly passed to event handler functions */
   if (event->type != EVENT_MOTIONNOTIFY)
     return 1;
@@ -59,10 +70,22 @@ int FilterMouseMotionEvents(const Event *event)
   if (button_status == MB_RELEASED &&
       game_status != GAME_MODE_EDITOR && game_status != GAME_MODE_PLAYING)
     return 0;
-  else
-    return 1;
+
+  return 1;
 }
 
+#if defined(TARGET_SDL2)
+int FilterEvents(void *userdata, Event *event)
+{
+  return FilterEventsExt(event);
+}
+#else
+int FilterEvents(const Event *event)
+{
+  return FilterEventsExt(event);
+}
+#endif
+
 /* to prevent delay problems, skip mouse motion events if the very next
    event is also a mouse motion event (and therefore effectively only
    handling the last of a row of mouse motion events in the event queue) */
@@ -104,7 +127,7 @@ static boolean NextValidEvent(Event *event)
 
     NextEvent(event);
 
-    if (FilterMouseMotionEvents(event))
+    if (FilterEventsExt(event))
       handle_this_event = TRUE;
 
     if (SkipPressedMouseMotionEvent(event))
@@ -318,7 +341,7 @@ void SleepWhileUnmapped()
 
 void HandleExposeEvent(ExposeEvent *event)
 {
-#ifndef TARGET_SDL
+#if !defined(TARGET_SDL)
   RedrawPlayfield(FALSE, event->x, event->y, event->width, event->height);
   FlushDisplay();
 #endif