Skip to content

Commit 89d0907

Browse files
committed
Nav: Made Ctrl+Tab/Ctrl+Shift+Tab windowing register ownership to held modifier. (#4828, #3255, #5641)
1 parent c98bad0 commit 89d0907

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Other changes:
4646
be desirable to take advantage of this trick. (#4714)
4747
- Drag, Sliders: Fixed parsing of text input when '+' or '#' format flags are used
4848
in the format string. (#6259) [@idbrii]
49+
- Nav: Made Ctrl+Tab/Ctrl+Shift+Tab windowing register ownership to held modifier so
50+
it doesn't interfere with other code when remapping those actions. (#4828, #3255, #5641)
4951
- ColorEdit: Fixed shading of S/V triangle in Hue Wheel mode. (#5200, #6254) [@jamesthomasgriffin]
5052
- Rendering: Using adaptative tesselation for: RadioButton, ColorEdit preview circles,
5153
Windows Close and Collapse Buttons.

imgui.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -8862,6 +8862,17 @@ void ImGui::SetKeyOwner(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags)
88628862
owner_data->LockThisFrame = (flags & ImGuiInputFlags_LockThisFrame) != 0 || (owner_data->LockUntilRelease);
88638863
}
88648864

8865+
// Rarely used helper
8866+
void ImGui::SetKeyOwnersForKeyChord(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
8867+
{
8868+
if (key_chord & ImGuiMod_Ctrl) { SetKeyOwner(ImGuiMod_Ctrl, owner_id, flags); }
8869+
if (key_chord & ImGuiMod_Shift) { SetKeyOwner(ImGuiMod_Shift, owner_id, flags); }
8870+
if (key_chord & ImGuiMod_Alt) { SetKeyOwner(ImGuiMod_Alt, owner_id, flags); }
8871+
if (key_chord & ImGuiMod_Super) { SetKeyOwner(ImGuiMod_Super, owner_id, flags); }
8872+
if (key_chord & ImGuiMod_Shortcut) { SetKeyOwner(ImGuiMod_Shortcut, owner_id, flags); }
8873+
if (key_chord & ~ImGuiMod_Mask_) { SetKeyOwner((ImGuiKey)(key_chord & ~ImGuiMod_Mask_), owner_id, flags); }
8874+
}
8875+
88658876
// This is more or less equivalent to:
88668877
// if (IsItemHovered() || IsItemActive())
88678878
// SetKeyOwner(key, GetItemID());
@@ -11782,10 +11793,11 @@ static void ImGui::NavUpdateWindowing()
1178211793
}
1178311794

1178411795
// Start CTRL+Tab or Square+L/R window selection
11796+
const ImGuiID owner_id = ImHashStr("###NavUpdateWindowing");
1178511797
const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
1178611798
const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
11787-
const bool keyboard_next_window = allow_windowing && g.ConfigNavWindowingKeyNext && Shortcut(g.ConfigNavWindowingKeyNext, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat | ImGuiInputFlags_RouteAlways);
11788-
const bool keyboard_prev_window = allow_windowing && g.ConfigNavWindowingKeyPrev && Shortcut(g.ConfigNavWindowingKeyPrev, ImGuiKeyOwner_None, ImGuiInputFlags_Repeat | ImGuiInputFlags_RouteAlways);
11799+
const bool keyboard_next_window = allow_windowing && g.ConfigNavWindowingKeyNext && Shortcut(g.ConfigNavWindowingKeyNext, owner_id, ImGuiInputFlags_Repeat | ImGuiInputFlags_RouteAlways);
11800+
const bool keyboard_prev_window = allow_windowing && g.ConfigNavWindowingKeyPrev && Shortcut(g.ConfigNavWindowingKeyPrev, owner_id, ImGuiInputFlags_Repeat | ImGuiInputFlags_RouteAlways);
1178911801
const bool start_windowing_with_gamepad = allow_windowing && nav_gamepad_active && !g.NavWindowingTarget && IsKeyPressed(ImGuiKey_NavGamepadMenu, 0, ImGuiInputFlags_None);
1179011802
const bool start_windowing_with_keyboard = allow_windowing && !g.NavWindowingTarget && (keyboard_next_window || keyboard_prev_window); // Note: enabled even without NavEnableKeyboard!
1179111803
if (start_windowing_with_gamepad || start_windowing_with_keyboard)
@@ -11796,6 +11808,10 @@ static void ImGui::NavUpdateWindowing()
1179611808
g.NavWindowingAccumDeltaPos = g.NavWindowingAccumDeltaSize = ImVec2(0.0f, 0.0f);
1179711809
g.NavWindowingToggleLayer = start_windowing_with_gamepad ? true : false; // Gamepad starts toggling layer
1179811810
g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_Keyboard : ImGuiInputSource_Gamepad;
11811+
11812+
// Register ownership of our mods. Using ImGuiInputFlags_RouteGlobalHigh in the Shortcut() calls instead would probably be correct but may have more side-effects.
11813+
if (keyboard_next_window || keyboard_prev_window)
11814+
SetKeyOwnersForKeyChord((g.ConfigNavWindowingKeyNext | g.ConfigNavWindowingKeyPrev) & ImGuiMod_Mask_, owner_id);
1179911815
}
1180011816

1180111817
// Gamepad update

imgui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// Library Version
2424
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345')
2525
#define IMGUI_VERSION "1.89.5 WIP"
26-
#define IMGUI_VERSION_NUM 18943
26+
#define IMGUI_VERSION_NUM 18944
2727
#define IMGUI_HAS_TABLE
2828

2929
/*

imgui_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -2933,6 +2933,7 @@ namespace ImGui
29332933
// Please open a GitHub Issue to submit your usage scenario or if there's a use case you need solved.
29342934
IMGUI_API ImGuiID GetKeyOwner(ImGuiKey key);
29352935
IMGUI_API void SetKeyOwner(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags = 0);
2936+
IMGUI_API void SetKeyOwnersForKeyChord(ImGuiKeyChord key, ImGuiID owner_id, ImGuiInputFlags flags = 0);
29362937
IMGUI_API void SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags = 0); // Set key owner to last item if it is hovered or active. Equivalent to 'if (IsItemHovered() || IsItemActive()) { SetKeyOwner(key, GetItemID());'.
29372938
IMGUI_API bool TestKeyOwner(ImGuiKey key, ImGuiID owner_id); // Test that key is either not owned, either owned by 'owner_id'
29382939
inline ImGuiKeyOwnerData* GetKeyOwnerData(ImGuiContext* ctx, ImGuiKey key) { if (key & ImGuiMod_Mask_) key = ConvertSingleModFlagToKey(ctx, key); IM_ASSERT(IsNamedKey(key)); return &ctx->KeysOwnerData[key - ImGuiKey_NamedKey_BEGIN]; }

0 commit comments

Comments
 (0)