diff --git a/src/gui/sdl_mapper.cpp b/src/gui/sdl_mapper.cpp index 06b6cd7a..305f372d 100644 --- a/src/gui/sdl_mapper.cpp +++ b/src/gui/sdl_mapper.cpp @@ -2688,15 +2688,6 @@ void MAPPER_DisplayUI() { GFX_ResetScreen(); } -static void MAPPER_Init(Section *sec) { - (void) sec; // unused but present for API compliance - QueryJoysticks(); - if (buttons.empty()) - CreateLayout(); - if (bindgroups.empty()) - CreateBindGroups(); -} - static void MAPPER_Destroy(Section *sec) { (void) sec; // unused but present for API compliance @@ -2743,6 +2734,15 @@ void MAPPER_BindKeys() { //Release any keys pressed, or else they'll get stuck GFX_LosingFocus(); + QueryJoysticks(); + + // Create the graphical layout for all registered key-binds + if (buttons.empty()) + CreateLayout(); + + if (bindgroups.empty()) + CreateBindGroups(); + // Create binds from file or fallback to internals if (!MAPPER_CreateBindsFromFile()) CreateDefaultBinds(); @@ -2778,11 +2778,18 @@ void MAPPER_AutoType(std::vector &sequence, } // Activate user-specified or default binds -static void MAPPER_LoadFile(Section *sec) { +static void MAPPER_ConfigureBindings(Section *sec) { + (void) sec; // unused but present for API compliance Section_prop const *const section=static_cast(sec); Prop_path const *const pp = section->Get_path("mapperfile"); mapper.filename = pp->realpath; + /* Because the mapper is initialized before several other of DOSBox's + * submodules have a chance to register their key bindings, we defer + * the mapper's setup and instead manully BindKeys() in SDL main only + * after -all- subsystems have been initialized, which ensures that all + * binding a present, and thus are also layed out in the mapper's GUI. + */ static bool init_phase = true; if (init_phase) { init_phase = false; @@ -2794,11 +2801,8 @@ static void MAPPER_LoadFile(Section *sec) { void MAPPER_StartUp(Section * sec) { Section_prop * section = static_cast(sec); - //runs one-time on startup - section->AddInitFunction(&MAPPER_Init, false); - //runs after this function ends and for subsequent config -set "sdl mapperfile=file.map" commands - section->AddInitFunction(&MAPPER_LoadFile, true); + section->AddInitFunction(&MAPPER_ConfigureBindings, true); // runs one-time on shutdown section->AddDestroyFunction(&MAPPER_Destroy, false); diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 1f3b0091..fb020d6a 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -3245,9 +3245,8 @@ int main(int argc, char* argv[]) { } } - // Apply key bindings only after all subsystems have added them - MAPPER_BindKeys(); - // With the default key binds in place, render the mapper UI if requested + MAPPER_BindKeys(); // All subsystem handlers need to be + // registered at this point to be mappable. if (control->cmdline->FindExist("-startmapper")) MAPPER_DisplayUI();