SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit fcf31be7357ba15acc21417817d09e7c8d737173 parent d8905f57bf8c21bb6b062dc18c793eca29d61d51 Author: Lior Halphon <LIJI32@gmail.com> Date: Fri, 15 Dec 2023 15:24:09 +0200 Fix SDL controllers not automatically reconnecting. Fixes #563 Diffstat:
| M | SDL/gui.c | 5 | +++-- |
| M | SDL/gui.h | 1 | + |
| M | SDL/main.c | 9 | +++++++++ |
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/SDL/gui.c b/SDL/gui.c @@ -1776,9 +1776,9 @@ static void enter_keyboard_menu(unsigned index) } static unsigned joypad_index = 0; -static SDL_Joystick *joystick = NULL; static SDL_GameController *controller = NULL; SDL_Haptic *haptic = NULL; +SDL_Joystick *joystick = NULL; static const char *current_joypad_name(unsigned index) { @@ -1830,7 +1830,8 @@ static void cycle_joypads(unsigned index) } if (joystick) { haptic = SDL_HapticOpenFromJoystick(joystick); - }} + } +} static void cycle_joypads_backwards(unsigned index) { diff --git a/SDL/gui.h b/SDL/gui.h @@ -21,6 +21,7 @@ extern SDL_Window *window; extern SDL_Renderer *renderer; extern SDL_Texture *texture; extern SDL_PixelFormat *pixel_format; +extern SDL_Joystick *joystick; extern SDL_Haptic *haptic; extern shader_t shader; diff --git a/SDL/main.c b/SDL/main.c @@ -249,6 +249,15 @@ static void handle_events(GB_gameboy_t *gb) break; } + case SDL_JOYDEVICEREMOVED: + if (joystick && event.jdevice.which == SDL_JoystickInstanceID(joystick)) { + SDL_JoystickClose(joystick); + joystick = NULL; + } + case SDL_JOYDEVICEADDED: + connect_joypad(); + break; + case SDL_JOYBUTTONUP: case SDL_JOYBUTTONDOWN: { joypad_button_t button = get_joypad_button(event.jbutton.button);
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.