From a6f79959c0f8e626e3b67df1605f8fc4fec2bfba Mon Sep 17 00:00:00 2001 From: Katajisto Date: Sat, 17 Oct 2026 09:03:50 +0300 Subject: [PATCH] improve mouse cursor locking --- modules/Input/module.jai | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/Input/module.jai b/modules/Input/module.jai index 3c0c68c..0076948 100644 --- a/modules/Input/module.jai +++ b/modules/Input/module.jai @@ -6,6 +6,7 @@ #scope_file shouldLockMouseCursor : bool = false; +cursorCurrentlyLocked : bool = false; #scope_export; set_should_lock_cursor :: (shouldLock: bool) { @@ -17,12 +18,16 @@ is_cursor_locked :: () -> bool { } unlock_cursor :: () { + cursorCurrentlyLocked = false; plat_set_cursor_lock(false); } // We use this so menu and editor is unlocked and game is locked if the game sets the should lock. lock_cursor_if_should :: () { - if shouldLockMouseCursor then plat_set_cursor_lock(true); + if shouldLockMouseCursor { + plat_set_cursor_lock(true); + cursorCurrentlyLocked = true; + } } @@ -248,6 +253,9 @@ input_per_frame_event_and_flag_update :: () { // Called once per frame, probably. for events_this_frame { + if it.key_code == .MOUSE_BUTTON_LEFT && it.key_pressed == 1 && cursorCurrentlyLocked { + plat_set_cursor_lock(true); + } allocator := it.files.allocator; // Same allocator for filenames and the array itself. for file: it.files {