]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/joystick.cpp
non-PCH build fix (according to Tinderbox).
[wxWidgets.git] / src / unix / joystick.cpp
index a9c434cbc15e3616a1a31cc76131ee03954dabd9..64afa78cb989e8286f7a8fec2b91cb99e1e378e9 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        joystick.cpp
+// Name:        src/unix/joystick.cpp
 // Purpose:     wxJoystick class
 // Author:      Ported to Linux by Guilhem Lavaux
 // Modified by:
 // Purpose:     wxJoystick class
 // Author:      Ported to Linux by Guilhem Lavaux
 // Modified by:
@@ -9,19 +9,18 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "joystick.h"
-#endif
-
 // for compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 // for compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
-#include "wx/defs.h"
-
 #if wxUSE_JOYSTICK
 
 #include "wx/joystick.h"
 
 #if wxUSE_JOYSTICK
 
 #include "wx/joystick.h"
 
+#ifndef WX_PRECOMP
+    #include "wx/event.h"
+    #include "wx/window.h"
+#endif //WX_PRECOMP
+
 #include <linux/joystick.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <linux/joystick.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
 
 #include <fcntl.h>
 #include <unistd.h>
 
-#include "wx/event.h"
-#include "wx/window.h"
+#ifdef HAVE_SYS_SELECT_H
+#   include <sys/select.h>
+#endif
+
+#include "wx/unix/private.h"
 
 enum {
     wxJS_AXIS_X = 0,
 
 enum {
     wxJS_AXIS_X = 0,
@@ -91,7 +93,7 @@ void* wxJoystickThread::Entry()
     fd_set read_fds;
     struct timeval time_out = {0, 0};
 
     fd_set read_fds;
     struct timeval time_out = {0, 0};
 
-    FD_ZERO(&read_fds);
+    wxFD_ZERO(&read_fds);
     while (true)
     {
         if (TestDestroy())
     while (true)
     {
         if (TestDestroy())
@@ -104,9 +106,9 @@ void* wxJoystickThread::Entry()
         else
             time_out.tv_usec = 10 * 1000; // check at least every 10 msec in blocking case
 
         else
             time_out.tv_usec = 10 * 1000; // check at least every 10 msec in blocking case
 
-        FD_SET(m_device, &read_fds);
+        wxFD_SET(m_device, &read_fds);
         select(m_device+1, &read_fds, NULL, NULL, &time_out);
         select(m_device+1, &read_fds, NULL, NULL, &time_out);
-        if (FD_ISSET(m_device, &read_fds))
+        if (wxFD_ISSET(m_device, &read_fds))
         {
             memset(&j_evt, 0, sizeof(j_evt));
             read(m_device, &j_evt, sizeof(j_evt));
         {
             memset(&j_evt, 0, sizeof(j_evt));
             read(m_device, &j_evt, sizeof(j_evt));
@@ -184,14 +186,14 @@ wxJoystick::wxJoystick(int joystick)
     wxString dev_name;
 
      // old /dev structure
     wxString dev_name;
 
      // old /dev structure
-    dev_name.Printf( wxT("/dev/js%d"), (joystick == wxJOYSTICK1) ? 0 : 1);
+    dev_name.Printf( wxT("/dev/js%d"), joystick);
     m_device = open(dev_name.fn_str(), O_RDONLY);
 
     // new /dev structure with "input" subdirectory
     if (m_device == -1)
     {
     m_device = open(dev_name.fn_str(), O_RDONLY);
 
     // new /dev structure with "input" subdirectory
     if (m_device == -1)
     {
-        dev_name.Printf( wxT("/dev/input/js%d"), (joystick == wxJOYSTICK1) ? 0 : 1);
-        m_device = open(dev_name.fn_str(), O_RDONLY);             
+        dev_name.Printf( wxT("/dev/input/js%d"), joystick);
+        m_device = open(dev_name.fn_str(), O_RDONLY);
     }
 
     if (m_device != -1)
     }
 
     if (m_device != -1)
@@ -286,7 +288,7 @@ bool wxJoystick::IsOk() const
     return (m_device != -1);
 }
 
     return (m_device != -1);
 }
 
-int wxJoystick::GetNumberJoysticks() const
+int wxJoystick::GetNumberJoysticks()
 {
     wxString dev_name;
     int fd, j;
 {
     wxString dev_name;
     int fd, j;
@@ -295,9 +297,20 @@ int wxJoystick::GetNumberJoysticks() const
         dev_name.Printf(wxT("/dev/js%d"), j);
         fd = open(dev_name.fn_str(), O_RDONLY);
         if (fd == -1)
         dev_name.Printf(wxT("/dev/js%d"), j);
         fd = open(dev_name.fn_str(), O_RDONLY);
         if (fd == -1)
-            return j;
+            break;
         close(fd);
     }
         close(fd);
     }
+
+    if (j == 0) {
+        for (j=0; j<4; j++) {
+            dev_name.Printf(wxT("/dev/input/js%d"), j);
+            fd = open(dev_name.fn_str(), O_RDONLY);
+            if (fd == -1)
+                return j;
+            close(fd);
+        }
+    }
+
     return j;
 }
 
     return j;
 }
 
@@ -481,4 +494,3 @@ bool wxJoystick::ReleaseCapture()
     return false;
 }
 #endif  // wxUSE_JOYSTICK
     return false;
 }
 #endif  // wxUSE_JOYSTICK
-