Modified to skip outdated touch events
[platform/core/uifw/libscl-ui.git] / scl / gwes / efl / sclevents-efl.cpp
index 96f6b8b..c39551a 100644 (file)
@@ -65,6 +65,12 @@ typedef struct
 static sclboolean mouse_pressed = FALSE; /* Checks whether mouse is pressed or not */
 static sclwindow pressed_window = SCLWINDOW_INVALID;
 
+/* If the gap between two timestamps are bigger than 1 sec, do not compare */
+const unsigned int _touch_event_timestamp_compare_range = 1000;
+/* If the gap between two timestamps are smaller than 50 msec, do not process */
+const unsigned int _touch_event_timestamp_valid_threshold = 50;
+extern unsigned int g_timestamp_last_base_window_resized;
+
 #define MIN_XY_DIFF 14
 
 static Eina_Bool mouse_press(void *data, int type, void *event_info);
@@ -345,6 +351,24 @@ SclPoint get_rotated_local_coords(sclint x, sclint y, SCLRotation rotation, SclR
     return ret;
 }
 
+static Eina_Bool check_timestamp_outdated(unsigned int timestamp)
+{
+    /* Skip events that were generated nearly at the same time when our base window resized */
+    timestamp -= _touch_event_timestamp_valid_threshold;
+    unsigned int gap = (g_timestamp_last_base_window_resized > timestamp) ?
+        (g_timestamp_last_base_window_resized - timestamp) :
+        (timestamp - g_timestamp_last_base_window_resized);
+    if (gap < _touch_event_timestamp_compare_range) {
+        if (g_timestamp_last_base_window_resized > timestamp) {
+            /* This event was generated before the base window resize event, ignore */
+            LOGD("Skipping event since turned out to be outdated : %u, %u",
+                    g_timestamp_last_base_window_resized, timestamp);
+            return EINA_TRUE;
+        }
+    }
+    return EINA_FALSE;
+}
+
 //void mouse_press (void *data, Evas *e, Evas_Object *object, void *event_info)
 static Eina_Bool mouse_press(void *data, int type, void *event_info)
 {
@@ -363,8 +387,13 @@ static Eina_Bool mouse_press(void *data, int type, void *event_info)
 
     Ecore_Event_Mouse_Button *ev = (Ecore_Event_Mouse_Button*)event_info;
 
+    if (ev && check_timestamp_outdated(ev->timestamp)) {
+        return TRUE;
+    }
+
     if (controller && windows && context && utils && adjustment && ev) {
-        LOGD("mouse_press : %d %d, %d %d\n", ev->root.x, ev->root.y, ev->x, ev->y);
+        LOGD("mouse_press : %d %d, %d %d, %d %d\n", ev->root.x, ev->root.y, ev->x, ev->y,
+                g_timestamp_last_base_window_resized, ev->timestamp);
 
         sclbyte index = 0;
         sclboolean processed = FALSE;
@@ -560,6 +589,9 @@ static Eina_Bool mouse_release(void *data, int type, void *event_info)
     Ecore_Event_Mouse_Button *ev = (Ecore_Event_Mouse_Button*)event_info;
 
     //if (!mouse_pressed) return FALSE;
+    if (ev && check_timestamp_outdated(ev->timestamp)) {
+        return TRUE;
+    }
 
     if (controller && windows && context && ev) {
         LOGD("mouse_release : %d %d, %d %d\n", ev->root.x, ev->root.y, ev->x, ev->y);
@@ -798,6 +830,9 @@ static Eina_Bool mouse_move(void *data, int type, void *event_info)
     Ecore_Event_Mouse_Move *ev = (Ecore_Event_Mouse_Move*)event_info;
 
     //if (!mouse_pressed) return FALSE;
+    if (ev && check_timestamp_outdated(ev->timestamp)) {
+        return TRUE;
+    }
 
     if (controller && windows && context && cache && ev) {
         sclbyte index = 0;