From 06f790d86c6cb68f0f4f9e76388aa836c881d943 Mon Sep 17 00:00:00 2001 From: Mario Sanchez Prada Date: Thu, 8 Feb 2018 11:11:11 +0000 Subject: [PATCH] switcherPopup: Handle removal of items from SwitcherPopup This will be mainly useful for closing apps from the applications switcher, but can be implemented generically enough to select the nearest existing item after removal if there's any, or destroying the popup's actor otherwise. Specifically for the apps switcher, doing this also removes the need of having to manually either update the current app in AppSwitcher and highlight it, if there are still any items after the removal, or simply destroy the AppSwitcher otherwise. Besides, calling _select() in the handler for item-removed makes sure that the list of thumbnails in the switcher is always closed, if open, when quitting the app. https://bugzilla.gnome.org/show_bug.cgi?id=620106 --- js/ui/altTab.js | 7 ------- js/ui/switcherPopup.js | 25 ++++++++++++++++++++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/js/ui/altTab.js b/js/ui/altTab.js index 80039cba5..407a56e4c 100644 --- a/js/ui/altTab.js +++ b/js/ui/altTab.js @@ -812,13 +812,6 @@ var AppSwitcher = new Lang.Class({ this.icons.splice(index, 1); this.removeItem(index); - - if (this._curApp == index) - this._curApp = SwitcherPopup.mod(index, this.icons.length); - if (this.icons.length > 0) - this.highlight(this._curApp); - else - this.actor.destroy(); }, }); diff --git a/js/ui/switcherPopup.js b/js/ui/switcherPopup.js index 9a29ce2c2..9f92c4598 100644 --- a/js/ui/switcherPopup.js +++ b/js/ui/switcherPopup.js @@ -133,6 +133,7 @@ var SwitcherPopup = new Lang.Class({ this.actor.add_actor(this._switcherList.actor); this._switcherList.connect('item-activated', Lang.bind(this, this._itemActivated)); this._switcherList.connect('item-entered', Lang.bind(this, this._itemEntered)); + this._switcherList.connect('item-removed', Lang.bind(this, this._itemRemoved)); // Need to force an allocation so we can figure out whether we // need to scroll when selecting @@ -247,6 +248,19 @@ var SwitcherPopup = new Lang.Class({ this._itemEnteredHandler(n); }, + _itemRemovedHandler: function(n) { + if (this._items.length > 0) { + let newIndex = Math.min(n, this._items.length - 1); + this._select(newIndex); + } else { + this.actor.destroy(); + } + }, + + _itemRemoved: function(switcher, n) { + this._itemRemovedHandler(n); + }, + _disableHover: function() { this.mouseActive = false; @@ -421,6 +435,7 @@ var SwitcherList = new Lang.Class({ removeItem: function(index) { let item = this._items.splice(index, 1); item[0].destroy(); + this.emit('item-removed', index); }, _onItemClicked: function (index) { @@ -442,15 +457,15 @@ var SwitcherList = new Lang.Class({ this._items[this._highlighted].remove_style_pseudo_class('selected'); } - this._highlighted = index; - - if (this._highlighted != -1) { + if (this._items[index]) { if (justOutline) - this._items[this._highlighted].add_style_pseudo_class('outlined'); + this._items[index].add_style_pseudo_class('outlined'); else - this._items[this._highlighted].add_style_pseudo_class('selected'); + this._items[index].add_style_pseudo_class('selected'); } + this._highlighted = index; + let adjustment = this._scrollView.hscroll.adjustment; let [value, lower, upper, stepIncrement, pageIncrement, pageSize] = adjustment.get_values(); let [absItemX, absItemY] = this._items[index].get_transformed_position();