From 29d0c7cecd474d143c7499e24160f6693f4a978c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Thu, 11 Feb 2021 16:51:52 +0000 Subject: [PATCH] src: decouple accelerators array from actions array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We will be adding many more actions shortly, so cannot keep the two arrays' sizes in sync. Signed-off-by: Daniel P. Berrangé --- src/virt-viewer-window.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c index 19b39c9..def5a0b 100644 --- a/src/virt-viewer-window.c +++ b/src/virt-viewer-window.c @@ -812,13 +812,17 @@ static const GActionEntry keypad_action_entries[] = { { .name = "zoom-reset", .activate = action_zoom_reset }, }; -static const gchar *const keypad_action_accels[][2] = { - /* numpad keys are not handled automatically by gtk, see bgo#699823 */ - {"KP_Add", NULL}, - {"KP_Subtract", NULL}, - {"KP_0", NULL}, +struct VirtViewerActionAccels { + const char *accels[2]; + const char *action; +}; + +static const struct VirtViewerActionAccels action_accels[] = { + /* numpad keys are not handled automatically by gtk, see bgo#699823 */ + { {"KP_Add", NULL}, "win.zoom-in" }, + { {"KP_Subtract", NULL}, "win.zoom-out" }, + { {"KP_0", NULL}, "win.zoom-reset" }, }; -G_STATIC_ASSERT(G_N_ELEMENTS(keypad_action_entries) == G_N_ELEMENTS(keypad_action_accels)); void virt_viewer_window_disable_modifiers(VirtViewerWindow *self) @@ -854,8 +858,11 @@ virt_viewer_window_disable_modifiers(VirtViewerWindow *self) "gtk-enable-mnemonics", FALSE, NULL); - for (i = 0; i < G_N_ELEMENTS(keypad_action_entries); i++) { - g_action_map_remove_action(G_ACTION_MAP(self->window), keypad_action_entries[i].name); + for (i = 0; i < G_N_ELEMENTS(action_accels); i++) { + const char *noaccels[1] = { NULL }; + gtk_application_set_accels_for_action(GTK_APPLICATION(self->app), + action_accels[i].action, + noaccels); } self->accel_enabled = FALSE; @@ -900,12 +907,10 @@ virt_viewer_window_enable_modifiers(VirtViewerWindow *self) g_action_map_add_action_entries(G_ACTION_MAP(self->window), keypad_action_entries, G_N_ELEMENTS(keypad_action_entries), self); - for (i = 0; i < G_N_ELEMENTS(keypad_action_entries); i++) { - gchar *detailed_name = g_strdup_printf("win.%s", keypad_action_entries[i].name); + for (i = 0; i < G_N_ELEMENTS(action_accels); i++) { gtk_application_set_accels_for_action(GTK_APPLICATION(self->app), - detailed_name, - keypad_action_accels[i]); - g_free(detailed_name); + action_accels[i].action, + action_accels[i].accels); } }