Compare commits

...

2 commits

Author SHA1 Message Date
151afec7f0 Fix app context lifetime in emscripten
All checks were successful
Run tests / Run tests (push) Successful in 7m49s
2026-07-04 16:31:34 +03:00
abf45f3dcb Fix handling key events (this also intercepts browser shortcuts, sadly) 2026-07-04 16:30:44 +03:00
3 changed files with 6 additions and 5 deletions

View file

@ -20,6 +20,7 @@
{
std::unique_ptr<psemek::app::application> application;
std::unique_ptr<psemek::sdl2::window> window;
psemek::app::application::context context;
} em_state;
#endif
@ -59,7 +60,11 @@ int main(int argc, char ** argv) try
sdl2::window window(options);
#endif
#ifdef __EMSCRIPTEN__
auto & context = em_state.context;
#else
app::application::context context;
#endif
for (int i = 0; i < argc; ++i)
context.args.push_back(argv[i]);
context.show_cursor = [&](bool show){ window.show_cursor(show); };

View file

@ -22,10 +22,6 @@ namespace psemek::sdl2
window::window(psemek::app::application::options const & options)
{
#ifdef __EMSCRIPTEN__
SDL_SetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT, "#canvas");
#endif
sdl_init_ = init(SDL_INIT_EVENTS | SDL_INIT_VIDEO);
std::uint32_t flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE;

View file

@ -8,7 +8,7 @@
</style>
</head>
<body>
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<canvas id="canvas" tabindex="-1" oncontextmenu="event.preventDefault()"></canvas>
<script type="text/javascript">
var Module = {
canvas: document.getElementById('canvas'),