From ff79eae6c420e02b5ee648c6b555b806c962f706 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Sat, 23 Nov 2024 20:22:36 +0000 Subject: [PATCH] window: hide mouse cursor on controller input for windowed mode --- UnleashedRecomp/ui/window.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/UnleashedRecomp/ui/window.cpp b/UnleashedRecomp/ui/window.cpp index 7e660ffe..420b81e8 100644 --- a/UnleashedRecomp/ui/window.cpp +++ b/UnleashedRecomp/ui/window.cpp @@ -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);