mirror of https://github.com/mgba-emu/mgba.git
SDL: Automatically map controllers when plugged in
This commit is contained in:
parent
2f14f58911
commit
2da3d3e6ba
1
CHANGES
1
CHANGES
|
@ -53,6 +53,7 @@ Misc:
|
||||||
- All: Move time.h include to common.h
|
- All: Move time.h include to common.h
|
||||||
- CMake: Add ability to just print version string
|
- CMake: Add ability to just print version string
|
||||||
- Qt: Merge "Save" and "OK" buttons in shader options
|
- Qt: Merge "Save" and "OK" buttons in shader options
|
||||||
|
- SDL: Automatically map controllers when plugged in
|
||||||
|
|
||||||
0.5.2: (2016-12-31)
|
0.5.2: (2016-12-31)
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
|
@ -48,14 +48,16 @@ InputController::InputController(int playerId, QWidget* topLevel, QObject* paren
|
||||||
updateJoysticks();
|
updateJoysticks();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_gamepadTimer = new QTimer(this);
|
|
||||||
#ifdef BUILD_SDL
|
#ifdef BUILD_SDL
|
||||||
connect(m_gamepadTimer, &QTimer::timeout, [this]() {
|
connect(&m_gamepadTimer, &QTimer::timeout, [this]() {
|
||||||
testGamepad(SDL_BINDING_BUTTON);
|
testGamepad(SDL_BINDING_BUTTON);
|
||||||
|
if (m_playerId == 0) {
|
||||||
|
updateJoysticks();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
m_gamepadTimer->setInterval(50);
|
m_gamepadTimer.setInterval(50);
|
||||||
m_gamepadTimer->start();
|
m_gamepadTimer.start();
|
||||||
|
|
||||||
mInputBindKey(&m_inputMap, KEYBOARD, Qt::Key_X, GBA_KEY_A);
|
mInputBindKey(&m_inputMap, KEYBOARD, Qt::Key_X, GBA_KEY_A);
|
||||||
mInputBindKey(&m_inputMap, KEYBOARD, Qt::Key_Z, GBA_KEY_B);
|
mInputBindKey(&m_inputMap, KEYBOARD, Qt::Key_Z, GBA_KEY_B);
|
||||||
|
|
|
@ -11,10 +11,9 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
#include <QTimer>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
class QTimer;
|
|
||||||
|
|
||||||
#include <mgba/internal/gba/input.h>
|
#include <mgba/internal/gba/input.h>
|
||||||
|
|
||||||
#ifdef BUILD_SDL
|
#ifdef BUILD_SDL
|
||||||
|
@ -54,7 +53,6 @@ public:
|
||||||
|
|
||||||
const mInputMap* map() const { return &m_inputMap; }
|
const mInputMap* map() const { return &m_inputMap; }
|
||||||
|
|
||||||
void updateJoysticks();
|
|
||||||
int pollEvents();
|
int pollEvents();
|
||||||
|
|
||||||
static const int32_t AXIS_THRESHOLD = 0x3000;
|
static const int32_t AXIS_THRESHOLD = 0x3000;
|
||||||
|
@ -66,7 +64,7 @@ public:
|
||||||
void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);
|
void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);
|
||||||
void unbindAllAxes(uint32_t type);
|
void unbindAllAxes(uint32_t type);
|
||||||
|
|
||||||
void bindHat(uint32_t type, int hat, GamepadHatEvent::Direction, GBAKey);
|
void bindHat(uint32_t type, int hat, GamepadHatEvent::Direction, GBAKey);
|
||||||
|
|
||||||
QStringList connectedGamepads(uint32_t type) const;
|
QStringList connectedGamepads(uint32_t type) const;
|
||||||
int gamepad(uint32_t type) const;
|
int gamepad(uint32_t type) const;
|
||||||
|
@ -92,6 +90,7 @@ signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void testGamepad(int type);
|
void testGamepad(int type);
|
||||||
|
void updateJoysticks();
|
||||||
|
|
||||||
// TODO: Move these to somewhere that makes sense
|
// TODO: Move these to somewhere that makes sense
|
||||||
void suspendScreensaver();
|
void suspendScreensaver();
|
||||||
|
@ -123,7 +122,7 @@ private:
|
||||||
QSet<int> m_activeButtons;
|
QSet<int> m_activeButtons;
|
||||||
QSet<QPair<int, GamepadAxisEvent::Direction>> m_activeAxes;
|
QSet<QPair<int, GamepadAxisEvent::Direction>> m_activeAxes;
|
||||||
QSet<QPair<int, GamepadHatEvent::Direction>> m_activeHats;
|
QSet<QPair<int, GamepadHatEvent::Direction>> m_activeHats;
|
||||||
QTimer* m_gamepadTimer;
|
QTimer m_gamepadTimer;
|
||||||
|
|
||||||
QSet<GBAKey> m_pendingEvents;
|
QSet<GBAKey> m_pendingEvents;
|
||||||
};
|
};
|
||||||
|
|
|
@ -339,8 +339,32 @@ void mSDLUpdateJoysticks(struct mSDLEvents* events) {
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick);
|
joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick);
|
||||||
#endif
|
#endif
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; (int) i < events->playersAttached; ++i) {
|
||||||
|
if (events->players[i]->joystick) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* joystickName;
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
|
joystickName = SDL_JoystickName(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick);
|
||||||
|
#else
|
||||||
|
joystickName = SDL_JoystickName(SDL_JoystickIndex(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick));
|
||||||
|
#endif
|
||||||
|
if (events->preferredJoysticks[i] && strcmp(events->preferredJoysticks[i], joystickName) == 0) {
|
||||||
|
events->players[i]->joystick = joystick;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; (int) i < events->playersAttached; ++i) {
|
||||||
|
if (events->players[i]->joystick) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
events->players[i]->joystick = joystick;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else if (event.type == SDL_JOYDEVICEREMOVED) {
|
} else if (event.type == SDL_JOYDEVICEREMOVED) {
|
||||||
SDL_JoystickID ids[MAX_PLAYERS];
|
SDL_JoystickID ids[MAX_PLAYERS] = { 0 };
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; (int) i < events->playersAttached; ++i) {
|
for (i = 0; (int) i < events->playersAttached; ++i) {
|
||||||
if (events->players[i]->joystick) {
|
if (events->players[i]->joystick) {
|
||||||
|
|
Loading…
Reference in New Issue