shortcutcontroller: Don't reinject menu accels

The normal way to associate accels with actions is
to attach a shortcut controller to the widget. The shorcut
controller will inject the accel into the action muxer
tree, so that it can get displayed in widgets that activate
the action (say, in menus.

This approach does not works for generated menus, since the
widgets are not in the hands of the app developer, so attaching
shortcut controllers to them is impractical.

Instead, GtkModelButton has an accel property that gets
bound to the accel coming from the action muxer tree (most
likely put there via gtk_application_set_accel_for_action),
and creates a shortcut controller itself.

The change in this commit is to prevent the shortcut controller
from injecting the accel into the action muxer tree in this case.
Otherwise, the accels get 'stuck' and we won't update them if the
global accels are later changed.

This is a hack, and needs a better solution.
This commit is contained in:
Matthias Clasen 2021-06-17 08:43:48 -04:00
parent 64af90111e
commit 7344a03aa3

View File

@ -78,6 +78,7 @@
#include "gtkwidgetprivate.h"
#include "gtknative.h"
#include "gtkdebug.h"
#include "gtkmodelbuttonprivate.h"
#include <gdk/gdk.h>
@ -489,7 +490,7 @@ gtk_shortcut_controller_update_accels (GtkShortcutController *self)
guint i, p;
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self));
if (!widget)
if (!widget || GTK_IS_MODEL_BUTTON (widget))
return;
muxer = _gtk_widget_get_action_muxer (widget, TRUE);