OSX: fix missing axes in wxJoystick (PR #26216)

0 views
Skip to first unread message

Hydra

unread,
7:14 PM (3 hours ago) 7:14 PM
to wx-...@googlegroups.com, Subscribed

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.


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/26216

Commit Summary

  • d3d1dac OSX: fix missing axes in wxJoystick

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26216@github.com>

VZ

unread,
7:25 PM (3 hours ago) 7:25 PM
to wx-...@googlegroups.com, Subscribed

@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.Message ID: <wxWidgets/wxWidgets/pull/26216/review/3834702210@github.com>

Hydra

unread,
7:55 PM (3 hours ago) 7:55 PM
to wx-...@googlegroups.com, Push

@Hydr8gon pushed 1 commit.

  • 2bcb12b OSX: fix missing axes in wxJoystick


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26216/before/d3d1dac538857314a225b7f2e4210384429bb271/after/2bcb12b601fea5c4ac83d90a4407ee0797118b54@github.com>

Reply all
Reply to author
Forward
0 new messages