Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
shell: allow keyboard refocus when embedded in an iframe #7631
On sites such as itch.io, the game area is embedded in an iframe.
#7484 does not help in that case: clicking on the canvas doesn't change the focus. For a SDL2 application, finding a bit of non-canvas document area to click on is a work-around, but not suitable if the canvas auto-adjusts to the document area.
I added 2 custom events to the canvas to fix keyboard focus:
This is an issue that is common on such websites, and tricky to identify and fix, hence why I submit it here. If this is too specific, let me know if there's an other way to address this issue :)
I may be missing something here - I can't reproduce that behavior in a testcase. For example, in
Then clicking on the canvas in the iframe does focus the element as I would expect. Is this testcase different from what you are seeing in a crucial way?
The difference appears to come from SDL2 and handling mouse events (default), which can be simulated in your test case with:
e.preventDefault() is used in a lot of SDL2 event handlers
Still with e.preventDefault:
Note that in this configuration, document.activeElement is "body" at all times.
This is messier than I initially though, I'm not sure adding a counter-handler is a clean fix.
Thanks, yeah, makes sense
What I think maybe we should do is that in such handlers that