[gnome-shell/T27795: 71/138] Implement the "toggle windows picker" functionality



commit e5eb2271560b4654f16c95adf02ed2cd19a52a8b
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Wed Feb 14 10:13:20 2018 +0000

    Implement the "toggle windows picker" functionality
    
    This will be invoked via the hot corner, allowing the user to pick one
    of the running applications from a high-level view of clones.
    
    Also, enable toggling the windows picker with the Super+S keybinding

 js/ui/hotCorner.js    |  2 +-
 js/ui/main.js         |  2 +-
 js/ui/overview.js     | 47 ++++++++++++++++++++++++++++++++++++++++++++---
 js/ui/viewSelector.js |  6 +++---
 4 files changed, 49 insertions(+), 8 deletions(-)
---
diff --git a/js/ui/hotCorner.js b/js/ui/hotCorner.js
index 29f52c74a6..4e0e5b9807 100644
--- a/js/ui/hotCorner.js
+++ b/js/ui/hotCorner.js
@@ -50,7 +50,7 @@ class HotCorner extends PanelMenu.SingleIconButton {
              event.type() == Clutter.EventType.BUTTON_PRESS)) {
             let button = event.get_button();
             if (button == Gdk.BUTTON_PRIMARY && Main.overview.shouldToggleByCornerOrButton())
-                Main.overview.toggle();
+                Main.overview.toggleWindows();
             else if (button == Gdk.BUTTON_SECONDARY)
                 this.menu.toggle();
         }
diff --git a/js/ui/main.js b/js/ui/main.js
index 08d634a16f..0ef29e1df0 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -108,7 +108,7 @@ function _sessionUpdated() {
     wm.setCustomKeybindingHandler('panel-main-menu',
                                   Shell.ActionMode.NORMAL |
                                   Shell.ActionMode.OVERVIEW,
-                                  sessionMode.hasOverview ? overview.toggle.bind(overview) : null);
+                                  sessionMode.hasOverview ? overview.toggleWindows.bind(overview) : null);
     wm.allowKeybinding('overlay-key', Shell.ActionMode.NORMAL |
                                       Shell.ActionMode.OVERVIEW);
 
diff --git a/js/ui/overview.js b/js/ui/overview.js
index 303e4960e5..cbdd18a773 100644
--- a/js/ui/overview.js
+++ b/js/ui/overview.js
@@ -137,6 +137,8 @@ var Overview = class {
 
         this.visible = false;           // animating to overview, in overview, animating out
         this._shown = false;            // show() and not hide()
+        this._toggleToHidden = false;   // Whether to hide the overview when either toggle function is called
+        this._targetPage = null;        // do we have a target page to animate to?
         this._modal = false;            // have a modal grab
         this.animationInProgress = false;
         this.visibleTarget = false;
@@ -265,6 +267,8 @@ var Overview = class {
     }
 
     _onPageChanged() {
+        this._toggleToHidden = false;
+
         // SideComponent hooks on this signal but can't connect directly to
         // viewSelector since it won't be created at the time the component
         // is enabled, so rely on the overview and re-issue it from here.
@@ -429,10 +433,12 @@ var Overview = class {
     }
 
     _showOrSwitchPage(page) {
-        if (this.visible)
+        if (this.visible) {
             this.viewSelector.setActivePage(page);
-        else
+        } else {
+            this._targetPage = page;
             this.show();
+        }
     }
 
     showApps() {
@@ -500,6 +506,32 @@ var Overview = class {
         this.hide();
     }
 
+    toggleWindows() {
+        if (this.isDummy)
+            return;
+
+        if (!this.visible ||
+            this.viewSelector.getActivePage() !== ViewSelector.ViewPage.WINDOWS) {
+            this.showWindows();
+            return;
+        }
+
+        if (!this._toggleToHidden) {
+            this.showApps();
+            return;
+        }
+
+        if (!Main.workspaceMonitor.hasVisibleWindows) {
+            // There are active windows but all of them are
+            // hidden, so we get back to show the icons grid.
+            this.showApps();
+            return;
+        }
+
+        // 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
@@ -572,7 +604,16 @@ var Overview = class {
         this._activationTime = GLib.get_monotonic_time() / GLib.USEC_PER_SEC;
 
         Meta.disable_unredirect_for_display(global.display);
-        this.viewSelector.show();
+
+        if (!this._targetPage)
+            this._targetPage = ViewSelector.ViewPage.WINDOWS;
+
+        this.viewSelector.show(this._targetPage);
+        this._targetPage = null;
+
+        // Since the overview is just becoming visible, we should toggle back
+        // the hidden state
+        this._toggleToHidden = true;
 
         this._overview.opacity = 0;
         this._overview.ease({
diff --git a/js/ui/viewSelector.js b/js/ui/viewSelector.js
index 42772086ef..3443663b2b 100644
--- a/js/ui/viewSelector.js
+++ b/js/ui/viewSelector.js
@@ -223,7 +223,7 @@ var ViewSelector = class {
                               Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
                               Shell.ActionMode.NORMAL |
                               Shell.ActionMode.OVERVIEW,
-                              Main.overview.toggle.bind(Main.overview));
+                              Main.overview.toggleWindows.bind(Main.overview));
 
         let side;
         if (Clutter.get_default_text_direction() == Clutter.TextDirection.RTL)
@@ -258,11 +258,11 @@ var ViewSelector = class {
         Main.overview.show();
     }
 
-    show() {
+    show(viewPage) {
         this.reset();
         this._workspacesDisplay.show(true);
 
-        this._showPage(this._appsPage);
+        this._showPage(this._pageFromViewPage(viewPage));
     }
 
     animateFromOverview() {


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