diff --git a/src/core.c b/src/core.c index 737d2935..91ce0ca3 100644 --- a/src/core.c +++ b/src/core.c @@ -406,9 +406,7 @@ typedef struct CoreData { bool cursorHidden; // Track if cursor is hidden bool cursorOnScreen; // Tracks if cursor is inside client area -#if defined(PLATFORM_WEB) - bool cursorLockRequired; // Ask for cursor pointer lock on next click -#endif + char currentButtonState[3]; // Registers current mouse button state char previousButtonState[3]; // Registers previous mouse button state int currentWheelMove; // Registers current mouse wheel variation @@ -1301,9 +1299,6 @@ void EnableCursor(void) #if defined(PLATFORM_DESKTOP) glfwSetInputMode(CORE.Window.handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL); #endif -#if defined(PLATFORM_WEB) - CORE.Input.Mouse.cursorLockRequired = true; -#endif #if defined(PLATFORM_UWP) UWPGetMouseUnlockFunc()(); #endif @@ -1316,9 +1311,6 @@ void DisableCursor(void) #if defined(PLATFORM_DESKTOP) glfwSetInputMode(CORE.Window.handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED); #endif -#if defined(PLATFORM_WEB) - CORE.Input.Mouse.cursorLockRequired = true; -#endif #if defined(PLATFORM_UWP) UWPGetMouseLockFunc()(); #endif @@ -4226,20 +4218,19 @@ static EM_BOOL EmscriptenKeyboardCallback(int eventType, const EmscriptenKeyboar static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) { // Lock mouse pointer when click on screen - if ((eventType == EMSCRIPTEN_EVENT_CLICK) && CORE.Input.Mouse.cursorLockRequired) + if ((eventType == EMSCRIPTEN_EVENT_CLICK)) { EmscriptenPointerlockChangeEvent plce; emscripten_get_pointerlock_status(&plce); + + int result = emscripten_request_pointerlock("#canvas", 1); // TODO: It does not work! + + // result -> EMSCRIPTEN_RESULT_DEFERRED + // The requested operation cannot be completed now for web security reasons, + // and has been deferred for completion in the next event handler. --> but it never happens! - if (!plce.isActive) emscripten_request_pointerlock(0, 1); - else - { - emscripten_exit_pointerlock(); - emscripten_get_pointerlock_status(&plce); - //if (plce.isActive) TRACELOG(LOG_WARNING, "Pointer lock exit did not work!"); - } - - CORE.Input.Mouse.cursorLockRequired = false; + //if (!plce.isActive) emscripten_request_pointerlock(0, 1); + //else emscripten_exit_pointerlock(); } return 0;