From bf213af362d8ecf88a5e1c8af3d264470caf32a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Wed, 15 Jan 2020 16:19:41 +0100 Subject: [PATCH] switcherPopup: Lookup index of items when hovering or clicking Right now the index that gets selected on click and motion events is set when connecting the event inside the addItem function. If items are added or removed (for example when an application is closed by pressing "q"), this index isn't valid anymore and has to be updated. To fix this, use the items themselves instead of the index as arguments for the event handlers and lookup the index of the item inside the event handler. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/167 --- js/ui/altTab.js | 4 +++- js/ui/switcherPopup.js | 15 +++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/js/ui/altTab.js b/js/ui/altTab.js index 12b784939..35d991e20 100644 --- a/js/ui/altTab.js +++ b/js/ui/altTab.js @@ -775,7 +775,9 @@ class AppSwitcher extends SwitcherPopup.SwitcherList { // We override SwitcherList's _onItemEnter method to delay // activation when the thumbnail list is open - _onItemEnter(index) { + _onItemEnter(item) { + const index = this._items.indexOf(item); + if (this._mouseTimeOutId != 0) GLib.source_remove(this._mouseTimeOutId); if (this._altTabPopup.thumbnailsVisible) { diff --git a/js/ui/switcherPopup.js b/js/ui/switcherPopup.js index 46a4b158a..f7ee2e769 100644 --- a/js/ui/switcherPopup.js +++ b/js/ui/switcherPopup.js @@ -427,9 +427,8 @@ var SwitcherList = GObject.registerClass({ bbox.set_child(item); this._list.add_actor(bbox); - let n = this._items.length; - bbox.connect('clicked', () => this._onItemClicked(n)); - bbox.connect('motion-event', () => this._onItemEnter(n)); + bbox.connect('clicked', () => this._onItemClicked(bbox)); + bbox.connect('motion-event', () => this._onItemEnter(bbox)); bbox.label_actor = label; @@ -452,14 +451,14 @@ var SwitcherList = GObject.registerClass({ this._items[index].remove_accessible_state(state); } - _onItemClicked(index) { - this._itemActivated(index); + _onItemClicked(item) { + this._itemActivated(this._items.indexOf(item)); } - _onItemEnter(index) { + _onItemEnter(item) { // Avoid reentrancy - if (index !== this._highlighted) - this._itemEntered(index); + if (item !== this._items[this._highlighted]) + this._itemEntered(this._items.indexOf(item)); return Clutter.EVENT_PROPAGATE; }