diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index fc81dc193..dd3005758 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -182,7 +182,8 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && - mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { + Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() && + mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); } else { mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask); diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 4dcb57ce0..781b2c6a6 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -276,7 +276,8 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct mapping = std::make_shared(mPortIndex, mStickIndex, direction, mKeyboardScancodeForNewMapping); } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && - mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { + Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() && + mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, mMouseButtonForNewMapping); } else { diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index aa6b8edb4..41dc00dcd 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -994,6 +994,18 @@ bool Gui::IsMouseOverAnyGuiItem() { return ImGui::IsAnyItemHovered(); } +bool Gui::IsMouseOverActivePopup() { + ImGuiContext* ctx = ImGui::GetCurrentContext(); + if (ctx->OpenPopupStack.Size == 0 || ctx->HoveredWindow == NULL) { + return false; + } + ImGuiPopupData data = ctx->OpenPopupStack.back(); + if (data.Window == NULL) { + return false; + } + return (ctx->HoveredWindow->ID == data.Window->ID); +} + std::shared_ptr Gui::GetMenu() { return mMenu; } diff --git a/src/window/gui/Gui.h b/src/window/gui/Gui.h index 12913bad0..7f4629777 100644 --- a/src/window/gui/Gui.h +++ b/src/window/gui/Gui.h @@ -100,6 +100,7 @@ class Gui { std::shared_ptr GetMenu(); bool GetMenuOrMenubarVisible(); bool IsMouseOverAnyGuiItem(); + bool IsMouseOverActivePopup(); bool GamepadNavigationEnabled(); void BlockGamepadNavigation();