From 9adb8c359496c568b1892d9abab857e8ba76130c Mon Sep 17 00:00:00 2001 From: Thibault Meyer Date: Sat, 18 Jan 2020 18:22:56 +0100 Subject: [PATCH] Add dynamic key binding Signed-off-by: Thibault Meyer --- CMakeLists.txt | 2 + src/gui/gui.h | 52 ++++--- src/gui/gui_main_callback_window_key.c | 56 +------ src/gui/gui_settings_callback_input_key.c | 13 ++ src/gui/gui_settings_init.c | 1 + src/gui/gui_settings_init_key_binding.c | 147 ++++++++++++++++++ ...olbox_load_settings_from_file_or_default.c | 32 ++++ src/gui/gui_toolbox_save_settings_to_file.c | 16 ++ 8 files changed, 250 insertions(+), 69 deletions(-) create mode 100644 src/gui/gui_settings_callback_input_key.c create mode 100644 src/gui/gui_settings_init_key_binding.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 6101896..5c4a028 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,12 +101,14 @@ ADD_EXECUTABLE( src/gui/gui_settings_callback_colorbutton_background.c src/gui/gui_settings_callback_colorbutton_foreground.c src/gui/gui_settings_callback_combobox_cpu_frequency.c + src/gui/gui_settings_callback_input_key.c src/gui/gui_settings_callback_window_destroy.c src/gui/gui_settings_init.c src/gui/gui_settings_init_color_background.c src/gui/gui_settings_init_color_foreground.c src/gui/gui_settings_init_cpu_frequency.c src/gui/gui_settings_init_display_mode.c + src/gui/gui_settings_init_key_binding.c src/gui/gui_toolbox_get_settings_filename.c src/gui/gui_toolbox_is_gtk_dark_theme_enabled src/gui/gui_toolbox_load_settings_from_file_or_default.c diff --git a/src/gui/gui.h b/src/gui/gui.h index b7b629c..c6e83ab 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -21,6 +21,7 @@ typedef struct s_gui_settings { uint32_t display_mode; GdkRGBA color_background; GdkRGBA color_foreground; + guint keybinding[CHIP8_KEYBOARD_MAX_KEY]; } s_gui_settings; typedef struct s_gui_settings_combobox_value { @@ -66,7 +67,7 @@ GdkPixbuf *gui_image_load_from_memory_scale(const unsigned char *data, * Callback. Configure main window when activated. Only call once. * * @param app GTK application instance - * @param user_data custom user data + * @param user_data Custom user data */ void gui_main_callback_app_activate(GtkApplication *app, gpointer user_data); @@ -74,7 +75,7 @@ void gui_main_callback_app_activate(GtkApplication *app, gpointer user_data); * Callback. Update counter. * * @param app GTK application instance - * @param user_data custom user data + * @param user_data Custom user data */ gboolean gui_main_callback_chip8_tick_counter(); @@ -90,7 +91,7 @@ gboolean gui_main_callback_chip8_tick_cpu(); * * @param app Widget instance * @param allocation Allocation information - * @param user_data custom user data + * @param user_data Custom user data */ gboolean gui_main_callback_drawing_area_draw(GtkWidget *widget, cairo_t *cr, void *data); @@ -99,7 +100,7 @@ gboolean gui_main_callback_drawing_area_draw(GtkWidget *widget, cairo_t *cr, voi * * @param app Widget instance * @param allocation Allocation information - * @param user_data custom user data + * @param user_data Custom user data */ void gui_main_callback_drawing_area_new_size(GtkWidget *widget, GtkAllocation *allocation, void *data); @@ -107,7 +108,7 @@ void gui_main_callback_drawing_area_new_size(GtkWidget *widget, GtkAllocation *a * Callback. Load a ROM. * * @param app GTK application instance - * @param user_data custom user data + * @param user_data Custom user data */ void gui_main_callback_header_bar_load_rom(GtkApplication *app, gpointer user_data); @@ -115,7 +116,7 @@ void gui_main_callback_header_bar_load_rom(GtkApplication *app, gpointer user_da * Callback. Reset chip8 CPU. * * @param app GTK application instance - * @param user_data custom user data + * @param user_data Custom user data */ void gui_main_callback_header_bar_reset_cpu(GtkApplication *app, gpointer user_data); @@ -123,7 +124,7 @@ void gui_main_callback_header_bar_reset_cpu(GtkApplication *app, gpointer user_d * Callback. Show "about" dialog. * * @param app GTK application instance - * @param user_data custom user data + * @param user_data Custom user data */ void gui_main_callback_menu_more_about(GtkApplication *app, gpointer user_data); @@ -131,7 +132,7 @@ void gui_main_callback_menu_more_about(GtkApplication *app, gpointer user_data); * Callback. Show "settings" dialog. * * @param app GTK application instance - * @param user_data custom user data + * @param user_data Custom user data */ void gui_main_callback_menu_more_settings(GtkApplication *app, gpointer user_data); @@ -139,7 +140,7 @@ void gui_main_callback_menu_more_settings(GtkApplication *app, gpointer user_dat * Callback. Main window is destroyed. * * @param app GTK application instance - * @param user_data custom user data + * @param user_data Custom user data */ void gui_main_callback_window_destroy(GtkWidget *widget, gpointer data); @@ -147,7 +148,7 @@ void gui_main_callback_window_destroy(GtkWidget *widget, gpointer data); * Callback. A key has been pressed or released. * * @param app GTK application instance - * @param user_data custom user data + * @param user_data Custom user data */ gboolean gui_main_callback_window_key(GtkWidget *widget, GdkEventKey *event, gpointer data); @@ -165,7 +166,7 @@ void gui_main_initialize_main_window(GtkApplication *app); * Settings - Callback - Set the background color. * * @param widget Handle to the GTK color button - * @param user_data custom user data + * @param user_data Custom user data */ void gui_settings_callback_colorbutton_background(GtkColorButton *widget, gpointer user_data); @@ -173,7 +174,7 @@ void gui_settings_callback_colorbutton_background(GtkColorButton *widget, gpoint * Settings - Callback - Set the foreground color. * * @param widget Handle to the GTK color button - * @param user_data custom user data + * @param user_data Custom user data */ void gui_settings_callback_colorbutton_foreground(GtkColorButton *widget, gpointer user_data); @@ -181,15 +182,23 @@ void gui_settings_callback_colorbutton_foreground(GtkColorButton *widget, gpoint * Settings - Callback - Set the CPU frequency. * * @param widget Handle to the combobox widget - * @param user_data custom user data + * @param user_data Custom user data */ void gui_settings_callback_combobox_cpu_frequency(GtkComboBox *widget, gpointer user_data); +/** + * Settings - Callback - Set binding for a specific key. + * + * @param widget Handle to the GTK entry + * @param key_idx Index of the key to set + */ +void gui_settings_callback_input_key(GtkEntry *entry, uint32_t key_idx); + /** * Callback. Settings window is destroyed. * * @param app GTK application instance - * @param user_data custom user data + * @param user_data Custom user data */ void gui_settings_callback_window_destroy(GtkWidget *widget, gpointer data); @@ -199,33 +208,40 @@ void gui_settings_callback_window_destroy(GtkWidget *widget, gpointer data); void gui_settings_init(void); /** - * Initialize the settings window - Background Color + * Initialize the settings window - Background Color. * * @param fixed_container Container to place components */ void gui_settings_init_color_background(GtkFixed *fixed_container); /** - * Initialize the settings window - Foreground Color + * Initialize the settings window - Foreground Color. * * @param fixed_container Container to place components */ void gui_settings_init_color_foreground(GtkFixed *fixed_container); /** - * Initialize the settings window - CPU Frequency + * Initialize the settings window - CPU Frequency. * * @param fixed_container Container to place components */ void gui_settings_init_cpu_frequency(GtkFixed *fixed_container); /** - * Initialize the settings window - Display Mode + * Initialize the settings window - Display Mode. * * @param fixed_container Container to place components */ void gui_settings_init_display_mode(GtkFixed *fixed_container); +/** + * Initialize the settings window - Key Binding. + * + * @param fixed_container Container to place components + */ +void gui_settings_init_key_binding(GtkFixed *fixed_container); + /** * Retrieves the settings filename. * diff --git a/src/gui/gui_main_callback_window_key.c b/src/gui/gui_main_callback_window_key.c index 09ff957..7eef3c2 100644 --- a/src/gui/gui_main_callback_window_key.c +++ b/src/gui/gui_main_callback_window_key.c @@ -3,57 +3,11 @@ gboolean gui_main_callback_window_key(GtkWidget *widget, GdkEventKey *event, gpointer data) { if (gl_gui_components.chip8_cpu) { uint8_t value = event->type == GDK_KEY_PRESS ? 1 : 0; - switch (event->keyval) { - case GDK_KEY_ampersand: - gl_gui_components.chip8_cpu->keyboard[1] = value; - break; - case GDK_KEY_eacute: - gl_gui_components.chip8_cpu->keyboard[2] = value; - break; - case GDK_KEY_quotedbl: - gl_gui_components.chip8_cpu->keyboard[3] = value; - break; - case GDK_KEY_apostrophe: - gl_gui_components.chip8_cpu->keyboard[12] = value; - break; - case GDK_KEY_a: - gl_gui_components.chip8_cpu->keyboard[4] = value; - break; - case GDK_KEY_z: - gl_gui_components.chip8_cpu->keyboard[5] = value; - break; - case GDK_KEY_e: - gl_gui_components.chip8_cpu->keyboard[6] = value; - break; - case GDK_KEY_r: - gl_gui_components.chip8_cpu->keyboard[13] = value; - break; - case GDK_KEY_q: - gl_gui_components.chip8_cpu->keyboard[7] = value; - break; - case GDK_KEY_s: - gl_gui_components.chip8_cpu->keyboard[8] = value; - break; - case GDK_KEY_d: - gl_gui_components.chip8_cpu->keyboard[9] = value; - break; - case GDK_KEY_f: - gl_gui_components.chip8_cpu->keyboard[14] = value; - break; - case GDK_KEY_w: - gl_gui_components.chip8_cpu->keyboard[10] = value; - break; - case GDK_KEY_x: - gl_gui_components.chip8_cpu->keyboard[0] = value; - break; - case GDK_KEY_c: - gl_gui_components.chip8_cpu->keyboard[11] = value; - break; - case GDK_KEY_v: - gl_gui_components.chip8_cpu->keyboard[15] = value; - break; - default: - break; + + for (uint8_t idx = 0; idx < CHIP8_KEYBOARD_MAX_KEY; ++idx) { + if (gl_gui_settings.keybinding[idx] == event->keyval) { + gl_gui_components.chip8_cpu->keyboard[idx] = value; + } } } diff --git a/src/gui/gui_settings_callback_input_key.c b/src/gui/gui_settings_callback_input_key.c new file mode 100644 index 0000000..9048160 --- /dev/null +++ b/src/gui/gui_settings_callback_input_key.c @@ -0,0 +1,13 @@ +#include "gui.h" + +void gui_settings_callback_input_key(GtkEntry *entry, uint32_t key_idx) { + const gchar *data = gtk_entry_get_text(entry); + + if (data[0] != 0) { + // Set new value + gl_gui_settings.keybinding[key_idx] = gdk_unicode_to_keyval(data[0]); + + // Persists settings + gui_toolbox_save_settings_to_file(); + } +} diff --git a/src/gui/gui_settings_init.c b/src/gui/gui_settings_init.c index bcfa7d3..e2c3e62 100644 --- a/src/gui/gui_settings_init.c +++ b/src/gui/gui_settings_init.c @@ -29,6 +29,7 @@ void gui_settings_init() { gui_settings_init_color_foreground(GTK_FIXED(fixed)); gui_settings_init_cpu_frequency(GTK_FIXED(fixed)); gui_settings_init_display_mode(GTK_FIXED(fixed)); + gui_settings_init_key_binding(GTK_FIXED(fixed)); // Mark some widget/object to be explicitly deleted when window will be destroyed GSList *components = g_slist_alloc(); diff --git a/src/gui/gui_settings_init_key_binding.c b/src/gui/gui_settings_init_key_binding.c new file mode 100644 index 0000000..383aece --- /dev/null +++ b/src/gui/gui_settings_init_key_binding.c @@ -0,0 +1,147 @@ +#include "gui.h" + +void gui_settings_init_key_binding(GtkFixed *fixed_container) { + // Create label and entry components + GtkWidget *label_key_binding = gtk_label_new("Keys"); + GtkWidget *entry_key_0 = gtk_entry_new(); + GtkWidget *entry_key_1 = gtk_entry_new(); + GtkWidget *entry_key_2 = gtk_entry_new(); + GtkWidget *entry_key_3 = gtk_entry_new(); + GtkWidget *entry_key_4 = gtk_entry_new(); + GtkWidget *entry_key_5 = gtk_entry_new(); + GtkWidget *entry_key_6 = gtk_entry_new(); + GtkWidget *entry_key_7 = gtk_entry_new(); + GtkWidget *entry_key_8 = gtk_entry_new(); + GtkWidget *entry_key_9 = gtk_entry_new(); + GtkWidget *entry_key_A = gtk_entry_new(); + GtkWidget *entry_key_B = gtk_entry_new(); + GtkWidget *entry_key_C = gtk_entry_new(); + GtkWidget *entry_key_D = gtk_entry_new(); + GtkWidget *entry_key_E = gtk_entry_new(); + GtkWidget *entry_key_F = gtk_entry_new(); + + // Configure entry components + gtk_entry_set_max_length(GTK_ENTRY(entry_key_0), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_0), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_0), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_1), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_1), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_1), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_2), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_2), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_2), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_3), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_3), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_3), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_4), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_4), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_4), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_5), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_5), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_5), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_6), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_6), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_6), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_7), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_7), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_7), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_8), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_8), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_8), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_9), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_9), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_9), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_A), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_A), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_A), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_B), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_B), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_B), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_C), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_C), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_C), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_D), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_D), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_D), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_E), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_E), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_E), 0.5); + gtk_entry_set_max_length(GTK_ENTRY(entry_key_F), 1); + gtk_entry_set_width_chars(GTK_ENTRY(entry_key_F), 2); + gtk_entry_set_alignment(GTK_ENTRY(entry_key_F), 0.5); + + // Restore values + gchar *text = g_malloc0(2); + text[0] = gl_gui_settings.keybinding[0]; + gtk_entry_set_text(GTK_ENTRY(entry_key_0), text); + text[0] = gl_gui_settings.keybinding[1]; + gtk_entry_set_text(GTK_ENTRY(entry_key_1), text); + text[0] = gl_gui_settings.keybinding[2]; + gtk_entry_set_text(GTK_ENTRY(entry_key_2), text); + text[0] = gl_gui_settings.keybinding[3]; + gtk_entry_set_text(GTK_ENTRY(entry_key_3), text); + text[0] = gl_gui_settings.keybinding[4]; + gtk_entry_set_text(GTK_ENTRY(entry_key_4), text); + text[0] = gl_gui_settings.keybinding[5]; + gtk_entry_set_text(GTK_ENTRY(entry_key_5), text); + text[0] = gl_gui_settings.keybinding[6]; + gtk_entry_set_text(GTK_ENTRY(entry_key_6), text); + text[0] = gl_gui_settings.keybinding[7]; + gtk_entry_set_text(GTK_ENTRY(entry_key_7), text); + text[0] = gl_gui_settings.keybinding[8]; + gtk_entry_set_text(GTK_ENTRY(entry_key_8), text); + text[0] = gl_gui_settings.keybinding[9]; + gtk_entry_set_text(GTK_ENTRY(entry_key_9), text); + text[0] = gl_gui_settings.keybinding[10]; + gtk_entry_set_text(GTK_ENTRY(entry_key_A), text); + text[0] = gl_gui_settings.keybinding[11]; + gtk_entry_set_text(GTK_ENTRY(entry_key_B), text); + text[0] = gl_gui_settings.keybinding[12]; + gtk_entry_set_text(GTK_ENTRY(entry_key_C), text); + text[0] = gl_gui_settings.keybinding[13]; + gtk_entry_set_text(GTK_ENTRY(entry_key_D), text); + text[0] = gl_gui_settings.keybinding[14]; + gtk_entry_set_text(GTK_ENTRY(entry_key_E), text); + text[0] = gl_gui_settings.keybinding[15]; + gtk_entry_set_text(GTK_ENTRY(entry_key_F), text); + g_free(text); + + // Connect signal + g_signal_connect(entry_key_0, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 0); + g_signal_connect(entry_key_1, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 1); + g_signal_connect(entry_key_2, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 2); + g_signal_connect(entry_key_3, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 3); + g_signal_connect(entry_key_4, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 4); + g_signal_connect(entry_key_5, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 5); + g_signal_connect(entry_key_6, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 6); + g_signal_connect(entry_key_7, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 7); + g_signal_connect(entry_key_8, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 8); + g_signal_connect(entry_key_9, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 9); + g_signal_connect(entry_key_A, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 10); + g_signal_connect(entry_key_B, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 11); + g_signal_connect(entry_key_C, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 12); + g_signal_connect(entry_key_D, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 13); + g_signal_connect(entry_key_E, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 14); + g_signal_connect(entry_key_F, "changed", G_CALLBACK(gui_settings_callback_input_key), (void *) 15); + + // Place components on the container + gtk_fixed_put(fixed_container, label_key_binding, 350, 15); + gtk_fixed_put(fixed_container, entry_key_1, 420, 10); + gtk_fixed_put(fixed_container, entry_key_2, 460, 10); + gtk_fixed_put(fixed_container, entry_key_3, 500, 10); + gtk_fixed_put(fixed_container, entry_key_C, 540, 10); + gtk_fixed_put(fixed_container, entry_key_4, 420, 50); + gtk_fixed_put(fixed_container, entry_key_5, 460, 50); + gtk_fixed_put(fixed_container, entry_key_6, 500, 50); + gtk_fixed_put(fixed_container, entry_key_D, 540, 50); + gtk_fixed_put(fixed_container, entry_key_7, 420, 90); + gtk_fixed_put(fixed_container, entry_key_8, 460, 90); + gtk_fixed_put(fixed_container, entry_key_9, 500, 90); + gtk_fixed_put(fixed_container, entry_key_E, 540, 90); + gtk_fixed_put(fixed_container, entry_key_A, 420, 130); + gtk_fixed_put(fixed_container, entry_key_0, 460, 130); + gtk_fixed_put(fixed_container, entry_key_B, 500, 130); + gtk_fixed_put(fixed_container, entry_key_F, 540, 130); + + //uint32_t t = ; +} diff --git a/src/gui/gui_toolbox_load_settings_from_file_or_default.c b/src/gui/gui_toolbox_load_settings_from_file_or_default.c index 5a0c494..bd790a3 100644 --- a/src/gui/gui_toolbox_load_settings_from_file_or_default.c +++ b/src/gui/gui_toolbox_load_settings_from_file_or_default.c @@ -17,6 +17,22 @@ void gui_toolbox_load_settings_from_file_or_default(void) { gl_gui_settings.color_foreground.green = g_key_file_get_double(key_file, "color_foreground", "green", NULL); gl_gui_settings.color_foreground.blue = g_key_file_get_double(key_file, "color_foreground", "blue", NULL); gl_gui_settings.color_foreground.alpha = 1; + gl_gui_settings.keybinding[0] = g_key_file_get_integer(key_file, "keybinding", "0", NULL); + gl_gui_settings.keybinding[1] = g_key_file_get_integer(key_file, "keybinding", "1", NULL); + gl_gui_settings.keybinding[2] = g_key_file_get_integer(key_file, "keybinding", "2", NULL); + gl_gui_settings.keybinding[3] = g_key_file_get_integer(key_file, "keybinding", "3", NULL); + gl_gui_settings.keybinding[4] = g_key_file_get_integer(key_file, "keybinding", "4", NULL); + gl_gui_settings.keybinding[5] = g_key_file_get_integer(key_file, "keybinding", "5", NULL); + gl_gui_settings.keybinding[6] = g_key_file_get_integer(key_file, "keybinding", "6", NULL); + gl_gui_settings.keybinding[7] = g_key_file_get_integer(key_file, "keybinding", "7", NULL); + gl_gui_settings.keybinding[8] = g_key_file_get_integer(key_file, "keybinding", "8", NULL); + gl_gui_settings.keybinding[9] = g_key_file_get_integer(key_file, "keybinding", "9", NULL); + gl_gui_settings.keybinding[10] = g_key_file_get_integer(key_file, "keybinding", "10", NULL); + gl_gui_settings.keybinding[11] = g_key_file_get_integer(key_file, "keybinding", "11", NULL); + gl_gui_settings.keybinding[12] = g_key_file_get_integer(key_file, "keybinding", "12", NULL); + gl_gui_settings.keybinding[13] = g_key_file_get_integer(key_file, "keybinding", "13", NULL); + gl_gui_settings.keybinding[14] = g_key_file_get_integer(key_file, "keybinding", "14", NULL); + gl_gui_settings.keybinding[15] = g_key_file_get_integer(key_file, "keybinding", "15", NULL); } else { // Use default values gl_gui_settings.cpu_frequency = 500; @@ -29,6 +45,22 @@ void gui_toolbox_load_settings_from_file_or_default(void) { gl_gui_settings.color_foreground.green = 1; gl_gui_settings.color_foreground.blue = 1; gl_gui_settings.color_foreground.alpha = 1; + gl_gui_settings.keybinding[0] = GDK_KEY_x; + gl_gui_settings.keybinding[1] = GDK_KEY_ampersand; + gl_gui_settings.keybinding[2] = GDK_KEY_eacute; + gl_gui_settings.keybinding[3] = GDK_KEY_quotedbl; + gl_gui_settings.keybinding[4] = GDK_KEY_a; + gl_gui_settings.keybinding[5] = GDK_KEY_z; + gl_gui_settings.keybinding[6] = GDK_KEY_e; + gl_gui_settings.keybinding[7] = GDK_KEY_q; + gl_gui_settings.keybinding[8] = GDK_KEY_s; + gl_gui_settings.keybinding[9] = GDK_KEY_d; + gl_gui_settings.keybinding[10] = GDK_KEY_w; + gl_gui_settings.keybinding[11] = GDK_KEY_c; + gl_gui_settings.keybinding[12] = GDK_KEY_apostrophe; + gl_gui_settings.keybinding[13] = GDK_KEY_r; + gl_gui_settings.keybinding[14] = GDK_KEY_f; + gl_gui_settings.keybinding[15] = GDK_KEY_v; gui_toolbox_save_settings_to_file(); } diff --git a/src/gui/gui_toolbox_save_settings_to_file.c b/src/gui/gui_toolbox_save_settings_to_file.c index a14addf..e8b6a9a 100644 --- a/src/gui/gui_toolbox_save_settings_to_file.c +++ b/src/gui/gui_toolbox_save_settings_to_file.c @@ -13,6 +13,22 @@ void gui_toolbox_save_settings_to_file(void) { g_key_file_set_double(key_file, "color_foreground", "red", gl_gui_settings.color_foreground.red); g_key_file_set_double(key_file, "color_foreground", "green", gl_gui_settings.color_foreground.green); g_key_file_set_double(key_file, "color_foreground", "blue", gl_gui_settings.color_foreground.blue); + g_key_file_set_integer(key_file, "keybinding", "0", gl_gui_settings.keybinding[0]); + g_key_file_set_integer(key_file, "keybinding", "1", gl_gui_settings.keybinding[1]); + g_key_file_set_integer(key_file, "keybinding", "2", gl_gui_settings.keybinding[2]); + g_key_file_set_integer(key_file, "keybinding", "3", gl_gui_settings.keybinding[3]); + g_key_file_set_integer(key_file, "keybinding", "4", gl_gui_settings.keybinding[4]); + g_key_file_set_integer(key_file, "keybinding", "5", gl_gui_settings.keybinding[5]); + g_key_file_set_integer(key_file, "keybinding", "6", gl_gui_settings.keybinding[6]); + g_key_file_set_integer(key_file, "keybinding", "7", gl_gui_settings.keybinding[7]); + g_key_file_set_integer(key_file, "keybinding", "8", gl_gui_settings.keybinding[8]); + g_key_file_set_integer(key_file, "keybinding", "9", gl_gui_settings.keybinding[9]); + g_key_file_set_integer(key_file, "keybinding", "10", gl_gui_settings.keybinding[10]); + g_key_file_set_integer(key_file, "keybinding", "11", gl_gui_settings.keybinding[11]); + g_key_file_set_integer(key_file, "keybinding", "12", gl_gui_settings.keybinding[12]); + g_key_file_set_integer(key_file, "keybinding", "13", gl_gui_settings.keybinding[13]); + g_key_file_set_integer(key_file, "keybinding", "14", gl_gui_settings.keybinding[14]); + g_key_file_set_integer(key_file, "keybinding", "15", gl_gui_settings.keybinding[15]); // Save to file g_key_file_save_to_file(key_file, filename, NULL);