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) {
ButtonEvent event;
do {
waitForEvent(&event);
} while (event.state != state);
while (!waitForEvent(&event) || event.state != state);
return event.button;
}
void InputManager::waitForEvent(ButtonEvent *event) {
getEvent(event, true);
bool InputManager::waitForEvent(ButtonEvent *event) {
return getEvent(event, true);
}
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
//in some time, and when it occurs, do a key repeat
int i;
#ifndef SDL_JOYSTICK_DISABLED
if (joystick) {
SDL_JoystickUpdate();
@ -179,7 +179,7 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
}
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
&& (unsigned int)event.key.keysym.sym == buttonMap[i].code) {
bevent->button = static_cast<Button>(i);
@ -188,7 +188,7 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
}
#ifndef SDL_JOYSTICK_DISABLED
} 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
&& (unsigned int)event.jbutton.button == buttonMap[i].code) {
bevent->button = static_cast<Button>(i);
@ -197,6 +197,10 @@ bool InputManager::getEvent(ButtonEvent *bevent, bool wait) {
}
#endif
}
if (i == BUTTON_TYPE_SIZE)
return false;
if (wait && PowerSaver::isRunning()) {
PowerSaver::getInstance()->resetScreenTimer();
}

View File

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