[gnome-shell] workspace: Always leave overview when in app grid state



commit 2e817d3fa8cf3697511b7fca59e2ebeb82d2ee15
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Feb 5 13:22:18 2021 -0300

    workspace: Always leave overview when in app grid state
    
    The behavior of workspaces is different depending on whether
    the overview is in window picker state, or app grid state.
    
    When in window picker state, clicking on adjacent workspaces
    should only activate them, without hiding the overview; and
    clicking on the active workspace hides the overview. When in
    app grid state, clicking on a workspace must always hide the
    overview.
    
    Pass the overview adjustment to Workspace, and leave overview
    if the overview state is bigger than WINDOW_PICKER.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1645>

 js/ui/workspace.js      | 33 +++++++++++++++++++++++++--------
 js/ui/workspacesView.js |  8 ++++++--
 2 files changed, 31 insertions(+), 10 deletions(-)
---
diff --git a/js/ui/workspace.js b/js/ui/workspace.js
index 954812bdc5..b8893357a0 100644
--- a/js/ui/workspace.js
+++ b/js/ui/workspace.js
@@ -6,6 +6,7 @@ const { Clutter, GLib, GObject, Graphene, Meta, St } = imports.gi;
 const Background = imports.ui.background;
 const DND = imports.ui.dnd;
 const Main = imports.ui.main;
+const OverviewControls = imports.ui.overviewControls;
 const Params = imports.misc.params;
 const Util = imports.misc.util;
 const { WindowPreview } = imports.ui.windowPreview;
@@ -932,7 +933,7 @@ class WorkspaceBackground extends St.Widget {
  */
 var Workspace = GObject.registerClass(
 class Workspace extends St.Widget {
-    _init(metaWorkspace, monitorIndex) {
+    _init(metaWorkspace, monitorIndex, overviewAdjustment) {
         super._init({
             style_class: 'window-picker',
             pivot_point: new Graphene.Point({ x: 0.5, y: 0.5 }),
@@ -942,6 +943,7 @@ class Workspace extends St.Widget {
 
         this.metaWorkspace = metaWorkspace;
 
+        this._overviewAdjustment = overviewAdjustment;
         this.monitorIndex = monitorIndex;
         this._monitor = Main.layoutManager.monitors[this.monitorIndex];
 
@@ -954,12 +956,15 @@ class Workspace extends St.Widget {
 
         const clickAction = new Clutter.ClickAction();
         clickAction.connect('clicked', action => {
-            // Only switch to the workspace when there's no application
-            // windows open. The problem is that it's too easy to miss
-            // an app window and get the wrong one focused.
-            if ((action.get_button() === 1 || action.get_button() === 0) &&
-                this.isEmpty())
-                Main.overview.hide();
+            // Switch to the workspace when not the active one, leave the
+            // overview otherwise.
+            if (action.get_button() === 1 || action.get_button() === 0) {
+                const leaveOverview = this._shouldLeaveOverview();
+
+                this.metaWorkspace?.activate(global.get_current_time());
+                if (leaveOverview)
+                    Main.overview.hide();
+            }
         });
         this.bind_property('mapped', clickAction, 'enabled', GObject.BindingFlags.SYNC_CREATE);
         this.add_action(clickAction);
@@ -995,6 +1000,14 @@ class Workspace extends St.Widget {
         this._delegate = this;
     }
 
+    _shouldLeaveOverview() {
+        if (!this.metaWorkspace || this.metaWorkspace.active)
+            return true;
+
+        const overviewState = this._overviewAdjustment.value;
+        return overviewState > OverviewControls.ControlsState.WINDOW_PICKER;
+    }
+
     vfunc_get_focus_chain() {
         return this.layout_manager.getFocusChain();
     }
@@ -1267,7 +1280,11 @@ class Workspace extends St.Widget {
 
     _onCloneSelected(clone, time) {
         const wsIndex = this.metaWorkspace?.index();
-        Main.activateWindow(clone.metaWindow, time, wsIndex);
+
+        if (this._shouldLeaveOverview())
+            Main.activateWindow(clone.metaWindow, time, wsIndex);
+        else
+            this.metaWorkspace?.activate(time);
     }
 
     // Draggable target interface
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index b1b5eda024..0cfe91561b 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -449,7 +449,10 @@ class WorkspacesView extends WorkspacesViewBase {
             let workspace;
 
             if (j >= this._workspaces.length) { /* added */
-                workspace = new Workspace.Workspace(metaWorkspace, this._monitorIndex);
+                workspace = new Workspace.Workspace(
+                    metaWorkspace,
+                    this._monitorIndex,
+                    this._overviewAdjustment);
                 this.add_actor(workspace);
                 this._workspaces[j] = workspace;
             } else  {
@@ -540,7 +543,8 @@ var ExtraWorkspaceView = GObject.registerClass(
 class ExtraWorkspaceView extends WorkspacesViewBase {
     _init(monitorIndex, overviewAdjustment) {
         super._init(monitorIndex, overviewAdjustment);
-        this._workspace = new Workspace.Workspace(null, monitorIndex);
+        this._workspace =
+            new Workspace.Workspace(null, monitorIndex, overviewAdjustment);
         this.add_actor(this._workspace);
     }
 


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