浏览代码

Remove automatic pointer lock on mouse click #1513

Ray 4 年之前
父节点
当前提交
721768bdb0
共有 1 个文件被更改,包括 7 次插入11 次删除
  1. 7 11
      src/core.c

+ 7 - 11
src/core.c

@@ -1738,6 +1738,9 @@ void EnableCursor(void)
 #if defined(PLATFORM_DESKTOP)
     glfwSetInputMode(CORE.Window.handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
 #endif
+#if defined(PLATFORM_WEB)
+    emscripten_exit_pointerlock();
+#endif
 #if defined(PLATFORM_UWP)
     UWPGetMouseUnlockFunc()();
 #endif
@@ -1750,6 +1753,9 @@ void DisableCursor(void)
 #if defined(PLATFORM_DESKTOP)
     glfwSetInputMode(CORE.Window.handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
 #endif
+#if defined(PLATFORM_WEB)
+    emscripten_request_pointerlock("#canvas", 1);
+#endif
 #if defined(PLATFORM_UWP)
     UWPGetMouseLockFunc()();
 #endif
@@ -5092,17 +5098,7 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent
     // Lock mouse pointer when click on screen
     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();
+        // TODO: Manage mouse events if required (note that GLFW JS wrapper manages it now)
     }
 
     return 0;