From 6170647c0c17534bc9dceb5135191abc568e0ad1 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 20 Jan 2025 02:10:48 -0600 Subject: [PATCH] [nostalgia,studio] Proper fix for input filtering --- .../core/src/studio/paletteeditor/paletteeditor-imgui.cpp | 3 +-- src/olympic/studio/applib/src/studioapp.cpp | 5 +++++ src/olympic/studio/modlib/include/studio/imguiutil.hpp | 3 +++ src/olympic/studio/modlib/src/imguiutil.cpp | 5 +++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp index 9e2a8a4a..bd33d678 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -258,8 +258,7 @@ void PaletteEditorImGui::drawColorEditor() noexcept { std::ignore = pushCommand( m_pal, m_page, m_selectedColorRow); } - if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootWindow) && - !inputFocused && !m_pageRenameDlg.isOpen()) { + if (ig::mainWinHasFocus()) { if (!ImGui::IsKeyDown(ImGuiKey_ModAlt)) { numShortcuts(m_selectedColorRow, largestPage(m_pal)); } else { diff --git a/src/olympic/studio/applib/src/studioapp.cpp b/src/olympic/studio/applib/src/studioapp.cpp index 67e2bb28..f7e354b5 100644 --- a/src/olympic/studio/applib/src/studioapp.cpp +++ b/src/olympic/studio/applib/src/studioapp.cpp @@ -18,6 +18,9 @@ namespace studio { +namespace ig { +extern bool s_mainWinHasFocus; +} static ox::Vector modules; void registerModule(Module const*mod) noexcept { @@ -114,6 +117,8 @@ void StudioUI::draw() noexcept { ImGuiWindowFlags_NoSavedSettings; ImGui::Begin("MainWindow##Studio", nullptr, windowFlags); { + ig::s_mainWinHasFocus = ImGui::IsWindowFocused( + ImGuiFocusedFlags_RootAndChildWindows | ImGuiFocusedFlags_NoPopupHierarchy); if (m_showProjectExplorer) { m_projectExplorer.draw(m_sctx); ImGui::SameLine(); diff --git a/src/olympic/studio/modlib/include/studio/imguiutil.hpp b/src/olympic/studio/modlib/include/studio/imguiutil.hpp index 60bff752..cf272261 100644 --- a/src/olympic/studio/modlib/include/studio/imguiutil.hpp +++ b/src/olympic/studio/modlib/include/studio/imguiutil.hpp @@ -256,4 +256,7 @@ class FilePicker { }; +[[nodiscard]] +bool mainWinHasFocus() noexcept; + } diff --git a/src/olympic/studio/modlib/src/imguiutil.cpp b/src/olympic/studio/modlib/src/imguiutil.cpp index b6d8fb2a..d3af2aaf 100644 --- a/src/olympic/studio/modlib/src/imguiutil.cpp +++ b/src/olympic/studio/modlib/src/imguiutil.cpp @@ -208,4 +208,9 @@ void FilePicker::show() noexcept { m_show = true; } +bool s_mainWinHasFocus{}; +bool mainWinHasFocus() noexcept { + return s_mainWinHasFocus; +} + }