summaryrefslogtreecommitdiffstats
path: root/src/gui.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gui.cpp96
1 files changed, 90 insertions, 6 deletions
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() {
879 return; 879 return;
880 } 880 }
881 881
882 if (esc_edge) { 882 if (esc_edge && g_capture_card >= 0)
883 if (g_capture_card >= 0) 883 g_capture_card = -1;
884 g_capture_card = -1;
885 else
886 close_gui();
887 }
888 884
889 // Keep the native cursor free even if the game re-grabs it. 885 // Keep the native cursor free even if the game re-grabs it.
890 if (sd_set_relative) 886 if (sd_set_relative)
@@ -1196,4 +1192,92 @@ void gui_draw() {
1196} 1192}
1197 1193
1198bool gui_is_open() { return g_open; } 1194bool gui_is_open() { return g_open; }
1195bool gui_bind_capture_active() { return g_open && g_capture_card >= 0; }
1199QAngle gui_frozen_view() { return g_frozen; } 1196QAngle gui_frozen_view() { return g_frozen; }
1197
1198// ---------------------------------------------------------------------------
1199// SDL cursor interposition
1200// ---------------------------------------------------------------------------
1201// The game re-asserts relative mouse mode / hides the cursor every frame. While
1202// the GUI is open, force the opposite so the native cursor stays usable.
1203
1204static int (*real_show_cursor)(int) = nullptr;
1205static int (*real_set_relative)(int) = nullptr;
1206static void (*real_warp_mouse)(void *, int, int) = nullptr;
1207static void (*real_set_grab)(void *, int) = nullptr;
1208
1209extern "C" __attribute__((visibility("default"))) int SDL_ShowCursor(int toggle) {
1210 if (!real_show_cursor)
1211 real_show_cursor = (int (*)(int))dlsym(RTLD_NEXT, "SDL_ShowCursor");
1212 if (g_open && toggle != -1) {
1213 if (real_show_cursor)
1214 real_show_cursor(1);
1215 return 1;
1216 }
1217 return real_show_cursor ? real_show_cursor(toggle) : 0;
1218}
1219
1220extern "C" __attribute__((visibility("default"))) int
1221SDL_SetRelativeMouseMode(int enabled) {
1222 if (!real_set_relative)
1223 real_set_relative =
1224 (int (*)(int))dlsym(RTLD_NEXT, "SDL_SetRelativeMouseMode");
1225 if (g_open) {
1226 if (real_set_relative)
1227 real_set_relative(0);
1228 return 0;
1229 }
1230 return real_set_relative ? real_set_relative(enabled) : 0;
1231}
1232
1233extern "C" __attribute__((visibility("default"))) void
1234SDL_WarpMouseInWindow(void *window, int x, int y) {
1235 if (!real_warp_mouse)
1236 real_warp_mouse =
1237 (void (*)(void *, int, int))dlsym(RTLD_NEXT, "SDL_WarpMouseInWindow");
1238 if (g_open)
1239 return;
1240 if (real_warp_mouse)
1241 real_warp_mouse(window, x, y);
1242}
1243
1244extern "C" __attribute__((visibility("default"))) void
1245SDL_SetWindowGrab(void *window, int grabbed) {
1246 if (!real_set_grab)
1247 real_set_grab =
1248 (void (*)(void *, int))dlsym(RTLD_NEXT, "SDL_SetWindowGrab");
1249 if (g_open) {
1250 if (real_set_grab)
1251 real_set_grab(window, 0);
1252 return;
1253 }
1254 if (real_set_grab)
1255 real_set_grab(window, grabbed);
1256}
1257
1258static void (*real_set_mouse_grab)(void *, int) = nullptr;
1259static void (*real_warp_global)(int, int) = nullptr;
1260
1261extern "C" __attribute__((visibility("default"))) void
1262SDL_SetWindowMouseGrab(void *window, int grabbed) {
1263 if (!real_set_mouse_grab)
1264 real_set_mouse_grab =
1265 (void (*)(void *, int))dlsym(RTLD_NEXT, "SDL_SetWindowMouseGrab");
1266 if (g_open) {
1267 if (real_set_mouse_grab)
1268 real_set_mouse_grab(window, 0);
1269 return;
1270 }
1271 if (real_set_mouse_grab)
1272 real_set_mouse_grab(window, grabbed);
1273}
1274
1275extern "C" __attribute__((visibility("default"))) void
1276SDL_WarpMouseGlobal(int x, int y) {
1277 if (!real_warp_global)
1278 real_warp_global = (void (*)(int, int))dlsym(RTLD_NEXT, "SDL_WarpMouseGlobal");
1279 if (g_open)
1280 return;
1281 if (real_warp_global)
1282 real_warp_global(x, y);
1283}