-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix controller vibration in macOS and migrate to GameController API #80709
Fix controller vibration in macOS and migrate to GameController API #80709
Conversation
Oh, some of this stuff is only available for macOS 10.15+. So, this wouldn't work as Godot supports macOS 10.13+... I'll have to rethink this. |
Can the macOS 10.15+ stuff be made optional? I don't think vibration support (or even controller support) is essential on very old macOS versions. macOS 10.15 is 4 years old at this point. |
I will see if the macOS 10.15+ stuff can be made optional, I'm not sure though. |
Controller support is available in macOS 10.9+, and Haptics in macOS 11+. So, vibrations are the only optional stuff for macOS 11+. |
What I did for SDL2 was, on the IOKit side:
On the GameController side, I made it so that if the OS isn't 11 or higher, the init would just fail (thus making SDL no longer try to use the GameController calls). The reason for checking for macOS 11 is because it added the Yes, the GameController stuff can be made optional: You can weak-link frameworks and libraries so the program won't crash at launch if it's missing frameworks or libraries (It will, however, crash if you call the weak-linked functions). |
I wanted to try this 'PR'. (XBox Controller on macOS) Unfortunately compiling was not possible. My Does this error mean that a 'rebase' would be necessary later? thirdparty/zlib/zconf.h:450:1: error: import of C++ module 'Darwin.POSIX.sys.types' appears within extern "C" language linkage specification [-Wmodule-import-in-extern-c]
# include <sys/types.h> /* for off_t */
^
./thirdparty/minizip/unzip.h:47:1: note: extern "C" language linkage specification begins here
extern "C" {
^ https://hardwaretester.com/gamepad i was first going to suggest taking some sources from the chromium project, then found this 'PR'. |
That looks like an error in Apple's new C module parser. Try disabling modules in Xcode. |
I use VSCode with scons I have tested an example for GameController API, XBox controller has vibrated 👍 |
On my MacM1, master branch also has problems with: There is a configuration for 'clang' to disable this error: clang-docs -->
On 'stackoverflow' some say switch to 'XCode 14' for similar linker error. clang -v
/usr/bin/xcodebuild -version
|
That's Xcode 15 new linker error (seems to be related to Relevant buildsystem fix: godot/platform/macos/detect.py Lines 129 to 130 in 6916349
|
@bruvzg thx, 'joypads' demo starts now. Vibration is executed. It detects 1 button less (menu button), I'll try to check it in more detail in the next days. Update: |
b7c9860
to
58122c2
Compare
Rebased with master branch. |
I would have to debug the 2 buttons first.
|
I found that my old Xbox 360 controller is recognized under Google Chrome, without macOS driver! If this 'PR' / 'GameController API' is done, then maybe later I'll check the Chrome sources (effort and compatibility) https://hardwaretester.com/gamepad (Copyright 2013-2023) Statistics from the last 10 years maybe, XBox 360 is still No.1 there by far |
float value = gamepad.rightTrigger.value; | ||
Input::get_singleton()->joy_axis(joy_id, JoyAxis::TRIGGER_RIGHT, value); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created macos_xbox-branch on my account
These are all extensions: 70bb7a3
Note: leftThumbstickButton
and rightThumbstickButton
require macOS 10.14.1+
The two if-queries above would have to be removed again.
Tests XBox buttonShare linked with Screen-2023-10-09-184918.mp4 |
We discussed this in the PR-review meeting. It would need testing and could be considered for 4.3. |
#88590 - a bunch of extra stuff for the future (touchpad + gyroscope support). |
Suggestions committed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style and docs look good, save for one grammar detail I missed!
Please squash your commits into one, see here
e9906f4
to
ae77fa3
Compare
Squashed commits~ |
Needs a rebase to fix CI |
ae77fa3
to
24625b4
Compare
Must be something else in this PR that triggers this then, as it doesn't occur without it |
The error looks like something related to the #87999, no idea why it's triggering now. Really strange. |
Might be triggered by |
This comment was marked as outdated.
This comment was marked as outdated.
Or do the same trick as Display Server do and redefine conflicting diff --git a/platform/macos/SCsub b/platform/macos/SCsub
index ab6ca236ce..355772fcd2 100644
--- a/platform/macos/SCsub
+++ b/platform/macos/SCsub
@@ -121,8 +121,6 @@ files = [
"gl_manager_macos_legacy.mm",
]
-env.Append(CCFLAGS=["-fmodules", "-fcxx-modules", "-Wno-module-import-in-extern-c"])
-
prog = env.add_program("#bin/godot", files)
if env["debug_symbols"] and env["separate_debug_symbols"]:
diff --git a/platform/macos/joypad_macos.h b/platform/macos/joypad_macos.h
index 01949a8f37..e27f51b890 100644
--- a/platform/macos/joypad_macos.h
+++ b/platform/macos/joypad_macos.h
@@ -29,8 +29,10 @@
/**************************************************************************/
#include "core/input/input.h"
+#define Key _QKey
#import <CoreHaptics/CoreHaptics.h>
#import <GameController/GameController.h>
+#undef Key
@interface JoypadMacOSObserver : NSObject
|
This should fix a lot of issues regarding to old controller API, such as vibration Haptics (vibrations) are only available in macOS 11+, so haptics are now processed in macOS 11+ only. Also, this doesn't interfere with controller's input as controller support is available in macOS 10.9+. Added a Note for macOS regarding vibration support
24625b4
to
07313a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in case, re-tested it another time, everything seems to be ok.
Thanks! And congrats for your first merged Godot contribution 🎉 |
This PR fixed my ongoing xbox controller problems(wrong button mapping, some buttons not detected at al). But now my Nvidia shield controller inputs are no longer detected at all in 4.3 dev4. They are detected in 4.2.1 stable. |
@nikoladigi Could you open a new issue so we can properly track the regression? |
Is there any intention of backporting this to Godot 3.x? |
Relates to #14634
This PR migrates the ForceFeedback implementation in favor of GameController and CoreHaptics frameworks, in order to add/fix controller vibration in macOS.
The GameController implementation was essentially copied/pasted from the iOS one.