reversed controller button reaction (now on UP), fixes #567

prevent button read for up after long press
This commit is contained in:
thrust26 2020-02-02 16:05:24 +01:00
parent 0781e7d720
commit f50cadde04
8 changed files with 37 additions and 36 deletions

View File

@ -721,7 +721,7 @@ void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, bool pressed
j->buttonLast[stick] = pressed ? button : JOY_CTRL_NONE; j->buttonLast[stick] = pressed ? button : JOY_CTRL_NONE;
// Handle buttons which switch eventhandler state // Handle buttons which switch eventhandler state
if(pressed && myHandler.changeStateByEvent(j->joyMap.get(EventMode::kEmulationMode, button))) if(!pressed && myHandler.changeStateByEvent(j->joyMap.get(EventMode::kEmulationMode, button)))
return; return;
// Determine which mode we're in, then send the event to the appropriate place // Determine which mode we're in, then send the event to the appropriate place

View File

@ -276,7 +276,7 @@ void ContextMenu::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ContextMenu::handleJoyDown(int stick, int button, bool longPress) void ContextMenu::handleJoyUp(int stick, int button)
{ {
handleEvent(instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button)); handleEvent(instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button));
} }

View File

@ -87,7 +87,7 @@ class ContextMenu : public Dialog, public CommandSender
bool handleMouseClicks(int x, int y, MouseButton b) override; bool handleMouseClicks(int x, int y, MouseButton b) override;
void handleMouseWheel(int x, int y, int direction) override; void handleMouseWheel(int x, int y, int direction) override;
void handleKeyDown(StellaKey key, StellaMod mod, bool repeated) override; void handleKeyDown(StellaKey key, StellaMod mod, bool repeated) override;
void handleJoyDown(int stick, int button, bool longPress) override; void handleJoyUp(int stick, int button) override;
void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override; void handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) override;
bool handleJoyHat(int stick, int hat, JoyHatDir vahdirlue, int button) override; bool handleJoyHat(int stick, int hat, JoyHatDir vahdirlue, int button) override;
void handleEvent(Event::Type e); void handleEvent(Event::Type e);

View File

@ -572,26 +572,32 @@ bool Dialog::handleMouseClicks(int x, int y, MouseButton b)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleJoyDown(int stick, int button, bool longPress) void Dialog::handleJoyDown(int stick, int button, bool longPress)
{ {
Event::Type e = // Focused widget receives joystick events
instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button); if(_focusedWidget)
// Unless a widget has claimed all responsibility for data, we assume
// that if an event exists for the given data, it should have priority.
if(!handleNavEvent(e) && _focusedWidget)
{ {
Event::Type e =
instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
if(_focusedWidget->wantsRaw() || e == Event::NoType) if(_focusedWidget->wantsRaw() || e == Event::NoType)
_focusedWidget->handleJoyDown(stick, button, longPress); _focusedWidget->handleJoyDown(stick, button, longPress);
else
_focusedWidget->handleEvent(e);
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::handleJoyUp(int stick, int button) void Dialog::handleJoyUp(int stick, int button)
{ {
// Focused widget receives joystick events Event::Type e =
if(_focusedWidget) instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
_focusedWidget->handleJoyUp(stick, button);
// Unless a widget has claimed all responsibility for data, we assume
// that if an event exists for the given data, it should have priority.
if (!handleNavEvent(e) && _focusedWidget)
{
if (_focusedWidget->wantsRaw() || e == Event::NoType)
_focusedWidget->handleJoyUp(stick, button);
else
_focusedWidget->handleEvent(e);
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -66,6 +66,7 @@ void DialogContainer::updateTime(uInt64 time)
// Joystick has been pressed long // Joystick has been pressed long
if(myCurrentButtonDown.stick != -1 && myButtonLongPressTime < myTime) if(myCurrentButtonDown.stick != -1 && myButtonLongPressTime < myTime)
{ {
myButtonLongPress = true;
activeDialog->handleJoyDown(myCurrentButtonDown.stick, myCurrentButtonDown.button, true); activeDialog->handleJoyDown(myCurrentButtonDown.stick, myCurrentButtonDown.button, true);
myButtonLongPressTime = myButtonRepeatTime = myTime + _REPEAT_NONE; myButtonLongPressTime = myButtonRepeatTime = myTime + _REPEAT_NONE;
} }
@ -302,7 +303,10 @@ void DialogContainer::handleJoyBtnEvent(int stick, int button, bool pressed)
myCurrentButtonDown.stick = myCurrentButtonDown.button = -1; myCurrentButtonDown.stick = myCurrentButtonDown.button = -1;
myButtonRepeatTime = myButtonLongPressTime = 0; myButtonRepeatTime = myButtonLongPressTime = 0;
} }
activeDialog->handleJoyUp(stick, button); if (myButtonLongPress)
myButtonLongPress = false;
else
activeDialog->handleJoyUp(stick, button);
} }
} }

View File

@ -206,6 +206,7 @@ class DialogContainer
} myCurrentButtonDown; } myCurrentButtonDown;
uInt64 myButtonRepeatTime{0}; uInt64 myButtonRepeatTime{0};
uInt64 myButtonLongPressTime{0}; uInt64 myButtonLongPressTime{0};
bool myButtonLongPress{false};
// For continuous 'joy axis down' events // For continuous 'joy axis down' events
struct { struct {

View File

@ -404,6 +404,14 @@ void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::handleJoyDown(int stick, int button, bool longPress) void LauncherDialog::handleJoyDown(int stick, int button, bool longPress)
{
myEventHandled = false;
myList->setFlags(Widget::FLAG_WANTS_RAWDATA); // allow handling long button press
Dialog::handleJoyDown(stick, button, longPress);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::handleJoyUp(int stick, int button)
{ {
// open power-up options and settings for 2nd and 4th button if not mapped otherwise // open power-up options and settings for 2nd and 4th button if not mapped otherwise
Event::Type e = instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button); Event::Type e = instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
@ -413,19 +421,9 @@ void LauncherDialog::handleJoyDown(int stick, int button, bool longPress)
myGlobalProps->open(); myGlobalProps->open();
if (button == 3 && (e == Event::Event::UITabPrev || e == Event::NoType)) if (button == 3 && (e == Event::Event::UITabPrev || e == Event::NoType))
openSettings(); openSettings();
else else if (!myEventHandled)
{
myEventHandled = false;
myList->setFlags(Widget::FLAG_WANTS_RAWDATA); // allow handling long button press
Dialog::handleJoyDown(stick, button, longPress);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::handleJoyUp(int stick, int button)
{
if (!myEventHandled)
Dialog::handleJoyUp(stick, button); Dialog::handleJoyUp(stick, button);
myList->clearFlags(Widget::FLAG_WANTS_RAWDATA); // stop allowing to handle long button press myList->clearFlags(Widget::FLAG_WANTS_RAWDATA); // stop allowing to handle long button press
} }

View File

@ -279,12 +279,6 @@ void ListWidget::handleJoyDown(int stick, int button, bool longPress)
{ {
if (longPress) if (longPress)
sendCommand(ListWidget::kLongButtonPressCmd, _selectedItem, _id); sendCommand(ListWidget::kLongButtonPressCmd, _selectedItem, _id);
Event::Type e = _boss->instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
// handle UISelect event on button up
if(e != Event::UISelect)
handleEvent(e);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -292,9 +286,7 @@ void ListWidget::handleJoyUp(int stick, int button)
{ {
Event::Type e = _boss->instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button); Event::Type e = _boss->instance().eventHandler().eventForJoyButton(EventMode::kMenuMode, stick, button);
// handle UISelect event on button up handleEvent(e);
if(e == Event::UISelect)
handleEvent(e);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -