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
This commit is contained in:
Jonas Dreßler 2020-01-15 16:19:41 +01:00 committed by Florian Müllner
parent bfb0bc7a29
commit bf213af362
2 changed files with 10 additions and 9 deletions

View File

@ -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) {

View File

@ -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;
}