popupMenu: Avoid intermediate focus changes on menu switch

Currently when switching from a popup menu to another in the same
manager, we first show the new menu, then hide the old menu and
remove its grab, then create a new grab for the just shown menu.

This briefly ungrabbed moment will still trigger keyboard focus
changes, that might have other visible effects. In order to fix
this, change the grabbing order so first the new grab is created
then the old one is dismissed. This ensures focus moves from the
old menu to the new menu without gaps in between.

Since a grab is tied to an active menu, but close/grab are now
slightly decoupled, also ensure closing a menu only tears down its
own grab. This is necessary for correct accounting while doing the
grab shuffling.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5039
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2166>
This commit is contained in:
Carlos Garnacho 2022-02-09 15:32:56 +01:00 committed by Marge Bot
parent 00e41383c7
commit c13d44439f

View File

@ -1356,13 +1356,15 @@ var PopupMenuManager = class {
return;
if (open) {
if (this.activeMenu)
this.activeMenu.close(BoxPointer.PopupAnimation.FADE);
const oldMenu = this.activeMenu;
const oldGrab = this._grab;
this._grab = Main.pushModal(menu.actor, this._grabParams);
this.activeMenu = menu;
} else {
if (this.activeMenu === menu)
this.activeMenu = null;
oldMenu?.close(BoxPointer.PopupAnimation.FADE);
if (oldGrab)
Main.popModal(oldGrab);
} else if (this.activeMenu === menu) {
this.activeMenu = null;
Main.popModal(this._grab);
this._grab = null;
}