From 3fae02c7d342981c9910db7715305bc57b261a8b Mon Sep 17 00:00:00 2001 From: salmonik Date: Tue, 27 Oct 2026 18:09:19 +0100 Subject: GUI: allow movement while open; freeze look and block bind capture Feedback pass on the preview shell: - Freeze the rendered view explicitly in CreateMove and again at FRAME_RENDER_START; CInput was still letting mouse look move the camera. - Allow normal WASD/jump/duck movement while the GUI is open; strip attack/use/impulse/weapon selection so GUI clicks do not fire. - While bind capture is active, block all game input. - Esc no longer closes the GUI; it only cancels bind capture. F2 or the title-bar X close the preview. - Interpose SDL_ShowCursor / SDL_SetRelativeMouseMode / warp / window grab so the game cannot re-capture or hide the native cursor while the GUI is open. --- src/gui.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 6 deletions(-) (limited to 'src/gui.cpp') diff --git a/src/gui.cpp b/src/gui.cpp index 74dd537..923cd4d 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -879,12 +879,8 @@ void gui_handle_input() { return; } - if (esc_edge) { - if (g_capture_card >= 0) - g_capture_card = -1; - else - close_gui(); - } + if (esc_edge && g_capture_card >= 0) + g_capture_card = -1; // Keep the native cursor free even if the game re-grabs it. if (sd_set_relative) @@ -1196,4 +1192,92 @@ void gui_draw() { } bool gui_is_open() { return g_open; } +bool gui_bind_capture_active() { return g_open && g_capture_card >= 0; } QAngle gui_frozen_view() { return g_frozen; } + +// --------------------------------------------------------------------------- +// SDL cursor interposition +// --------------------------------------------------------------------------- +// The game re-asserts relative mouse mode / hides the cursor every frame. While +// the GUI is open, force the opposite so the native cursor stays usable. + +static int (*real_show_cursor)(int) = nullptr; +static int (*real_set_relative)(int) = nullptr; +static void (*real_warp_mouse)(void *, int, int) = nullptr; +static void (*real_set_grab)(void *, int) = nullptr; + +extern "C" __attribute__((visibility("default"))) int SDL_ShowCursor(int toggle) { + if (!real_show_cursor) + real_show_cursor = (int (*)(int))dlsym(RTLD_NEXT, "SDL_ShowCursor"); + if (g_open && toggle != -1) { + if (real_show_cursor) + real_show_cursor(1); + return 1; + } + return real_show_cursor ? real_show_cursor(toggle) : 0; +} + +extern "C" __attribute__((visibility("default"))) int +SDL_SetRelativeMouseMode(int enabled) { + if (!real_set_relative) + real_set_relative = + (int (*)(int))dlsym(RTLD_NEXT, "SDL_SetRelativeMouseMode"); + if (g_open) { + if (real_set_relative) + real_set_relative(0); + return 0; + } + return real_set_relative ? real_set_relative(enabled) : 0; +} + +extern "C" __attribute__((visibility("default"))) void +SDL_WarpMouseInWindow(void *window, int x, int y) { + if (!real_warp_mouse) + real_warp_mouse = + (void (*)(void *, int, int))dlsym(RTLD_NEXT, "SDL_WarpMouseInWindow"); + if (g_open) + return; + if (real_warp_mouse) + real_warp_mouse(window, x, y); +} + +extern "C" __attribute__((visibility("default"))) void +SDL_SetWindowGrab(void *window, int grabbed) { + if (!real_set_grab) + real_set_grab = + (void (*)(void *, int))dlsym(RTLD_NEXT, "SDL_SetWindowGrab"); + if (g_open) { + if (real_set_grab) + real_set_grab(window, 0); + return; + } + if (real_set_grab) + real_set_grab(window, grabbed); +} + +static void (*real_set_mouse_grab)(void *, int) = nullptr; +static void (*real_warp_global)(int, int) = nullptr; + +extern "C" __attribute__((visibility("default"))) void +SDL_SetWindowMouseGrab(void *window, int grabbed) { + if (!real_set_mouse_grab) + real_set_mouse_grab = + (void (*)(void *, int))dlsym(RTLD_NEXT, "SDL_SetWindowMouseGrab"); + if (g_open) { + if (real_set_mouse_grab) + real_set_mouse_grab(window, 0); + return; + } + if (real_set_mouse_grab) + real_set_mouse_grab(window, grabbed); +} + +extern "C" __attribute__((visibility("default"))) void +SDL_WarpMouseGlobal(int x, int y) { + if (!real_warp_global) + real_warp_global = (void (*)(int, int))dlsym(RTLD_NEXT, "SDL_WarpMouseGlobal"); + if (g_open) + return; + if (real_warp_global) + real_warp_global(x, y); +} -- cgit v1.2.3