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>
This commit is contained in:
Florian Müllner 2021-08-12 02:16:59 +02:00 committed by Marge Bot
parent 07daa95393
commit 0f5881788c

View File

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