SDL-emscripten icon indicating copy to clipboard operation
SDL-emscripten copied to clipboard

fix SDL_WINDOW_FULLSCREEN

Open gsathya opened this issue 10 years ago • 3 comments

Full screen needs to be requested on a user input action. library_sdl.js currently fakes it by checking on every keypress/mousemove to see if there is a need to go full screen and does it on the keypress/mousemove event. Do we want to do this? Is there a better way?

I'd be ok with just not doing this hack and have the user explicitly click on a button and then go full screen.

Also, write a test for this.

gsathya avatar Jun 28 '14 01:06 gsathya

Yeah, that is the way we need to handle this. We do not want to require developers to author web elements like buttons on the page to do pointerlock and fullscreen requests. The native Emscripten HTML5 api does the exact same thing with its "deferred" call architecture: https://github.com/kripken/emscripten/blob/master/src/library_html5.js#L60 and https://github.com/kripken/emscripten/blob/master/system/include/emscripten/html5.h#L48 .

You mention above that mousemove events would trigger deferred calls in SDL? If so, then that is not good, since mousemove is not a safe event where fullscreen & pointerlock requests can be made, browsers prohibit this. The safe events are mouse events (click, dblclick, down, up, not move), and touch events (touch down, up, not move), and key events (down, up), although in Internet Explorer, keyboard events are not accepted. Search for allowsdeferredcalls in Emscripten library_html5.js to see how it handles the decision of which events are ok to process deferred calls in, and which are not.

In the current implementation, the JS-implemented SDL1.2 and this SDL2 port have one limitation compared to the native HTML5 APIs: in the HTML5 API, user code is run as part of the event handler via the callback registration mechanism, so it is possible to perform the pointerlock and fullscreen requests immediately even without needing to defer. In SDL, events are polled in the main loop instead of processed immediately, which gives a problem that one will always need to defer.

To overcome this API problem with SDL, Michael Bishop added a new API extension to our SDL code: emscripten_SDL_SetEventHandler, which allows registering a callback to handle events, without having to poll. This API form allows user code to immediately perform fullscreen and pointerlock requests without ending up always deferring.

juj avatar Jul 09 '14 15:07 juj

https://github.com/kripken/emscripten/commit/b71f0def47d8ffbbaffcdaccba20713db5f0f5d1

juj avatar Jul 09 '14 15:07 juj

SDL2 has http://wiki.libsdl.org/SDL_SetEventFilter. Also SetWindowFullscreen is already implemented using the html5 api and seems to work(Ctrl+Enter in most of the tests). Creating a window fullscreen doesn't work though.

Daft-Freak avatar Aug 10 '14 10:08 Daft-Freak