Closed astrochili closed 1 year ago
Scroll events are really not accepted here, this is the key.
https://user-images.githubusercontent.com/4752473/167246008-c64fb92d-deb6-46f8-b187-26a2e134ed47.mov
Is it possible to lock the cursor in the center of the window instead of the top right corner? 🙂
The problem is inside of the Defold engine, i.e. the engine uses outdated version of GLFW, 2.7 plus extra changes and additions from the Defold team. From my view, this version of GLFW doesn't fully take into account some specific things introduced in the latest macOS releases like HiDPI.
I looked into GLFW sources, and I see that it tries to center mouse cursor after enabling of mouse lock - https://github.com/defold/defold/blob/1ae302ec33d4514408c04ad3ae5d3c1efe2057bd/engine/glfw/lib/enable.c#L90
// Move cursor to the middle of the window
_glfwPlatformSetMouseCursorPos( _glfwWin.width >> 1,
_glfwWin.height >> 1 );
Cocoa coordinate system has origin at lower left. It seems that _glfwPlatformSetMouseCursorPos() doesn't convert coords to HiDPI equivalent or something like that (there are system functions convertPointToBacking
and convertPointFromBacking
). It's the reason why mouse cursor appears in the top right corner.
Thank you for the explanation.
I think an another way is to use the native implantation as defos uses. I haven't tried it yet, but it might be worth it.
I think an another way is to use the native implantation as defos uses. I haven't tried it yet, but it might be worth it.
I prefer the way of fixing the issue in the Defold sources 😀
Sure I think so too! 😄 Is there issue for Defold?
Sure I think so too! 😄 Is there issue for Defold?
I was thinking about how to do that properly, i.e. what kind of issue should be made. The reason is that this extension uses non-exposed GLFW functions to enable/disable mouse lock on Linux/Windows/macOS and it's strange if we tell Defold developers that it doesn't work properly on HiDPi macOS displays.
So, there should be two issues:
Something like that 🤔
to be entirely honest i'm surprised pointer lock hasn't become a part of defold core by now, but that keeps things the way they are which is as always just about good enough for most. is there any update with this issue? i notice it has past many months no news. thank you!
Fixed in Defold 1.3.7 BETA
On macOS the cursor is locked on the top right corner and there are some problems.
1) Moving the mouse upwards causes the window title bar to pop up in full screen mode, this is normal macOS behaviour on the top edge of the screen. Same with moving from right to left - if you move hard enough, the system sidebar opens 😀. 2) Mouse wheel events are no longer accepted after the cursor locking. I think this is also due to the cursor position going out of the window content but I'm not sure.
Is it possible to lock the cursor in the center of the window instead of the top right corner? 🙂
https://user-images.githubusercontent.com/4752473/167244759-01ccea65-1970-4649-a041-1ca2c2c3427f.mov