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>
This commit is contained in:
Georges Basile Stavracas Neto 2021-02-05 13:22:18 -03:00 committed by Marge Bot
parent d6a1414a94
commit 2e817d3fa8
2 changed files with 31 additions and 10 deletions

View File

@ -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())
// 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();
if (this._shouldLeaveOverview())
Main.activateWindow(clone.metaWindow, time, wsIndex);
else
this.metaWorkspace?.activate(time);
}
// Draggable target interface

View File

@ -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);
}