From e3998417e79962787f8f3f3e3181401693c066e9 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 7 Sep 2023 14:11:17 +0200 Subject: [PATCH] Fix shortcut input handling in BaseButton. --- scene/gui/base_button.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 5bf0e3ad3..c033bdeca 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -30,8 +30,8 @@ #include "base_button.h" -#include "core/os/keyboard.h" #include "core/input/shortcut.h" +#include "core/os/keyboard.h" #include "scene/main/viewport.h" #include "scene/scene_string_names.h" @@ -352,13 +352,25 @@ Ref BaseButton::get_shortcut() const { void BaseButton::_shortcut_input(Ref p_event) { ERR_FAIL_COND(p_event.is_null()); - if (!is_disabled() && is_visible_in_tree() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { - if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this)) { - return; //ignore because of modal window + if (!is_disabled() && p_event->is_pressed() && is_visible_in_tree() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) { + if (toggle_mode) { + status.pressed = !status.pressed; + + _unpress_group(); + if (button_group.is_valid()) { + button_group->emit_signal("pressed", this); + } + + _toggled(status.pressed); + _pressed(); + + } else { + _pressed(); } - on_action_event(p_event); - get_tree()->set_input_as_handled(); + accept_event(); + + update(); } } @@ -463,10 +475,10 @@ BaseButton::BaseButton() { status.hovering = false; status.pressing_inside = false; status.disabled = false; - set_focus_mode(FOCUS_ALL); enabled_focus_mode = FOCUS_ALL; action_mode = ACTION_MODE_BUTTON_RELEASE; button_mask = BUTTON_MASK_LEFT; + set_focus_mode(FOCUS_ALL); } BaseButton::~BaseButton() {