Skip to content

Commit

Permalink
Nav: Alt doesn't toggle menu layer if other modifiers are held. (#4439)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Aug 17, 2021
1 parent c7529c8 commit 8fa502c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Other Changes:
- Menus: MenuItem() and BeginMenu() are not affected/overlapping when style.SelectableTextAlign is altered.
- Menus: fix hovering a disabled menu or menu item not closing other menus. (#211)
- Popups: fix BeginPopup/OpenPopup sequence failing when there are no focused windows. (#4308) [@rokups]
- Nav: Alt doesn't toggle menu layer if other modifiers are held. (#4439)
- Nav: Disabled items are not candidate for default focus. (#211, #787)
- Disabled: disabled items set HoveredId, allowing e.g. HoveredIdTimer to function. (#211, #3419) [@rokups]
- Disabled: disabled mode more consistently release active id if the active item got disabled. (#211)
Expand Down
19 changes: 14 additions & 5 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9123,9 +9123,15 @@ static void ImGui::NavUpdate()
if (io.KeyAlt && !io.KeyCtrl)
io.NavInputs[ImGuiNavInput_KeyMenu_] = 1.0f;

// We automatically cancel toggling nav layer when any text has been typed while holding Alt. (See #370)
if (io.KeyAlt && !io.KeyCtrl && g.NavWindowingToggleLayer && io.InputQueueCharacters.Size > 0)
g.NavWindowingToggleLayer = false;
// We cancel toggling nav layer when any text has been typed while holding Alt. (See #370)
// We cancel toggling nav layer when other modifiers are pressed. (See #4439)
if (g.NavWindowingToggleLayer && g.NavInputSource == ImGuiInputSource_Keyboard)
{
if (io.KeyAlt && !io.KeyCtrl && io.InputQueueCharacters.Size > 0)
g.NavWindowingToggleLayer = false;
if (io.KeyCtrl || io.KeyShift || io.KeySuper)
g.NavWindowingToggleLayer = false;
}

#undef NAV_MAP_KEY
}
Expand Down Expand Up @@ -9643,7 +9649,7 @@ static void ImGui::NavUpdateWindowing()
{
g.NavWindowingTarget = g.NavWindowingTargetAnim = window->RootWindow;
g.NavWindowingTimer = g.NavWindowingHighlightAlpha = 0.0f;
g.NavWindowingToggleLayer = start_windowing_with_keyboard ? false : true;
g.NavWindowingToggleLayer = start_windowing_with_gamepad ? true : false; // Gamepad starts toggling layer
g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_Keyboard : ImGuiInputSource_Gamepad;
}

Expand Down Expand Up @@ -9687,8 +9693,11 @@ static void ImGui::NavUpdateWindowing()

// Keyboard: Press and Release ALT to toggle menu layer
// FIXME: We lack an explicit IO variable for "is the imgui window focused", so compare mouse validity to detect the common case of backend clearing releases all keys on ALT-TAB
if (IsNavInputTest(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Pressed))
if (IsNavInputTest(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Pressed) && g.IO.KeyMods == ImGuiKeyModFlags_Alt)
{
g.NavWindowingToggleLayer = true;
g.NavInputSource = ImGuiInputSource_Keyboard;
}
if ((g.ActiveId == 0 || g.ActiveIdAllowOverlap) && g.NavWindowingToggleLayer && IsNavInputTest(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Released))
if (IsMousePosValid(&g.IO.MousePos) == IsMousePosValid(&g.IO.MousePosPrev))
apply_toggle_layer = true;
Expand Down

0 comments on commit 8fa502c

Please sign in to comment.