Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL3 Examples source code cannot be copied with Ctrl-C #12308

Open
rongcuid opened this issue Feb 17, 2025 · 6 comments
Open

SDL3 Examples source code cannot be copied with Ctrl-C #12308

rongcuid opened this issue Feb 17, 2025 · 6 comments
Assignees
Milestone

Comments

@rongcuid
Copy link

The example website's source code can only be copied with right click, not Ctrl-C (or Cmd-C on macs).

@icculus
Copy link
Collaborator

icculus commented Feb 17, 2025

I think this happens because the SDL app--specifically the canvas element, I assume--is stealing the keyboard input. You also can't bring up the developer console with F12 unless you click on the address bar first to break the keyboard focus.

We might be able to do some javascript magic in the examples to steal keyboard focus when the source code and console tabs pop up, and provide it back to the canvas when they pop back down, but I have not researched this at all.

@icculus
Copy link
Collaborator

icculus commented Feb 17, 2025

Moving this from sdlwiki to SDL, because fixes would happen in there.

@icculus icculus transferred this issue from libsdl-org/sdlwiki Feb 17, 2025
@icculus icculus self-assigned this Feb 17, 2025
@icculus icculus added this to the 3.2.6 milestone Feb 17, 2025
@rongcuid
Copy link
Author

Do you think looking at Raylib's site helps? Their example works with browsers better.

@icculus
Copy link
Collaborator

icculus commented Feb 21, 2025

Hmm. @Daft-Freak, how important is it that we grab the keyboard input by default? Compare:

https://www.raylib.com/examples/core/loader.html?name=core_basic_screen_manager

vs

https://examples.libsdl.org/SDL3/renderer/01-clear/

...and are we grabbing input too aggressively? Even when Raylib is taking keyboard input after clicking on the canvas, it still lets me use F12 to bring up the developer tools in Firefox.

@Daft-Freak
Copy link
Collaborator

I think it was all about keyboard events working by default? (I mostly remember that getting keyboard handling to where it is took a while, and a lot of fixing one usecase breaking another.)

If you only listen for keyboard events on the canvas (like by using the hint) then you need to add some JS to give the canvas focus.

F12 (or any of the f-keys) is one of the keys we make sure to preventDefault on so the browser doesn't do unexpected things. Though generally we don't know what keys the user might want to handle, so we assume ALL of them. (Can override this with an event filter... I think)

@icculus
Copy link
Collaborator

icculus commented Feb 21, 2025

Mmm, I might revisit this and see if we can at least have a convenient way for the examples to be less grabby without adding code to the apps themselves (maybe force a hint in template.html's startup JavaScript, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants