diff --git a/js/ui/workspace.js b/js/ui/workspace.js index 954812bdc..b8893357a 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 b1b5eda02..0cfe91561 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); }