OpenFodder / openfodder

Open Fodder: An open source port of Cannon Fodder
http://openfodder.com
GNU General Public License v3.0
459 stars 42 forks source link

Lock cursor to window does not toggle #93

Closed WickedSmoke closed 1 day ago

WickedSmoke commented 1 month ago

When the --alternate-mouse option is used pressing F12 will lock the cursor, but pressing the key again does not unlock the cursor. The lock toggle works without that option.

This occurs when running 1.9.2 built on Fedora 37.

WickedSmoke commented 1 month ago

Here's a patch I'm using to get this working:

diff --git a/Source/Fodder.cpp b/Source/Fodder.cpp
index 77b4ca0..d8cebe8 100644
--- a/Source/Fodder.cpp
+++ b/Source/Fodder.cpp
@@ -3132,9 +3132,13 @@ void cFodder::keyProcess(uint8 pKeyCode, bool pPressed) {
     if (pKeyCode == SDL_SCANCODE_F11 && pPressed)
         mWindow->ToggleFullscreen();

-    if (pKeyCode == SDL_SCANCODE_F12 && pPressed)
+    if (pKeyCode == SDL_SCANCODE_F12 && pPressed) {
         mParams->mMouseLocked = !mParams->mMouseLocked;

+        if (mStartParams->mMouseAlternative)
+            mWindow->SetRelativeMouseMode(mParams->mMouseLocked);
+    }
+
     if (pKeyCode == SDL_SCANCODE_ESCAPE && pPressed && mPhase_Aborted)
         mPhase_Aborted2 = true;
segrax commented 1 day ago

Hey @WickedSmoke,

Thanks for the report,

This must be a regression, I don't believe mouse-lock was intended (or tested?) for alternative mouse mode, But I see the issue, relative mode is set when the Window is created, which was a 'recent' change...

Thanks for the patch, have applied it as well as added a check on window creation for alternative mouse mode