Skip to content

Commit

Permalink
fixing global shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
wkjarosz committed Dec 10, 2024
1 parent e97b706 commit 915584e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1877,8 +1877,8 @@ void HDRViewApp::draw_command_palette()

ImCmd::CommandPalette("Command palette", "Filter commands...");

if (ImCmd::IsAnyItemSelected() || ImGui::GlobalChordPressed(ImGuiKey_Escape) ||
ImGui::GlobalChordPressed(ImGuiMod_Ctrl | ImGuiKey_Period, ImGuiInputFlags_Repeat) ||
if (ImCmd::IsAnyItemSelected() || ImGui::GlobalShortcut(ImGuiKey_Escape) ||
ImGui::GlobalShortcut(ImGuiMod_Ctrl | ImGuiKey_Period, ImGuiInputFlags_Repeat) ||
!ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows))
// Close window when user selects an item, hits escape, or unfocuses the command palette window
// (clicking elsewhere)
Expand Down Expand Up @@ -1928,7 +1928,7 @@ void HDRViewApp::process_hotkeys()

for (auto &a : m_actions)
if (a.second.chord)
if (a.second.enabled() && ImGui::GlobalChordPressed(a.second.chord, a.second.flags))
if (a.second.enabled() && ImGui::GlobalShortcut(a.second.chord, a.second.flags))
{
spdlog::trace("Processing hotkey for action '{}' (frame: {})", a.first, ImGui::GetFrameCount());
a.second.callback();
Expand Down
5 changes: 2 additions & 3 deletions src/imgui_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,9 @@ const char *GetKeyChordNameTranslated(ImGuiKeyChord key_chord)
return g.TempKeychordName;
}

bool GlobalChordPressed(const ImGuiKeyChord &chord, ImGuiInputFlags flags)
bool GlobalShortcut(const ImGuiKeyChord &chord, ImGuiInputFlags flags)
{
return ImGui::GetShortcutRoutingData(chord)->RoutingCurr == ImGuiKeyOwner_NoOwner &&
ImGui::IsKeyChordPressed(chord, flags);
return ImGui::Shortcut(chord, flags | ImGuiInputFlags_RouteGlobal);
}

} // namespace ImGui
2 changes: 1 addition & 1 deletion src/imgui_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ void TextWithHoverColor(ImVec4 col, const char *fmt, ...);
// Like ImGui::GetKeyChordName, but returns the translated name of the key chord.
const char *GetKeyChordNameTranslated(ImGuiKeyChord key_chord);
// Used for global key chords, e.g. for menu shortcuts.
bool GlobalChordPressed(const ImGuiKeyChord &chord, ImGuiInputFlags flags = 0);
bool GlobalShortcut(const ImGuiKeyChord &chord, ImGuiInputFlags flags = 0);

} // namespace ImGui

0 comments on commit 915584e

Please sign in to comment.