window: hide mouse cursor on controller input for windowed mode

This commit is contained in:
Hyper 2024-11-23 20:22:36 +00:00
parent e3f7eba9a6
commit ff79eae6c4

View file

@ -81,7 +81,7 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
case SDL_WINDOWEVENT_FOCUS_GAINED:
Window::s_isFocused = true;
SDL_ShowCursor(SDL_DISABLE);
SDL_ShowCursor(Window::IsFullscreen() ? SDL_DISABLE : SDL_ENABLE);
break;
case SDL_WINDOWEVENT_RESTORED:
@ -114,6 +114,20 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
}
}
if (!Window::IsFullscreen())
{
if (event->type == SDL_CONTROLLERBUTTONDOWN || event->type == SDL_CONTROLLERBUTTONUP || event->type == SDL_CONTROLLERAXISMOTION)
{
// Hide mouse cursor when controller input is detected.
SDL_ShowCursor(SDL_DISABLE);
}
else if (event->type == SDL_MOUSEMOTION)
{
// Restore mouse cursor when mouse input is detected.
SDL_ShowCursor(SDL_ENABLE);
}
}
for (auto listener : Window::s_eventListeners)
listener->OnSDLEvent(event);
@ -150,6 +164,9 @@ void Window::Init()
s_pWindow = SDL_CreateWindow("SWA", s_x, s_y, s_width, s_height, GetWindowFlags());
if (IsFullscreen())
SDL_ShowCursor(SDL_DISABLE);
SetIcon();
SetTitle();
SDL_SetWindowMinimumSize(s_pWindow, 640, 480);