mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-23 02:51:33 +02:00
InputManager: prevent unmapped buttons from generating events.
This commit is contained in:
parent
0043ea5909
commit
273770dad3
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user