Skip to content

shortcutmanager: Handle propagation phase changes of added controllers

GtkShortcutManager allows adding controllers to it. For the default implementation, they get added to one of two models, based on the propagation phase (either GTK_PHASE_CAPTURE or GTK_PHASE_BUBBLE).

However, when a controller is removed, its presence in the manager gets checked against the current propagation phase of the controller, which may have changed from when it was added. This can lead to crashes if the controller was not disposed properly since it still has a reference in one of the two models of the GtkShortcutManager.

To fix this, add a callback for notify::propagation-phase, which removes the controller from all possible models and readds it again with its current phase. This callback is only disconnected permanently when the controller is manually removed with gtk_shortcut_manager_default_remove_controller().

Closes #6246 (closed)

This directly solves gnome-control-center#2768 (closed), but I don't know of any other crashes due to this. It does not seem very common to change the propagation phase of existing controllers. This can lead to weird crashes that are hard to debug, because lingering shortcut controllers that are not disposed can still be activated anywhere in an app. See the list of issues in #6246 (closed) that appear very different, but were all traced back to this eventually.

Edited by Matthijs Velsink

Merge request reports