raylib: [rcore] Gamepad not working on macOS

Please, before submitting a new issue verify and check:

  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • I checked the documentation on the wiki
  • My code has no errors or misuse of raylib

Issue description

Gamepad input not working. I tried 2 different controllers.

  • Xbox One Series X connected via USB
    • IsGamepadAvailable(0) returns false.
  • Nintendo Switch Pro Controller connected via USB
    • IsGamepadAvailable(0) returns true.
    • No button input is ever detected

Environment

MacOSX Ventura on an M2 Mac.

Issue Screenshot

Can’t really show this.

Code Example

#include "raylib.h"
#include <stdio.h>

int main(void)
{
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "Gamepads Broken");

    SetTargetFPS(60);               

    while (!WindowShouldClose()) 
    {
        BeginDrawing();

            ClearBackground(RAYWHITE);

            if(IsGamepadAvailable(0)) {
                DrawText("FOUND GAMEPAD TEST", 190, 275, 20, PURPLE);
                
                if(IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN)) {
                    DrawText("BUTTON PRESSED", 190, 350, 20, PURPLE);
                }
            }

        EndDrawing();
    }
    CloseWindow();        

    return 0;
}

Provide minimal reproduction code to test the issue. Please, format the code properly and try to keep it as simple as possible, just focusing on the experienced issue.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 44 (13 by maintainers)

Most upvoted comments

I think this issue should be closed (unless we want to track it here). This is a GLFW problem. In order to make it work in Raylib, it should be fixed in GLFW first.

I think we maybe should keep it open to make it easier to track the progress upstream? Technically this issue is about all gamepads, so if the Switch Pro Controller is still not working, the issue is not yet resolved. Additionally, other people who might have problems with gamepads will find this (open) issue, instead of making a new one.

Edit: Added Pro Controller (Switch) test. Edit 2: With the changes made by @sleeptightAnsiC on #5036 , the Xbox Wireless Controller now works.

I can confirm the issue. At least for me, the only controller that works on macOS is the PS4 one.

I’m on Sequoia (15.4.1), using the offical gamepad example.

I tested:

  • DUALSHOCK 4 Wireless Controller
  • Xbox Wireless Controller
  • Pro Controller (Switch)

Web

DUALSHOCK 4 Wireless Controller

Image

  • ✅ Detects gamepad.
  • ✅ Registers buttons.
  • ✅ Registers axis (?) (the joystick moves, but the numbers don’t change).

Xbox Wireless Controller

Image

  • ✅ Detects gamepad.
  • ✅ Registers buttons.
  • ✅ Registers axis.

Pro Controller (Switch)

Image

  • ✅ Detects gamepad.
  • ✅ Register buttons.
  • ✅ Register axis.

macOS using raylib 5.5 (GLFW backend)

DUALSHOCK 4 Wireless Controller

Image

  • ✅ Detects gamepad.
  • ✅ Registers buttons.
  • ✅ Registers axis.

Xbox Wireless Controller

Image

  • ✅ Detects gamepad.
  • ✅ Registers buttons.
  • ✅ Registers axis.

Pro Controller (Switch)

Image

  • ✅ Detects gamepad.
  • ❌ Doesn’t register buttons.
  • ❌ Doesn’t register axis.

@darzaccaro thanks for the update, reopening

This issue is not fixed.

Gamepads, while detected, do not update their inputs on MacOS for PLATFORM_DESKTOP with the GLFW backend. They work fine with the SDL backend or PLATFORM_WEB.

Tested all of these today on an M1 mac running Sequoia 15.3.2 with an “Xbox Series X Controller”.

Can we re-open this, or should I start a new issue?

Well, the problem still exist and gamepads still not work under MacOS with Raylib.

WARNING: Some comments on this issue thread seem to be removed by the user or by user-removal. It could be confusing to follow the conversation if there are references to deleted comments.

Thanks @sleeptightAnsiC ! Now the Xbox Controller is working 🎉 Sadly, the Switch Pro Controller is still not recognised. But it’s something 😃

Can anyone here retest this issue with PR https://github.com/raysan5/raylib/pull/5036 ?

GLFW’s mappings are quite outdated in the current Raylib master branch. I also had a problem with the XSX|S Controller, and updating those mappings helped in my case (see https://github.com/raysan5/raylib/issues/5027#issuecomment-3054561168).

CC @hiulit @MikeshCZ @darzaccaro

@asdqwe I’ve tested under MacOS with pass results. Buttons are showed correctly in terminal.

time: 10.646164
joy1: 1
name: "Xbox Wireless Controller"
guid: "030000005e040000130b000015050000"
btns: 6 7

I have the same issue on Linux with my working Xbox Wireless Controllers - key presses are never registered despite successful discovery. No matter what I do, I won’t move. Compiling raylib with PLATFORM=PLATFORM_DESKTOP_SDL is the only thing that works.

I did notice a few things that might help narrowing down the problem. Or they might not.

For the mentioned controller (Bluetooth paired), my kernel reports the following:

$ cat /sys/devices/virtual/misc/uhid/0005\:045E\:02FD.001C/input/input52/name
Microsoft Corporation Gamepad
cat /sys/devices/virtual/misc/uhid/0005:045E:02FD.001C/input/input52/id/{bustype,vendor,product,version}
0005
045e
02fd
0903
$

Based on which I would expect the following entry is correct:

$ grep 050000005e040000fd02000003090000 src/raylib-5.5/src/external/glfw/src/mappings.h
"050000005e040000fd02000003090000,Xbox One Wireless Controller,a:b0,b:b1,back:b15,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b16,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Linux,",
$

However, running @konsumer 's sdl2-joystick.c reports the following:

$ ./sdl2-joystick
0300d6f25e040000fd02000000006800 "Xbox One S Controller" axes:6 buttons:15 hats:0 balls:0

Using steam as suggested by SDL_GameControllerDB returns the following:

0500d6f25e040000fd02000000006800,Xbox One S Controller,crc:f2d6,platform:Linux,a:b0,b:b1,x:b2,y:b3,dpleft:h0.8,dpright:h0.2,dpup:h0.1,dpdown:h0.4,leftx:a0,lefty:a1,leftstick:b7,rightx:a2,righty:a3,rightstick:b8,leftshoulder:b9,lefttrigger:a4,rightshoulder:b10,righttrigger:a5,back:b4,start:b6,guide:b5,steam:2,

If there’s anything I can help with, let me know. I can test/code/build on linux, macos and windows operating systems, with three Xbox Controllers each having a different firmware.

@konsumer This is returned value from your code:

0300c6515e040000130b000015056800 "Xbox Series X Controller" axes:6 buttons:16 hats:0 balls:0

Based on name/platform I narrowed the map lines down to these:

  const char* mappings = "030000007e0500000920000000000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Mac OS X,\
030000007e0500000920000001000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Mac OS X,\
030000007e0500000920000010020000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,platform:Mac OS X,\
050000007e05000009200000ff070000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,platform:Mac OS X,";
  
  int mapstatus = SetGamepadMappings(mappings);
  TraceLog(LOG_INFO, "mapping: %d", mapstatus);

I get same issue, with mapping: 1 output.

It still shows “Pro Controller” so mapping might not be working right.

I also tried adding same lines to mappings.h in glfw, with same results (wrong name, etc.)

Running a tester program, I got this from SDL2:

0300d71f7e0500000920000001006803 "Nintendo Switch Pro Controller" axes:6 buttons:20 hats:0 balls:0

Searching through the existing mapping these are already in there, and have “correct” name:

030000007e0500000920000000000000
030000007e0500000920000001000000

and these were not in there:

030000007e0500000920000010020000
050000007e05000009200000ff070000

Nothing seems to pick up these mappings, though. Like I also added this:

  const char* mappings = "0300d71f7e0500000920000001006803,DK Switch Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,platform:Mac OS X,";
  int mapstatus = SetGamepadMappings(mappings);
  TraceLog(LOG_INFO, "JS: mapping: %d", mapstatus);

and for both SDL & GLFW, it uses names that are not “DK Switch Controller”

Reopening for further review.

Would it be possible for you to test it with PLATFORM_DESKTOP_SDL (SDL2 preferably)?

Yep, I can setup a raylib tester with PLATFORM_DESKTOP_SDL with SDL2, and a no-raylib SDL2 tester.

Also, looked the doc to see if there were some sort of “keep alive” call, but found nothing.

Yeh, and this all works in Linux, too, so I think it’s some mac-specific bug. It may just be that joystick, or Mac’s handling of switch controllers, I am not sure.

I have a similar issue with plain C, on mac M1 (Sonoma.) On web, it works fine, but with this code, I only get the name, but no button-events, on native raylib 5.5:

#include "raylib.h"

int main(void) {
  InitWindow(320, 240, "gamepad test");
  SetTargetFPS(60);

  while (!WindowShouldClose()) {
    BeginDrawing();
    ClearBackground(RAYWHITE);

    char* gpText = "No gampepad";
    
    for (int gamepad=0; gamepad < 5; gamepad++) {
      if (IsGamepadAvailable(gamepad)) {
        gpText = TextFormat("GP%d: %s", gamepad, GetGamepadName(gamepad));
        for (int gamepadButton = GAMEPAD_BUTTON_UNKNOWN; gamepadButton <= GAMEPAD_BUTTON_RIGHT_THUMB; gamepadButton++) {
          if (IsGamepadButtonDown(gamepad, gamepadButton)) {
            DrawCircle((gamepadButton*17) + 9, 120, 8, RED);
          } else {
            DrawCircle((gamepadButton*17) + 9, 120, 8, GRAY);          }
        }
      }
    }

    DrawText(gpText, 10, 10, 10, BLACK);
    
    EndDrawing();
  }

  CloseWindow();
  return 0;
}

I tested with 2 controllers:

official PS5 controller, paired over bluetooth

Screenshot 2024-12-10 at 2 41 33 PM

PXN-P50S, connected over bluetooth, as “Pro Controller”

Screenshot 2024-12-10 at 2 15 12 PM

I am happy to test anything you like. I have 2 macs for testing (intel and M1.)

Update, after re-pairing a couple times, I got the PS5 controller to work, but not the PXN-P50S:

Screenshot 2024-12-10 at 2 58 39 PM

Update

I made a similar tester in GLFW (3.4) and got similar results.

#include <GLFW/glfw3.h>
#include <stdio.h>

#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif

void joystick_connect_callback(int jid, int event) {
  if (event == GLFW_CONNECTED) {
    printf("connected: %d: %s\n", jid, glfwGetJoystickName(jid));
  } else if (event == GLFW_DISCONNECTED){
    printf("disconnected: %d: %s\n", jid, glfwGetJoystickName(jid));
  }
}

GLFWwindow *window = NULL;

void mainLoop() {
  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  glClear(GL_COLOR_BUFFER_BIT);
  glfwSwapBuffers(window);
  glfwPollEvents();

  for (int jid = GLFW_JOYSTICK_1; jid<GLFW_JOYSTICK_4;jid++) {
    if (glfwJoystickPresent(jid)) {
      int count = 0;
      const unsigned char* buttons = glfwGetJoystickButtons(jid, &count);
      for (int b=0;b<count;b++) {
        if (buttons[b]) {
          printf("%d %u: DOWN\n", jid, b);
        } else {
          printf("%d %u: UP\n", jid, b);
        }
      }
    }
  }
}

int main() {
  if (!glfwInit()) {
    return 1;
  }

  window = glfwCreateWindow(320, 240, "gamepad tester", NULL, NULL);
  if (!window) {
    glfwTerminate();
    return 1;
  }

  glfwMakeContextCurrent(window);
  glfwSetJoystickCallback(joystick_connect_callback);

  for (int jid = GLFW_JOYSTICK_1; jid<GLFW_JOYSTICK_4;jid++) {
    if (glfwJoystickPresent(jid)) {
      printf("present: %d: %s\n", jid, glfwGetJoystickName(jid));
    }
  }


#ifdef EMSCRIPTEN
  emscripten_set_main_loop(&mainLoop, 0, 1);
#else
  while (!glfwWindowShouldClose(window)) {
    mainLoop();
  }
#endif

  glfwDestroyWindow(window);
  glfwTerminate();

  return 0;
}

Both were seen initially, but only PS5 updated it’s buttons. Like, I saw this, with some buttons pressed on both:

present: 0: Pro Controller
present: 1: DualSense Wireless Controller
0 0: UP
0 1: UP
0 2: UP
0 3: UP
0 4: UP
0 5: UP
0 6: UP
0 7: UP
0 8: UP
0 9: UP
0 10: UP
0 11: UP
0 12: UP
0 13: UP
0 14: UP
0 15: UP
0 16: UP
0 17: UP
0 18: UP
0 19: UP

1 0: DOWN
1 1: UP
1 2: UP
1 3: DOWN
1 4: UP
1 5: UP
1 6: UP
1 7: UP
1 8: UP
1 9: UP
1 10: UP
1 11: UP
1 12: UP
1 13: UP
1 14: UP
1 15: UP
1 16: UP
1 17: UP

@SoloByte Your Raylib-cs example works fine on Linux.

I also cannot find any platform specific macos code in raylib. Maybe a newer version of GFLW will fix this.