Load key bind defaults before loading the config, fixes saved key binds across emulator closures and reopenings.
This commit is contained in:
15
src/86box.c
15
src/86box.c
@@ -1000,6 +1000,13 @@ usage:
|
||||
zip_global_init();
|
||||
mo_global_init();
|
||||
|
||||
/* Initialize the keyboard accelerator list with default values */
|
||||
for (int x = 0; x < NUM_ACCELS; x++) {
|
||||
strcpy(acc_keys[x].name, def_acc_keys[x].name);
|
||||
strcpy(acc_keys[x].desc, def_acc_keys[x].desc);
|
||||
strcpy(acc_keys[x].seq, def_acc_keys[x].seq);
|
||||
}
|
||||
|
||||
/* Load the configuration file. */
|
||||
config_load();
|
||||
|
||||
@@ -1030,14 +1037,6 @@ usage:
|
||||
|
||||
gdbstub_init();
|
||||
|
||||
// Initialize the keyboard accelerator list with default values
|
||||
for(int x=0;x<NUM_ACCELS;x++) {
|
||||
strcpy(acc_keys[x].name, def_acc_keys[x].name);
|
||||
strcpy(acc_keys[x].desc, def_acc_keys[x].desc);
|
||||
strcpy(acc_keys[x].seq, def_acc_keys[x].seq);
|
||||
}
|
||||
|
||||
|
||||
/* All good! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
54
src/config.c
54
src/config.c
@@ -1772,23 +1772,22 @@ load_keybinds(void)
|
||||
char temp[512];
|
||||
memset(temp, 0, sizeof(temp));
|
||||
|
||||
// Now load values from config
|
||||
for(int x=0;x<NUM_ACCELS;x++)
|
||||
{
|
||||
p = ini_section_get_string(cat, acc_keys[x].name, "none");
|
||||
// If there's no binding in the file, leave it alone.
|
||||
if (strcmp(p, "none") != 0)
|
||||
{
|
||||
// It would be ideal to validate whether the user entered a
|
||||
// valid combo at this point, but the Qt method for testing that is
|
||||
// not available from C. Fortunately, if you feed Qt an invalid
|
||||
// keysequence string it just assigns nothing, so this won't blow up.
|
||||
// However, to improve the user experience, we should validate keys
|
||||
// and erase any bad combos from config on mainwindow load.
|
||||
|
||||
strcpy(acc_keys[x].seq, p);
|
||||
}
|
||||
}
|
||||
/* Now load values from config */
|
||||
for (int x = 0; x < NUM_ACCELS; x++) {
|
||||
p = ini_section_get_string(cat, acc_keys[x].name, "none");
|
||||
/* If there's no binding in the file, leave it alone. */
|
||||
if (strcmp(p, "none") != 0) {
|
||||
/*
|
||||
It would be ideal to validate whether the user entered a
|
||||
valid combo at this point, but the Qt method for testing that is
|
||||
not available from C. Fortunately, if you feed Qt an invalid
|
||||
keysequence string it just assigns nothing, so this won't blow up.
|
||||
However, to improve the user experience, we should validate keys
|
||||
and erase any bad combos from config on mainwindow load.
|
||||
*/
|
||||
strcpy(acc_keys[x].seq, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Load the specified or a default configuration file. */
|
||||
@@ -1892,7 +1891,7 @@ config_load(void)
|
||||
#ifndef USE_SDL_UI
|
||||
load_gl3_shaders(); /* GL3 Shaders */
|
||||
#endif
|
||||
load_keybinds(); /* Load shortcut keybinds */
|
||||
load_keybinds(); /* Load shortcut keybinds */
|
||||
|
||||
/* Migrate renamed device configurations. */
|
||||
c = ini_find_section(config, "MDA");
|
||||
@@ -2524,16 +2523,13 @@ save_keybinds(void)
|
||||
{
|
||||
ini_section_t cat = ini_find_or_create_section(config, "Keybinds");
|
||||
|
||||
for(int x=0;x<NUM_ACCELS;x++)
|
||||
{
|
||||
// Has accelerator been changed from default?
|
||||
if (strcmp(def_acc_keys[x].seq, acc_keys[x].seq) == 0)
|
||||
{
|
||||
ini_section_delete_var(cat, acc_keys[x].name);
|
||||
} else {
|
||||
ini_section_set_string(cat, acc_keys[x].name, acc_keys[x].seq);
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < NUM_ACCELS; x++) {
|
||||
/* Has accelerator been changed from default? */
|
||||
if (strcmp(def_acc_keys[x].seq, acc_keys[x].seq) == 0)
|
||||
ini_section_delete_var(cat, acc_keys[x].name);
|
||||
else
|
||||
ini_section_set_string(cat, acc_keys[x].name, acc_keys[x].seq);
|
||||
}
|
||||
|
||||
ini_delete_section_if_empty(config, cat);
|
||||
}
|
||||
@@ -3148,7 +3144,7 @@ config_save(void)
|
||||
#ifndef USE_SDL_UI
|
||||
save_gl3_shaders(); /* GL3 Shaders */
|
||||
#endif
|
||||
save_keybinds(); /* Key bindings */
|
||||
save_keybinds(); /* Key bindings */
|
||||
|
||||
ini_write(config, cfg_path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user