[gnome-shell] appMenu: Delay window sections update when selecting window



commit 0f5881788cdfd36c2232ab05e0b20d81fe269831
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Aug 12 02:16:59 2021 +0200

    appMenu: Delay window sections update when selecting window
    
    App windows are ordered by recency, so a focus change (correctly)
    triggers the ::window-changed signal. If we rebuild the section
    immediately in response, the activating item will be destroyed
    before the menu's ::activate handler, with the result that the
    menu remains open.
    
    Defer the section update in that case to allow the menu to process
    the ::activate signal first.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1948>

 js/ui/appMenu.js | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/appMenu.js b/js/ui/appMenu.js
index 42c92a4222..a795e8e616 100644
--- a/js/ui/appMenu.js
+++ b/js/ui/appMenu.js
@@ -1,6 +1,6 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 /* exported AppMenu */
-const { Gio, GLib, Shell, St } = imports.gi;
+const { Gio, GLib, Meta, Shell, St } = imports.gi;
 
 const PopupMenu = imports.ui.popupMenu;
 const Main = imports.ui.main;
@@ -18,6 +18,7 @@ var AppMenu = class AppMenu extends PopupMenu.PopupMenu {
         this._appSystem = Shell.AppSystem.get_default();
 
         this._windowsChangedId = 0;
+        this._updateWindowsLaterId = 0;
 
         /* Translators: This is the heading of a list of open windows */
         this._openWindowsHeader = new PopupMenu.PopupSeparatorMenuItem(_('Open Windows'));
@@ -103,9 +104,8 @@ var AppMenu = class AppMenu extends PopupMenu.PopupMenu {
         this._app = app;
 
         if (app) {
-            this._windowsChangedId = app.connect('windows-changed', () => {
-                this._updateWindowsSection();
-            });
+            this._windowsChangedId = app.connect('windows-changed',
+                () => this._queueUpdateWindowsSection());
         }
 
         this._updateWindowsSection();
@@ -125,7 +125,22 @@ var AppMenu = class AppMenu extends PopupMenu.PopupMenu {
             app && app.can_open_new_window() && !actions.includes('new-window');
     }
 
+    _queueUpdateWindowsSection() {
+        if (this._updateWindowsLaterId)
+            return;
+
+        this._updateWindowsLaterId = Meta.later_add(
+            Meta.LaterType.BEFORE_REDRAW, () => {
+                this._updateWindowsSection();
+                return GLib.SOURCE_REMOVE;
+            });
+    }
+
     _updateWindowsSection() {
+        if (this._updateWindowsLaterId)
+            Meta.later_remove(this._updateWindowsLaterId);
+        this._updateWindowsLaterId = 0;
+
         this._windowSection.removeAll();
         this._openWindowsHeader.hide();
 


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