alaingalvan / CrossWindow

💻📱 A cross platform system abstraction library written in C++ for managing windows and performing OS tasks.
https://alain.xyz/libraries/crosswindow
MIT License
632 stars 50 forks source link

Mouse inputs are disabled after alt+tab #26

Open fcturan20 opened 1 year ago

fcturan20 commented 1 year ago

Hi, I implemented a camera system for our renderer but there is an issue. If user uses alt+tab while right-clicking, application stops getting inputs. Here's the implementation: https://github.com/Osman-Fatih-Cakir/DX12Renderer/pull/7/commits/7fc52a2edf97be8351ef0c0f87c531821b26863c . How can we fix this?

alaingalvan commented 1 year ago

~OK, this is a weird one!~

~I was able to reproduce it on my end in Win32 with DirectX 12 with ImGui.~

EDIT: So it turned out that IO state was just stuck after alt-tabbing while right clicking, so one way to mitigate this is to clear your IO state, with ImGui this would be:

if (e.type == xwin::EventType::Focus)
{
    xwin::FocusData fd = e.data.focus;
    if (!fd.focused)
    {
        // Clear IO
        io.ClearInputKeys();
    }
}

Try clearing your IO state when losing focus in your application, so that would be your isRightClicked variable in AppWindow.cpp.

fcturan20 commented 1 year ago

It didn't work out for me. The problem seems to be event queue isn't clearing its elements. Event queue element count keeps increasing even though i clear them using pop().