IO: modify io.AddFocusEvent() to tolerate in/out for multi-viewports. Amend 2f40be6. (merged from docking) (#3532)

This commit is contained in:
ocornut
2021-08-19 17:35:27 +02:00
parent fba756176d
commit bbb95a5e06
2 changed files with 19 additions and 7 deletions

View File

@ -1185,13 +1185,8 @@ void ImGuiIO::ClearInputCharacters()
InputQueueCharacters.resize(0);
}
void ImGuiIO::AddFocusEvent(bool focused)
void ImGuiIO::ClearInputKeys()
{
if (focused)
return;
// Clear buttons state when focus is lost
// (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle)
memset(KeysDown, 0, sizeof(KeysDown));
for (int n = 0; n < IM_ARRAYSIZE(KeysDownDuration); n++)
KeysDownDuration[n] = KeysDownDurationPrev[n] = -1.0f;
@ -1201,6 +1196,13 @@ void ImGuiIO::AddFocusEvent(bool focused)
NavInputsDownDuration[n] = NavInputsDownDurationPrev[n] = -1.0f;
}
void ImGuiIO::AddFocusEvent(bool focused)
{
// We intentionally overwrite this and process in NewFrame(), in order to give a chance
// to multi-viewports backends to queue AddFocusEvent(false),AddFocusEvent(true) in same frame.
AppFocusLost = !focused;
}
//-----------------------------------------------------------------------------
// [SECTION] MISC HELPERS/UTILITIES (Geometry functions)
//-----------------------------------------------------------------------------
@ -4070,6 +4072,14 @@ void ImGui::NewFrame()
g.DragDropWithinTarget = false;
g.DragDropHoldJustPressedId = 0;
// Clear buttons state when focus is lost
// (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle)
if (g.IO.AppFocusLost)
{
g.IO.ClearInputKeys();
g.IO.AppFocusLost = false;
}
// Update keyboard input state
// Synchronize io.KeyMods with individual modifiers io.KeyXXX bools
g.IO.KeyMods = GetMergedKeyModFlags();