em-dosbox icon indicating copy to clipboard operation
em-dosbox copied to clipboard

Trying to manually control pointerlock

Open jbaicoianu opened this issue 8 years ago • 2 comments
trafficstars

I'm trying to use em-dosbox in a situation where I want to be able to manually enable or disable pointerlock when a system is in use. I'm embedding this into another app which has its own pointerlock handling, so I'd like to only lock to the em-dosbox canvas element when it's been clicked directly, or focused in code.

It seems that as it is now, either em-dosbox or emscripten itself is calling emscripten_request_pointerlock() in response to keydown events, regardless of what I try to do to restrict mouse capture.

Things I've tried so far:

  • ENV['SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT'] = '#canvas';
  • Module.elementPointerLock = true (tried false too, no difference)
  • autolock=false in the [SDL] section of dosbox.conf

I looked into the code to try to trace this, I see two possible places which could be triggering it: https://github.com/dreamlayers/em-dosbox/blob/1f46d1ddf0a7893f52f6da7e24a968bb02aa97ad/src/gui/sdlmain.cpp#L1213-L1225

which is called from several places, but I wonder if https://github.com/dreamlayers/em-dosbox/blob/1f46d1ddf0a7893f52f6da7e24a968bb02aa97ad/src/gui/sdlmain.cpp#L1279-L1289 is causing issues, for example, if I already have the pointer locked when the emscripten module boots, when I exit from my own app's pointerlock, maybe this is triggering?

The other place that looks suspicious is Emscripten's deferred fullscreen/pointerlock requesting code, https://github.com/kripken/emscripten/blob/master/src/library_html5.js#L69-L97 - this queues up any requests to requestPointerLock() which may have happened and forces them to be executed on a qualifying user interaction event. So it's possible some code somewhere is requesting pointerlock and it's not being applied until I start trying to press keys (in this case, WASD to move around my virtual world)

Any hints on how to disable the built-in pointerlock logic and handle it myself?

jbaicoianu avatar Mar 25 '17 16:03 jbaicoianu

I can't reproduce this. I can click, get pointer lock, break it with the escape key or with setTimeout(function(){ document.exitPointerLock(); }, 3000); and then press keys without re-establishing pointer lock.

After looking at my code I do have some doubts about GFX_CaptureMouse() correctness. It may have some unexpected side effects via SDL calls in doGFX_CaptureMouse() or due to differences between sdl.mouse.locked and the real mouse capture state. Though there's nothing trying to capture the mouse in response to keyboard key events.

I guess what you describe might be happening due to focus changes? I'm just guessing because I can't reproduce this.

dreamlayers avatar Mar 26 '17 02:03 dreamlayers

Hmm. I'll play around with it and see if it's something the loader or something else on my end is doing, I'll set up a simplified test case and let you know.

jbaicoianu avatar Mar 26 '17 05:03 jbaicoianu