From a9819e9865dc8d45e494ead7f9d370a3bb9147f6 Mon Sep 17 00:00:00 2001 From: scuti Date: Sun, 26 Jan 2025 11:24:43 -0800 Subject: [PATCH] Created hotkey to grab and release mouse. Addresses #6790 --- binaries/data/config/default.cfg | 1 + binaries/data/mods/public/gui/hotkeys/spec/engine.json | 4 ++++ source/main.cpp | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index 22f05819ec..0f1573d6b4 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -205,6 +205,7 @@ togglefullscreen = "Alt+Return" ; Toggle fullscreen/windowed mode screenshot.watermark = "Alt+K" ; Toggle product/company watermark for official screenshots wireframe = "Alt+Shift+W" ; Toggle wireframe mode silhouettes = "Alt+Shift+S" ; Toggle unit silhouettes +mousegrabtoggle = "Ctrl+Alt" ; Toggle mouse grabbing mode ; > DIALOG HOTKEYS summary = "Ctrl+Tab" ; Toggle in-game summary diff --git a/binaries/data/mods/public/gui/hotkeys/spec/engine.json b/binaries/data/mods/public/gui/hotkeys/spec/engine.json index 20b29ccf9d..08531e4059 100644 --- a/binaries/data/mods/public/gui/hotkeys/spec/engine.json +++ b/binaries/data/mods/public/gui/hotkeys/spec/engine.json @@ -102,6 +102,10 @@ "text.move.right": { "name": "Move cursor to right word", "desc": "Move cursor to start of word to the right of cursor." + }, + "mousegrabtoggle": { + "name": "Toggle mouse grab", + "desc": "Constrain to window boundaries or release the mouse." } } } diff --git a/source/main.cpp b/source/main.cpp index bc00fd4a66..bd0c648510 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -244,6 +244,12 @@ static InReaction MainInputHandler(const SDL_Event_* ev) g_Profiler2.Toggle(); return IN_HANDLED; } + else if (hotkey == "mousegrabtoggle") + { + SDL_Window* const window{g_VideoMode.GetWindow()}; + const SDL_bool willGrabMouse{SDL_GetWindowGrab(window) ? SDL_FALSE : SDL_TRUE}; + SDL_SetWindowGrab(window, willGrabMouse); + } break; }