emscripten: install a callback for visibility changes

Fixes an issue where focus blur event was being dispatched only after
the game has been focused again.
This commit is contained in:
Sebastian Krzyszkowiak 2019-01-08 04:57:30 +01:00
parent 2ad77b071f
commit f07b075052
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 8 additions and 0 deletions

View file

@ -384,6 +384,12 @@ SYMBOL_INTERNAL void libsuperderpy_emscripten_mainloop(void* game) {
emscripten_cancel_main_loop();
}
}
SYMBOL_INTERNAL EM_BOOL libsuperderpy_emscripten_visibility_change(int eventType, const EmscriptenVisibilityChangeEvent* visibilityChangeEvent, void* game) {
libsuperderpy_emscripten_mainloop(game);
return false;
}
#endif
SYMBOL_EXPORT int libsuperderpy_run(struct Game* game) {
@ -392,6 +398,7 @@ SYMBOL_EXPORT int libsuperderpy_run(struct Game* game) {
return ret;
}
#ifdef __EMSCRIPTEN__
emscripten_set_visibilitychange_callback(game, false, libsuperderpy_emscripten_visibility_change);
emscripten_set_main_loop_arg(libsuperderpy_emscripten_mainloop, game, 0, true);
return 0;
#else

View file

@ -63,6 +63,7 @@ struct GamestateResources;
#include <allegro5/allegro_iphone.h>
#elif defined(__EMSCRIPTEN__)
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
#endif
#include "character.h"