From 1710197de88157a07b209d3237710bd8a84903dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davi=20da=20Silva=20B=C3=B6ger?= Date: Mon, 30 Jan 2017 16:07:15 -0200 Subject: [PATCH] Select first app when there are none running --- src/extension.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/extension.js b/src/extension.js index 6736937..f94448c 100644 --- a/src/extension.js +++ b/src/extension.js @@ -23,6 +23,7 @@ const AppFavorites = imports.ui.appFavorites; let AppSwitcher_init_orig; let AppSwitcherPopup_init_orig; +let AppSwitcherPopup_initialSelection_orig; let AppSwitcherPopup_select_orig; let AppSwitcherPopup_finish_orig; @@ -53,6 +54,16 @@ const AppSwitcherPopup_init_mod = function() { } } +const AppSwitcherPopup_initialSelection_mod = function(backward, binding) { + // favorites are always added after running apps, so if first icon has no windows, + // there are no running apps + if (this._items[0].cachedWindows.length == 0) { + this._select(0); + } else { + AppSwitcherPopup_initialSelection_orig.apply(this, [backward, binding]); + } +} + const AppSwitcherPopup_select_mod = function(app, window, forceAppFocus) { let appIcon = this._items[app]; if (appIcon.cachedWindows.length == 0) { @@ -85,6 +96,9 @@ function enable() { AppSwitcherPopup_init_orig = AltTab.AppSwitcherPopup.prototype._init; AltTab.AppSwitcherPopup.prototype._init = AppSwitcherPopup_init_mod; + AppSwitcherPopup_initialSelection_orig = AltTab.AppSwitcherPopup.prototype._initialSelection; + AltTab.AppSwitcherPopup.prototype._initialSelection = AppSwitcherPopup_initialSelection_mod; + AppSwitcherPopup_select_orig = AltTab.AppSwitcherPopup.prototype._select; AltTab.AppSwitcherPopup.prototype._select = AppSwitcherPopup_select_mod; @@ -99,6 +113,9 @@ function disable() { AltTab.AppSwitcherPopup.prototype._init = AppSwitcherPopup_init_orig; AppSwitcherPopup_init_orig = null; + AltTab.AppSwitcherPopup.prototype._initialSelection = AppSwitcherPopup_initialSelection_orig; + AppSwitcherPopup_initialSelection_orig = null; + AltTab.AppSwitcherPopup.prototype._select = AppSwitcherPopup_select_orig; AppSwitcherPopup_select_orig = null;