From 4b180acee9a744c5ed23a5f584e8bc0b1ca6bc84 Mon Sep 17 00:00:00 2001 From: Slendi Date: Sat, 6 Dec 2025 20:16:53 +0200 Subject: [PATCH] Mouse capture Signed-off-by: Slendi --- src/Application.cpp | 7 +++++-- src/Application.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 5a97d18..0db1810 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -76,7 +76,7 @@ auto Application::run() -> void } else if (e.type == SDL_EVENT_KEY_DOWN && e.key.repeat == false) { if (e.key.key == SDLK_F11 && e.key.mod & SDL_KMOD_LCTRL) { mouse_captured(!mouse_captured()); - m_show_imgui = mouse_captured(); + m_show_imgui = !mouse_captured(); } } @@ -111,7 +111,10 @@ auto Application::run() -> void auto Application::mouse_captured(bool new_state) -> void { - SDL_CaptureMouse(new_state); + if (!SDL_SetWindowRelativeMouseMode(m_window, new_state)) { + m_logger.err("Failed to capture mouse"); + return; + } m_mouse_captured = new_state; } diff --git a/src/Application.h b/src/Application.h index fdcd2c9..6ae590c 100644 --- a/src/Application.h +++ b/src/Application.h @@ -17,6 +17,7 @@ struct Application { ~Application(); auto run() -> void; + auto mouse_captured(bool new_state) -> void; auto mouse_captured() const -> bool { return m_mouse_captured; } auto toggle_mouse_captured() -> void { mouse_captured(!m_mouse_captured); }