Return-To-The-Roots / s25client

Return To The Roots (Settlers II(R) Clone)
http://www.rttr.info
GNU General Public License v2.0
470 stars 75 forks source link

Alt+q not working in game anymore #1583

Open ottml opened 1 year ago

ottml commented 1 year ago

Press alt+q in the game. Nothing happens. The following window should be shown. grafik

Flamefire commented 1 year ago

I can confirm this. This seems be caused by SDL2 being able to handle ALT-codes. E.g. pressing ALT+1 gives not a 1

So we don't get a SDL_TEXTINPUT event when ALT is pressed. We could manually make it handle letters when ALT is pressed but I fear this may lead to duplicate input events on systems where pressing ALT doesn't disable the textinput mode/waits for combined characters.

Flow86 commented 1 year ago

So is this a bug of SDL 2.26.4 then? Can someone try 2.26.5 (which is now available) if its fixed there? If so, I will update the toolchain again.

Flamefire commented 1 year ago

No this is not a bug, it's a feature. We react on text-input events and SDL doesn't give us text until there is text. We could react on key-down events but that would not give us text in some cases. We can only have either Unicode text input or (raw) key press events and we want the former, except for rare cases where we use ALT+key as a combo. So far I've seen that for ALT+q (open quit-window) and ALT+w (close active window) in our usage.

I don't really see a solution here that will always work. We could test if ALT+letter-key produces a text input event on any system and if it does not we can react on keydown events when ALT and a letter-key is pressed as-if it was a text-input event.

This is actually a limitation of our extra abstraction over SDL: If we'd used SDL directly we are supposed to switch between text mode and "raw" mode depending on the context. I.e. if the cursor is in a text-control we'd enable text-mode and only react on textinput events and otherwise only react on keydown events. But our abstraction only has keydown in the interface so we can't "switch" between those modes and have to choose one.