macOS per-document input sources

I’m trying to investigate an SDL app’s (TIC-80, but I also noticed this happens in MilkyTracker) behavior with the “Automatically switch to a document’s input source” setting in macOS.

This setting normally makes macOS remember which input source (keyboard layout) was previously used in which window, and then automatically switch the current input source based on which window is currently active.

I’ve found that for these SDL apps, switching to it from a different app doesn’t cause the keyboard layout to get automatically switched like other apps behave. Instead, the layout just stays on whatever the previous window was using. It’s very hard to find any information about this macOS feature online, so I’m wondering if this requires the app to do some special macOS magic to make it work, or if it’s some kind of SDL bug?

This is probably something that requires using the OS-provided UI text entry mechanisms, like NSTextField or NSTextView. It might even require that it be an actual “Document” app, which has more stuff and gets special treatment / extra help from the operating system compared to a plain macOS app.

SDL just handles the keyboard input events (which is done at a much lower level) and passes them to the application.

I wondered about that, but I found that the automatic keyboard layout switching also works as expected in apps such as e.g. Minecraft, Wine (any Windows apps), Blender, Renoise, which are clearly not using a macOS text field widget (or any macOS UI toolkit feature for that matter) for any keyboard input.

The same setting used to be called something different not involving “documents” in earlier versions of macOS, but I can’t remember what that was. (The equivalent feature in Gnome is just called per-window, which makes more sense to me.)

1 Like