diff --git a/src/ui/button.cpp b/src/ui/button.cpp index 90c415e1a..c950b2b16 100644 --- a/src/ui/button.cpp +++ b/src/ui/button.cpp @@ -86,11 +86,7 @@ bool ButtonBase::onProcessMessage(Message* msg) if (isEnabled() && isVisible()) { const bool mnemonicPressed = - (mnemonic() && - (!mnemonicRequiresModifiers() || - msg->altPressed() || - msg->cmdPressed()) && - isMnemonicPressed(keymsg)); + isMnemonicPressedWithModifiers(keymsg); // For kButtonWidget if (m_behaviorType == kButtonWidget) { @@ -157,11 +153,8 @@ bool ButtonBase::onProcessMessage(Message* msg) KeyMessage* keymsg = static_cast(msg); KeyScancode scancode = keymsg->scancode(); const bool mnemonicPressed = - (mnemonic() && - (!mnemonicRequiresModifiers() || - msg->altPressed() || - msg->cmdPressed()) && - isMnemonicPressed(keymsg)); + isMnemonicPressedWithModifiers(keymsg); + // Fire the onClick() event only if the user pressed space or // Alt+the underscored letter of the checkbox label. if (scancode == kKeySpace || mnemonicPressed) { diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index 787960a82..0b7b0f17b 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -1556,6 +1556,15 @@ bool Widget::isMnemonicPressed(const KeyMessage* keyMsg) const (chr >= '0' && chr <= '9' && keyMsg->scancode() == (kKey0 + chr - '0')))); } +bool Widget::isMnemonicPressedWithModifiers(const KeyMessage* msg) const +{ + return (mnemonic() && + (!mnemonicRequiresModifiers() || + msg->altPressed() || + msg->cmdPressed()) && + isMnemonicPressed(msg)); +} + bool Widget::onProcessMessage(Message* msg) { ASSERT(msg != nullptr); diff --git a/src/ui/widget.h b/src/ui/widget.h index ba5ff9080..a709f51f0 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -384,7 +384,7 @@ namespace ui { // Offer the capture to widgets of the given type. Returns true if // the capture was passed to other widget. - bool offerCapture(ui::MouseMessage* mouseMsg, int widget_type); + bool offerCapture(MouseMessage* mouseMsg, int widget_type); // Returns lower-case letter that represet the mnemonic of the widget // (the underscored character, i.e. the letter after & symbol). @@ -405,7 +405,11 @@ namespace ui { // Returns true if the mnemonic character is pressed (without modifiers). // TODO maybe we can add check for modifiers now that this // information is included in the Widget - bool isMnemonicPressed(const ui::KeyMessage* keyMsg) const; + bool isMnemonicPressed(const KeyMessage* keyMsg) const; + + // Returns true if the mnemonic character is pressed with + // modifiers (Alt or Command key). + bool isMnemonicPressedWithModifiers(const KeyMessage* msg) const; // Signals obs::signal InitTheme;