1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 22:40:39 +02:00

InputManager: prevent unmapped buttons from generating events.

This commit is contained in:
Paul Cercueil 2012-01-22 21:49:52 +01:00
parent 0043ea5909
commit 273770dad3
2 changed files with 12 additions and 8 deletions

View File

@ -121,14 +121,12 @@ InputManager::Button InputManager::waitForReleasedButton() {
InputManager::Button InputManager::waitForButton(ButtonState state) { InputManager::Button InputManager::waitForButton(ButtonState state) {
ButtonEvent event; ButtonEvent event;
do { while (!waitForEvent(&event) || event.state != state);
waitForEvent(&event);
} while (event.state != state);
return event.button; return event.button;
} }
void InputManager::waitForEvent(ButtonEvent *event) { bool InputManager::waitForEvent(ButtonEvent *event) {
getEvent(event, true); return getEvent(event, true);
} }
bool InputManager::pollEvent(ButtonEvent *event) { bool InputManager::pollEvent(ButtonEvent *event) {
@ -139,6 +137,8 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
//TODO: when an event is processed, program a new event //TODO: when an event is processed, program a new event
//in some time, and when it occurs, do a key repeat //in some time, and when it occurs, do a key repeat
int i;
#ifndef SDL_JOYSTICK_DISABLED #ifndef SDL_JOYSTICK_DISABLED
if (joystick) { if (joystick) {
SDL_JoystickUpdate(); SDL_JoystickUpdate();
@ -179,7 +179,7 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
} }
if (source == KEYBOARD) { if (source == KEYBOARD) {
for (int i = 0; i < BUTTON_TYPE_SIZE; i++) { for (i = 0; i < BUTTON_TYPE_SIZE; i++) {
if (buttonMap[i].source == KEYBOARD if (buttonMap[i].source == KEYBOARD
&& (unsigned int)event.key.keysym.sym == buttonMap[i].code) { && (unsigned int)event.key.keysym.sym == buttonMap[i].code) {
bevent->button = static_cast<Button>(i); bevent->button = static_cast<Button>(i);
@ -188,7 +188,7 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
} }
#ifndef SDL_JOYSTICK_DISABLED #ifndef SDL_JOYSTICK_DISABLED
} else if (source == JOYSTICK) { } else if (source == JOYSTICK) {
for (int i = 0; i < BUTTON_TYPE_SIZE; i++) { for (i = 0; i < BUTTON_TYPE_SIZE; i++) {
if (buttonMap[i].source == JOYSTICK if (buttonMap[i].source == JOYSTICK
&& (unsigned int)event.jbutton.button == buttonMap[i].code) { && (unsigned int)event.jbutton.button == buttonMap[i].code) {
bevent->button = static_cast<Button>(i); bevent->button = static_cast<Button>(i);
@ -197,6 +197,10 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
} }
#endif #endif
} }
if (i == BUTTON_TYPE_SIZE)
return false;
if (wait && PowerSaver::isRunning()) { if (wait && PowerSaver::isRunning()) {
PowerSaver::getInstance()->resetScreenTimer(); PowerSaver::getInstance()->resetScreenTimer();
} }

View File

@ -46,7 +46,7 @@ public:
~InputManager(); ~InputManager();
void init(const std::string &conffile); void init(const std::string &conffile);
void waitForEvent(ButtonEvent *event); bool waitForEvent(ButtonEvent *event);
Button waitForPressedButton(); Button waitForPressedButton();
Button waitForReleasedButton(); Button waitForReleasedButton();
bool pollEvent(ButtonEvent *event); bool pollEvent(ButtonEvent *event);