windows: fix nonuniform behavior of zoom hotkeys

If a vv file is used or the hotkeys are customized using the
--hotkeys cmd option, all hotkeys that are not explicitly
requested get disabled, this includes the zomm hotkeys.

As a consequence, the labels for zoom actions in the menu
disappear. However, the user can still perform these actions
using the keys on the numpad which are handled separately.

To fix it, check that the normal zoom hotkeys are enabled
before enabling the keypad ones.

Related to: https://bugzilla.redhat.com/show_bug.cgi?id=1791261

Signed-off-by: Jakub Janků <jjanku@redhat.com>
This commit is contained in:
Jakub Janků 2020-12-03 13:40:33 +01:00
parent d5e96a30cb
commit a40c8f4508

View File

@ -887,6 +887,7 @@ virt_viewer_window_enable_modifiers(VirtViewerWindow *self)
VirtViewerWindowPrivate *priv = self->priv;
GSList *accels;
guint i;
GtkAccelKey key;
if (priv->accel_enabled)
return;
@ -904,15 +905,20 @@ virt_viewer_window_enable_modifiers(VirtViewerWindow *self)
"gtk-enable-mnemonics", priv->enable_mnemonics_save,
NULL);
g_action_map_add_action_entries(G_ACTION_MAP(priv->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);
gtk_application_set_accels_for_action(GTK_APPLICATION(priv->app),
detailed_name,
keypad_action_accels[i]);
g_free(detailed_name);
/* if zoom actions using "normal" +/-/0 keys are enabled,
* allow the user to use the numpad +/-/0 keys as well */
if (gtk_accel_map_lookup_entry("<virt-viewer>/view/zoom-out", &key)
&& key.accel_key != 0) {
g_action_map_add_action_entries(G_ACTION_MAP(priv->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);
gtk_application_set_accels_for_action(GTK_APPLICATION(priv->app),
detailed_name,
keypad_action_accels[i]);
g_free(detailed_name);
}
}
priv->accel_enabled = TRUE;