I ended up doing my own canvas resize events
void send_window_resize_event(int w, int h)
{
SDL_Window *window = sys_get_window();
if(window == nullptr) return;
SDL_FlushEvent(SDL_WINDOWEVENT);
Common::Debug::Printf(Common::MessageType::kDbgMsg_Info,"Sent Resize %d, %d", w, h);
// SIZE_CHANGED is followed by RESIZED if the size was changed by an external event
SDL_WindowEvent* windowEvent_sz = new SDL_WindowEvent;
windowEvent_sz->windowID = SDL_GetWindowID(window);
windowEvent_sz->type = SDL_WINDOWEVENT;
windowEvent_sz->event = SDL_WINDOWEVENT_SIZE_CHANGED;
windowEvent_sz->data1 = w;
windowEvent_sz->data2 = h;
SDL_PushEvent(reinterpret_cast<SDL_Event *>(windowEvent_sz));
SDL_WindowEvent* windowEvent_rs = new SDL_WindowEvent;
windowEvent_rs->windowID = SDL_GetWindowID(window);
windowEvent_rs->type = SDL_WINDOWEVENT;
windowEvent_rs->event = SDL_WINDOWEVENT_RESIZED;
windowEvent_rs->data1 = w;
windowEvent_rs->data2 = h;
SDL_PushEvent(reinterpret_cast<SDL_Event *>(windowEvent_rs));
}
And then doing a size check per frame
double css_c_w = 0, css_c_h = 0;
emscripten_get_element_css_size("canvas", &css_c_w, &css_c_h);
int win_w = get_window_inner_width();
int win_h = get_window_inner_height();
if(WindowInnerSize.Width == win_w && WindowInnerSize.Height == win_h && win_w == (int) css_c_w && win_h == (int) css_c_h) return;
WindowInnerSize.Width = win_w;
WindowInnerSize.Height = win_h;
send_window_resize_event(win_w, win_h);
emscripten_set_canvas_element_size("canvas", win_w, win_h);
emscripten_set_element_css_size("canvas", WindowInnerSize.Width, WindowInnerSize.Height);
This fixed for the use case of the canvas being in an page where it needs to take either all the area available or all the area available of an iframe where the canvas is inside of it. And also screen rotation and mobile stuff.
I can’t though enable high-dpi either using this or without using this as both will make the canvas size grow indefinitely on each resize.
But without the code above, when the canvas goes out of fullscreen, it’s set to the size of the fullscreen still, which makes that, if the iframe aspect ratio doesn’t match the screen aspect ratio, lots of black bars to appear and the game to be squished.
I would love to be able to push resize events that make SDL do the actual resize instead of the way that I just get notifications later but have to handle the resize, because in this way I could at least fix the broken high-dpi for myself.