[gnome-shell/T27795: 70/138] Implement the "toggle apps" functionality



commit 6b98be74ad5bf6e94b96eab9035adf1aee4d814f
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Thu Sep 14 16:29:58 2017 +0100

    Implement the "toggle apps" functionality
    
    This will be invoked both when pressing the Super key or the Endless
    button, allowing the user to switch between the desktop's icon grid
    and the current mode (e.g. running application, windows picker).

 js/ui/main.js         |  2 +-
 js/ui/overview.js     | 45 +++++++++++++++++++++++++++++++++++++++++++++
 js/ui/viewSelector.js | 46 +++++++++++++++++++++++++++++++++-------------
 3 files changed, 79 insertions(+), 14 deletions(-)
---
diff --git a/js/ui/main.js b/js/ui/main.js
index 8c67e17000..08d634a16f 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -219,7 +219,7 @@ function _initializeUI() {
 
     global.display.connect('overlay-key', () => {
         if (!_a11ySettings.get_boolean (STICKY_KEYS_ENABLE))
-            overview.toggle();
+            overview.toggleApps();
     });
 
     global.connect('locate-pointer', () => {
diff --git a/js/ui/overview.js b/js/ui/overview.js
index 6ca8fb994c..303e4960e5 100644
--- a/js/ui/overview.js
+++ b/js/ui/overview.js
@@ -13,6 +13,7 @@ const MessageTray = imports.ui.messageTray;
 const Monitor = imports.ui.monitor;
 const OverviewControls = imports.ui.overviewControls;
 const Params = imports.misc.params;
+const ViewSelector = imports.ui.viewSelector;
 const WorkspaceThumbnail = imports.ui.workspaceThumbnail;
 
 // Time for initial animation going into Overview mode
@@ -427,6 +428,27 @@ var Overview = class {
         this._searchEntry.grab_key_focus();
     }
 
+    _showOrSwitchPage(page) {
+        if (this.visible)
+            this.viewSelector.setActivePage(page);
+        else
+            this.show();
+    }
+
+    showApps() {
+        if (this.isDummy)
+            return;
+
+        this._showOrSwitchPage(ViewSelector.ViewPage.APPS);
+    }
+
+    showWindows() {
+        if (this.isDummy)
+            return;
+
+        this._showOrSwitchPage(ViewSelector.ViewPage.WINDOWS);
+    }
+
     fadeInDesktop() {
         this._desktopFade.opacity = 0;
         this._desktopFade.show();
@@ -455,6 +477,29 @@ var Overview = class {
         });
     }
 
+    toggleApps() {
+        if (this.isDummy)
+            return;
+
+        if (!this.visible ||
+            this.viewSelector.getActivePage() !== ViewSelector.ViewPage.APPS) {
+            this.showApps();
+            return;
+        }
+
+        if (!Main.workspaceMonitor.hasVisibleWindows) {
+            // There are active windows but all of them are hidden, so activate
+            // the most recently used one before hiding the overview.
+            let appSystem = Shell.AppSystem.get_default();
+            let runningApps = appSystem.get_running();
+            if (runningApps.length > 0)
+                runningApps[0].activate();
+        }
+
+        // Toggle to the currently open window
+        this.hide();
+    }
+
     // Checks if the Activities button is currently sensitive to
     // clicks. The first call to this function within the
     // OVERVIEW_ACTIVATION_TIMEOUT time of the hot corner being
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index 11d0aeaa95..42772086ef 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -216,7 +216,7 @@ var ViewSelector = class {
                               Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
                               Shell.ActionMode.NORMAL |
                               Shell.ActionMode.OVERVIEW,
-                              this._toggleAppsPage.bind(this));
+                              Main.overview.toggleApps.bind(this));
 
         Main.wm.addKeybinding('toggle-overview',
                               new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
@@ -253,11 +253,6 @@ var ViewSelector = class {
             Main.overview.show();
     }
 
-    _toggleAppsPage() {
-        this._showAppsButton.checked = !this._showAppsButton.checked;
-        Main.overview.show();
-    }
-
     showApps() {
         this._showAppsButton.checked = true;
         Main.overview.show();
@@ -266,11 +261,8 @@ var ViewSelector = class {
     show() {
         this.reset();
         this._workspacesDisplay.show(true);
-        this._activePage = null;
-        this._showPage(this._appsPage);
 
-        if (!this._workspacesDisplay.activeWorkspaceHasMaximizedWindows())
-            Main.overview.fadeOutDesktop();
+        this._showPage(this._appsPage);
     }
 
     animateFromOverview() {
@@ -281,9 +273,6 @@ var ViewSelector = class {
         this._workspacesDisplay.animateFromOverview(this._activePage != this._workspacesPage);
 
         this._showAppsButton.checked = false;
-
-        if (!this._workspacesDisplay.activeWorkspaceHasMaximizedWindows())
-            Main.overview.fadeInDesktop();
     }
 
     setWorkspacesFullGeometry(geom) {
@@ -588,6 +577,17 @@ var ViewSelector = class {
         return Clutter.EVENT_PROPAGATE;
     }
 
+    _pageFromViewPage(viewPage) {
+        let page;
+
+        if (viewPage == ViewPage.WINDOWS)
+            page = this._workspacesPage;
+        else
+            page = this._appsPage;
+
+        return page;
+    }
+
     getActivePage() {
         if (this._activePage == this._workspacesPage)
             return ViewPage.WINDOWS;
@@ -596,5 +596,25 @@ var ViewSelector = class {
         else
             return ViewPage.SEARCH;
     }
+
+    setActivePage(viewPage) {
+        this._showPage(this._pageFromViewPage(viewPage));
+    }
+
+    fadeIn() {
+        this._activePage.ease({
+            opacity: 255,
+            duration: OverviewControls.SIDE_CONTROLS_ANIMATION_TIME / 2,
+            mode: Clutter.AnimationMode.EASE_OUT_QUAD,
+        });
+    }
+
+    fadeHalf() {
+        this._activePage.ease({
+            opacity: 128,
+            duration: OverviewControls.SIDE_CONTROLS_ANIMATION_TIME / 2,
+            mode: Clutter.AnimationMode.EASE_OUT_QUAD,
+        });
+    }
 };
 Signals.addSignalMethods(ViewSelector.prototype);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]