[gnome-shell/wip/carlosg/popup-logic] popupMenu: Avoid intermediate focus changes on menu switch




commit 4ea7cd65558621ff134fbc8b5de381a2acabc9fb
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Feb 9 15:32:56 2022 +0100

    popupMenu: Avoid intermediate focus changes on menu switch
    
    Currently when switching from a popup menu to another in the same
    manager, we first hide the old menu and remove its grab, then show
    the new menu, and create a new grab.
    
    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

 js/ui/popupMenu.js | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index b464673626..f3e014667e 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -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;
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]