Skip to content

Commit 8c95c08

Browse files
committed
Inputs: changed specs of SetKeyOwner() to alter OwnerCurr immediately.
Note the removed comments (hence not squashing) Amend 4448d97 (#456, #2637, #2620, #2891, #3370,, #4828, #5108, #5242, #5641)
1 parent 4448d97 commit 8c95c08

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

imgui.cpp

+5-14
Original file line numberDiff line numberDiff line change
@@ -8370,17 +8370,9 @@ bool ImGui::TestKeyOwner(ImGuiKey key, ImGuiID owner_id)
83708370
if (owner_id == ImGuiKeyOwner_Any)
83718371
return (owner_data->LockThisFrame == false);
83728372

8373-
// FIXME: For consistency with routing may be good to disable that, OR we could differentiate preemptive routing from setting owner on click.
8374-
// For now it is better to disable so we can actually get report of case where this may matter.
8375-
// -> Better to move in the SetKeyOwner() call, aka have a flag to set ->OwnerCurr in SetKeyOwner() ?
8376-
// May simply be inconsistent and unneeded to offer that feature:
8377-
// - for typical keyboard/gamepad routing with multiple claims and ServeLast, we don't want to affect owner testing during the frame.
8378-
// - for typical mouse routing overlap + hovered window generally prevents making it useful to alter owner testing during the frame.
8379-
// - but effectively Locked flag can alter same-frame behavior.
8380-
//// We want OwnerNext to be handled immediately so SetKeyOwner(key, id1), TestKeyOwner(key, id2) == false
8381-
//if (owner_data->OwnerNext != ImGuiKeyOwner_None && owner_data->OwnerNext != owner)
8382-
// return false;
8383-
8373+
// Note: SetKeyOwner() sets OwnerCurr. It is not strictly required for most mouse routing overlap (because of ActiveId/HoveredId
8374+
// are acting as filter before this has a chance to filter), but sane as soon as user tries to look into things.
8375+
// Setting OwnerCurr in SetKeyOwner() is more consistent than testing OwnerNext here: would be inconsistent with getter and other functions.
83848376
if (owner_data->OwnerCurr != owner_id)
83858377
{
83868378
if (owner_data->LockThisFrame)
@@ -8392,6 +8384,7 @@ bool ImGui::TestKeyOwner(ImGuiKey key, ImGuiID owner_id)
83928384
return true;
83938385
}
83948386

8387+
// _LockXXX flags are useful to lock keys away from code which is not input-owner aware.
83958388
// When using _LockXXX flags, you can use ImGuiKeyOwner_Any to lock keys from everyone.
83968389
// - SetKeyOwner(..., None) : clears owner
83978390
// - SetKeyOwner(..., Any, !Lock) : illegal (assert)
@@ -8401,14 +8394,12 @@ void ImGui::SetKeyOwner(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags)
84018394
IM_ASSERT(IsNamedKeyOrModKey(key) && (owner_id != ImGuiKeyOwner_Any || (flags & (ImGuiInputFlags_LockThisFrame | ImGuiInputFlags_LockUntilRelease)))); // Can only use _Any with _LockXXX flags (to eat a key away without an ID to retrieve it)
84028395

84038396
ImGuiKeyOwnerData* owner_data = GetKeyOwnerData(key);
8404-
owner_data->OwnerNext = owner_id;
8397+
owner_data->OwnerCurr = owner_data->OwnerNext = owner_id;
84058398

84068399
// We cannot lock by default as it would likely break lots of legacy code.
84078400
// In the case of using LockUntilRelease while key is not down we still lock during the frame (no key_data->Down test)
84088401
owner_data->LockUntilRelease = (flags & ImGuiInputFlags_LockUntilRelease) != 0;
84098402
owner_data->LockThisFrame = (flags & ImGuiInputFlags_LockThisFrame) != 0 || (owner_data->LockUntilRelease);
8410-
if (owner_data->LockThisFrame)
8411-
owner_data->OwnerCurr = owner_id;
84128403
}
84138404

84148405
// This is more or less equivalent to:

0 commit comments

Comments
 (0)