Don't double attach accels on enable window mods

Check whether accels are currently attached to a window before attaching
them when enabling window modifiers.

This commit fixes an assert in _gtk_accel_group_attach introduced by
cfcac9fb, which erroneously assumed that is harmless to re-add accel
groups that have already been added to a window.

Signed-off-by: Shawn M. Chapla <schapla@codeweavers.com>
This commit is contained in:
Shawn M. Chapla 2021-02-14 14:51:06 -05:00
parent 70b90370e2
commit bda6dbbecf

View File

@ -888,15 +888,21 @@ virt_viewer_window_enable_modifiers(VirtViewerWindow *self)
GSList *accels;
guint i;
GtkAccelKey key;
GSList *attached_accels;
if (priv->accel_enabled)
return;
/* This allows F10 activating menu bar */
g_object_set_property(G_OBJECT(settings), "gtk-menu-bar-accel", &priv->accel_setting);
attached_accels = gtk_accel_groups_from_object(G_OBJECT(priv->window));
/* This allows global accelerators like Ctrl+Q == Quit */
for (accels = priv->accel_list ; accels ; accels = accels->next) {
/* Do not attach accels that are already attached. */
if (attached_accels && g_slist_find(attached_accels, accels->data))
continue;
gtk_window_add_accel_group(GTK_WINDOW(priv->window), accels->data);
}