fix for wxJoystick when not calling SetCapture() (patch 1000685)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29164 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2004-09-16 22:10:34 +00:00
parent 837adaa922
commit 627b2b2a0d

View File

@@ -6,7 +6,7 @@
// Created: 05/23/98 // Created: 05/23/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Guilhem Lavaux // Copyright: (c) Guilhem Lavaux
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
@@ -63,10 +63,10 @@ private:
int m_device; int m_device;
int m_joystick; int m_joystick;
wxPoint m_lastposition; wxPoint m_lastposition;
int m_axe[15]; int m_axe[15];
int m_buttons; int m_buttons;
wxWindow* m_catchwin; wxWindow* m_catchwin;
int m_polling; int m_polling;
friend class wxJoystick; friend class wxJoystick;
}; };
@@ -92,7 +92,8 @@ void* wxJoystickThread::Entry()
struct timeval time_out = {0, 0}; struct timeval time_out = {0, 0};
FD_ZERO(&read_fds); FD_ZERO(&read_fds);
while (true) { while (true)
{
if (TestDestroy()) if (TestDestroy())
break; break;
@@ -113,15 +114,14 @@ void* wxJoystickThread::Entry()
//printf("time: %d\t value: %d\t type: %d\t number: %d\n", //printf("time: %d\t value: %d\t type: %d\t number: %d\n",
// j_evt.time, j_evt.value, j_evt.type, j_evt.number); // j_evt.time, j_evt.value, j_evt.type, j_evt.number);
if (m_catchwin) wxJoystickEvent jwx_event;
if (j_evt.type & JS_EVENT_AXIS)
{ {
wxJoystickEvent jwx_event; m_axe[j_evt.number] = j_evt.value;
if ((j_evt.type & JS_EVENT_AXIS) == JS_EVENT_AXIS) { switch (j_evt.number)
{
m_axe[j_evt.number] = j_evt.value;
switch (j_evt.number) {
case wxJS_AXIS_X: case wxJS_AXIS_X:
m_lastposition.x = j_evt.value; m_lastposition.x = j_evt.value;
jwx_event.SetEventType(wxEVT_JOY_MOVE); jwx_event.SetEventType(wxEVT_JOY_MOVE);
@@ -138,23 +138,23 @@ void* wxJoystickThread::Entry()
// TODO: There should be a way to indicate that the event // TODO: There should be a way to indicate that the event
// is for some other axes. // is for some other axes.
break; break;
} }
}
if (j_evt.type & JS_EVENT_BUTTON)
{
if (j_evt.value)
{
m_buttons |= (1 << j_evt.number);
jwx_event.SetEventType(wxEVT_JOY_BUTTON_DOWN);
}
else
{
m_buttons &= ~(1 << j_evt.number);
jwx_event.SetEventType(wxEVT_JOY_BUTTON_UP);
} }
if ((j_evt.type & JS_EVENT_BUTTON) == JS_EVENT_BUTTON) { jwx_event.SetButtonChange(j_evt.number);
if (j_evt.value)
{
m_buttons |= (1 << j_evt.number);
jwx_event.SetEventType(wxEVT_JOY_BUTTON_DOWN);
}
else
{
m_buttons &= ~(1 << j_evt.number);
jwx_event.SetEventType(wxEVT_JOY_BUTTON_UP);
}
jwx_event.SetButtonChange(j_evt.number);
}
jwx_event.SetTimestamp(j_evt.time); jwx_event.SetTimestamp(j_evt.time);
jwx_event.SetJoystick(m_joystick); jwx_event.SetJoystick(m_joystick);
@@ -163,12 +163,9 @@ void* wxJoystickThread::Entry()
jwx_event.SetZPosition(m_axe[3]); jwx_event.SetZPosition(m_axe[3]);
jwx_event.SetEventObject(m_catchwin); jwx_event.SetEventObject(m_catchwin);
if (m_catchwin)
m_catchwin->AddPendingEvent(jwx_event); m_catchwin->AddPendingEvent(jwx_event);
} }
// if (m_polling)
// wxThread::Sleep(m_polling);
} }
} }
@@ -186,7 +183,7 @@ wxJoystick::wxJoystick(int joystick)
{ {
wxString dev_name; wxString dev_name;
// Assume it's the same device name on all Linux systems ... // Assume it's the same device name on all Linux systems ...
dev_name.Printf( wxT("/dev/js%d"), (joystick == wxJOYSTICK1) ? 0 : 1); dev_name.Printf( wxT("/dev/js%d"), (joystick == wxJOYSTICK1) ? 0 : 1);
m_device = open(dev_name.fn_str(), O_RDONLY); m_device = open(dev_name.fn_str(), O_RDONLY);