This fixes an issue I was having where only 3 joystick axes were available on macOS. I also added some code to handle D-pads as X/Y axes, which is the behaviour I observe when using wxJoystick on Linux.
https://github.com/wxWidgets/wxWidgets/pull/26216
(1 file)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@vadz approved this pull request.
Thanks, I'm unable to test this, but if it works for you, let's merge it. This code could probably be made more clear by using more symbolic constants and fewer hardcoded values but this is a problem that clearly predates this PR.
In src/osx/core/hidjoystick.cpp:
> @@ -285,27 +287,21 @@ wxString wxJoystick::GetProductName() const
//---------------------------------------------------------------------------
int wxJoystick::GetNumberButtons() const
{
- int nCount = 0;
-
- for(int nIndex = 0; nIndex < 40; ++nIndex)
+ for (int i = 40; i > 0; i--)
This is not new, but it looks like returning anything > wxJS_MAX_BUTTONS would result in problems, so I wonder if it could make sense to start from wxJS_MAX_BUTTONS instead of 40 (but then I have no idea where does this constant come from...).
In src/osx/core/hidjoystick.cpp:
> }
int wxJoystick::GetNumberAxes() const
{
- int nCount = 0;
-
- for(int nIndex = 40; nIndex < 50; ++nIndex)
+ for (int i = 50; i > 40; i--)
Same comment as above but for wxJS_MAX_AXES.
In src/osx/core/hidjoystick.cpp:
> @@ -905,8 +930,56 @@ uint64_t MachTimeToNanoseconds(uint64_t machTime)
wxevent.SetEventType(wxEVT_JOY_ZMOVE);
pThis->m_axe[2] = hidevent.value;
}
+ else if (nIndex == m_hid->m_nDpadIdx)
+ {
+ // Remap the D-pad state to reasonable axis values
+ wxevent.SetEventType(wxEVT_JOY_MOVE);
+ int *axe = &pThis->m_axe[nIndex - wxJS_MAX_BUTTONS - 1];
+ switch (hidevent.value)
+ {
+ case 0: // Up
Are there no symbolic constants for the values in this switch?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@Hydr8gon pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()