From 6da26c8d6c868e0864d2173cf46f32ce6238f1e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Camilla=20L=C3=B6wy?= <elmindreda@glfw.org>
Date: Thu, 15 Jun 2017 17:40:57 +0200
Subject: [PATCH] Linux: Ignore partial state after SYN_DROPPED

Related to #1005.
---
 src/linux_joystick.c | 16 ++++++++++++++--
 src/linux_joystick.h |  1 +
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/linux_joystick.c b/src/linux_joystick.c
index 360e7a28..156e425c 100644
--- a/src/linux_joystick.c
+++ b/src/linux_joystick.c
@@ -399,12 +399,24 @@ int _glfwPlatformPollJoystick(int jid, int mode)
             break;
         }
 
+        if (e.type == EV_SYN)
+        {
+            if (e.code == SYN_DROPPED)
+                _glfw.linjs.dropped = GLFW_TRUE;
+            else if (e.code == SYN_REPORT)
+            {
+                _glfw.linjs.dropped = GLFW_FALSE;
+                pollAbsState(js);
+            }
+        }
+
+        if (_glfw.linjs.dropped)
+            continue;
+
         if (e.type == EV_KEY)
             handleKeyEvent(js, e.code, e.value);
         else if (e.type == EV_ABS)
             handleAbsEvent(js, e.code, e.value);
-        else if (e.type == EV_SYN && e.code == SYN_DROPPED)
-            pollAbsState(js);
     }
 
     return js->present;
diff --git a/src/linux_joystick.h b/src/linux_joystick.h
index c364cf76..227a6ed9 100644
--- a/src/linux_joystick.h
+++ b/src/linux_joystick.h
@@ -50,6 +50,7 @@ typedef struct _GLFWlibraryLinux
     int                     inotify;
     int                     watch;
     regex_t                 regex;
+    GLFWbool                dropped;
 } _GLFWlibraryLinux;