workspacesView: Move workspace scroll code to windowManager
This will allow sharing the code for the new super-scroll functionality. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1612>
This commit is contained in:
parent
463000d04d
commit
26a39bdf78
@ -27,6 +27,7 @@ var DIALOG_SHOW_WINDOW_ANIMATION_TIME = 100;
|
|||||||
var DESTROY_WINDOW_ANIMATION_TIME = 150;
|
var DESTROY_WINDOW_ANIMATION_TIME = 150;
|
||||||
var DIALOG_DESTROY_WINDOW_ANIMATION_TIME = 100;
|
var DIALOG_DESTROY_WINDOW_ANIMATION_TIME = 100;
|
||||||
var WINDOW_ANIMATION_TIME = 250;
|
var WINDOW_ANIMATION_TIME = 250;
|
||||||
|
var SCROLL_TIMEOUT_TIME = 150;
|
||||||
var DIM_BRIGHTNESS = -0.3;
|
var DIM_BRIGHTNESS = -0.3;
|
||||||
var DIM_TIME = 500;
|
var DIM_TIME = 500;
|
||||||
var UNDIM_TIME = 250;
|
var UNDIM_TIME = 250;
|
||||||
@ -571,6 +572,7 @@ var WindowManager = class {
|
|||||||
this._allowedKeybindings = {};
|
this._allowedKeybindings = {};
|
||||||
|
|
||||||
this._isWorkspacePrepended = false;
|
this._isWorkspacePrepended = false;
|
||||||
|
this._canScroll = true; // limiting scrolling speed
|
||||||
|
|
||||||
this._shellwm.connect('kill-window-effects', (shellwm, actor) => {
|
this._shellwm.connect('kill-window-effects', (shellwm, actor) => {
|
||||||
this._minimizeWindowDone(shellwm, actor);
|
this._minimizeWindowDone(shellwm, actor);
|
||||||
@ -1846,6 +1848,75 @@ var WindowManager = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleWorkspaceScroll(event) {
|
||||||
|
if (!this._canScroll)
|
||||||
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
|
||||||
|
if (event.type() !== Clutter.EventType.SCROLL)
|
||||||
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
|
||||||
|
if (event.is_pointer_emulated())
|
||||||
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
|
||||||
|
let direction = event.get_scroll_direction();
|
||||||
|
if (direction === Clutter.ScrollDirection.SMOOTH) {
|
||||||
|
const [dx, dy] = event.get_scroll_delta();
|
||||||
|
if (Math.abs(dx) > Math.abs(dy)) {
|
||||||
|
direction = dx < 0
|
||||||
|
? Clutter.ScrollDirection.RIGHT
|
||||||
|
: Clutter.ScrollDirection.LEFT;
|
||||||
|
} else if (Math.abs(dy) > Math.abs(dx)) {
|
||||||
|
direction = dy < 0
|
||||||
|
? Clutter.ScrollDirection.UP
|
||||||
|
: Clutter.ScrollDirection.DOWN;
|
||||||
|
} else {
|
||||||
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const workspaceManager = global.workspace_manager;
|
||||||
|
const vertical = workspaceManager.layout_rows === -1;
|
||||||
|
const rtl = this.text_direction === Clutter.TextDirection.RTL;
|
||||||
|
const activeWs = workspaceManager.get_active_workspace();
|
||||||
|
let ws;
|
||||||
|
switch (direction) {
|
||||||
|
case Clutter.ScrollDirection.UP:
|
||||||
|
if (vertical)
|
||||||
|
ws = activeWs.get_neighbor(Meta.MotionDirection.UP);
|
||||||
|
else if (rtl)
|
||||||
|
ws = activeWs.get_neighbor(Meta.MotionDirection.RIGHT);
|
||||||
|
else
|
||||||
|
ws = activeWs.get_neighbor(Meta.MotionDirection.LEFT);
|
||||||
|
break;
|
||||||
|
case Clutter.ScrollDirection.DOWN:
|
||||||
|
if (vertical)
|
||||||
|
ws = activeWs.get_neighbor(Meta.MotionDirection.DOWN);
|
||||||
|
else if (rtl)
|
||||||
|
ws = activeWs.get_neighbor(Meta.MotionDirection.LEFT);
|
||||||
|
else
|
||||||
|
ws = activeWs.get_neighbor(Meta.MotionDirection.RIGHT);
|
||||||
|
break;
|
||||||
|
case Clutter.ScrollDirection.LEFT:
|
||||||
|
ws = activeWs.get_neighbor(Meta.MotionDirection.LEFT);
|
||||||
|
break;
|
||||||
|
case Clutter.ScrollDirection.RIGHT:
|
||||||
|
ws = activeWs.get_neighbor(Meta.MotionDirection.RIGHT);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
}
|
||||||
|
this.actionMoveWorkspace(ws);
|
||||||
|
|
||||||
|
this._canScroll = false;
|
||||||
|
GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
||||||
|
SCROLL_TIMEOUT_TIME, () => {
|
||||||
|
this._canScroll = true;
|
||||||
|
return GLib.SOURCE_REMOVE;
|
||||||
|
});
|
||||||
|
|
||||||
|
return Clutter.EVENT_STOP;
|
||||||
|
}
|
||||||
|
|
||||||
_confirmDisplayChange() {
|
_confirmDisplayChange() {
|
||||||
let dialog = new DisplayChangeDialog(this._shellwm);
|
let dialog = new DisplayChangeDialog(this._shellwm);
|
||||||
dialog.open();
|
dialog.open();
|
||||||
|
@ -10,7 +10,6 @@ const Workspace = imports.ui.workspace;
|
|||||||
|
|
||||||
var { ANIMATION_TIME } = imports.ui.overview;
|
var { ANIMATION_TIME } = imports.ui.overview;
|
||||||
var WORKSPACE_SWITCH_TIME = 250;
|
var WORKSPACE_SWITCH_TIME = 250;
|
||||||
var SCROLL_TIMEOUT_TIME = 150;
|
|
||||||
|
|
||||||
const MUTTER_SCHEMA = 'org.gnome.mutter';
|
const MUTTER_SCHEMA = 'org.gnome.mutter';
|
||||||
|
|
||||||
@ -527,7 +526,6 @@ class WorkspacesDisplay extends St.Widget {
|
|||||||
this._restackedNotifyId = 0;
|
this._restackedNotifyId = 0;
|
||||||
this._scrollEventId = 0;
|
this._scrollEventId = 0;
|
||||||
this._keyPressEventId = 0;
|
this._keyPressEventId = 0;
|
||||||
this._scrollTimeoutId = 0;
|
|
||||||
this._syncActualGeometryLater = 0;
|
this._syncActualGeometryLater = 0;
|
||||||
|
|
||||||
this._actualGeometry = null;
|
this._actualGeometry = null;
|
||||||
@ -535,7 +533,6 @@ class WorkspacesDisplay extends St.Widget {
|
|||||||
this._leavingOverview = false;
|
this._leavingOverview = false;
|
||||||
|
|
||||||
this._gestureActive = false; // touch(pad) gestures
|
this._gestureActive = false; // touch(pad) gestures
|
||||||
this._canScroll = true; // limiting scrolling speed
|
|
||||||
this._animating = false;
|
this._animating = false;
|
||||||
|
|
||||||
this.connect('destroy', this._onDestroy.bind(this));
|
this.connect('destroy', this._onDestroy.bind(this));
|
||||||
@ -559,11 +556,6 @@ class WorkspacesDisplay extends St.Widget {
|
|||||||
this._syncActualGeometryLater = 0;
|
this._syncActualGeometryLater = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._scrollTimeoutId !== 0) {
|
|
||||||
GLib.source_remove(this._scrollTimeoutId);
|
|
||||||
this._scrollTimeoutId = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
global.window_manager.disconnect(this._switchWorkspaceId);
|
global.window_manager.disconnect(this._switchWorkspaceId);
|
||||||
global.workspace_manager.disconnect(this._reorderWorkspacesdId);
|
global.workspace_manager.disconnect(this._reorderWorkspacesdId);
|
||||||
Main.overview.disconnect(this._windowDragBeginId);
|
Main.overview.disconnect(this._windowDragBeginId);
|
||||||
@ -882,70 +874,7 @@ class WorkspacesDisplay extends St.Widget {
|
|||||||
this._getMonitorIndexForEvent(event) != this._primaryIndex)
|
this._getMonitorIndexForEvent(event) != this._primaryIndex)
|
||||||
return Clutter.EVENT_PROPAGATE;
|
return Clutter.EVENT_PROPAGATE;
|
||||||
|
|
||||||
if (!this._canScroll)
|
return Main.wm.handleWorkspaceScroll(event);
|
||||||
return Clutter.EVENT_PROPAGATE;
|
|
||||||
|
|
||||||
if (event.is_pointer_emulated())
|
|
||||||
return Clutter.EVENT_PROPAGATE;
|
|
||||||
|
|
||||||
let direction = event.get_scroll_direction();
|
|
||||||
if (direction === Clutter.ScrollDirection.SMOOTH) {
|
|
||||||
const [dx, dy] = event.get_scroll_delta();
|
|
||||||
if (Math.abs(dx) > Math.abs(dy)) {
|
|
||||||
direction = dx < 0
|
|
||||||
? Clutter.ScrollDirection.RIGHT
|
|
||||||
: Clutter.ScrollDirection.LEFT;
|
|
||||||
} else if (Math.abs(dy) > Math.abs(dx)) {
|
|
||||||
direction = dy < 0
|
|
||||||
? Clutter.ScrollDirection.UP
|
|
||||||
: Clutter.ScrollDirection.DOWN;
|
|
||||||
} else {
|
|
||||||
return Clutter.EVENT_PROPAGATE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let workspaceManager = global.workspace_manager;
|
|
||||||
const vertical = workspaceManager.layout_rows === -1;
|
|
||||||
const rtl = this.text_direction === Clutter.TextDirection.RTL;
|
|
||||||
let activeWs = workspaceManager.get_active_workspace();
|
|
||||||
let ws;
|
|
||||||
switch (direction) {
|
|
||||||
case Clutter.ScrollDirection.UP:
|
|
||||||
if (vertical)
|
|
||||||
ws = activeWs.get_neighbor(Meta.MotionDirection.UP);
|
|
||||||
else if (rtl)
|
|
||||||
ws = activeWs.get_neighbor(Meta.MotionDirection.RIGHT);
|
|
||||||
else
|
|
||||||
ws = activeWs.get_neighbor(Meta.MotionDirection.LEFT);
|
|
||||||
break;
|
|
||||||
case Clutter.ScrollDirection.DOWN:
|
|
||||||
if (vertical)
|
|
||||||
ws = activeWs.get_neighbor(Meta.MotionDirection.DOWN);
|
|
||||||
else if (rtl)
|
|
||||||
ws = activeWs.get_neighbor(Meta.MotionDirection.LEFT);
|
|
||||||
else
|
|
||||||
ws = activeWs.get_neighbor(Meta.MotionDirection.RIGHT);
|
|
||||||
break;
|
|
||||||
case Clutter.ScrollDirection.LEFT:
|
|
||||||
ws = activeWs.get_neighbor(Meta.MotionDirection.LEFT);
|
|
||||||
break;
|
|
||||||
case Clutter.ScrollDirection.RIGHT:
|
|
||||||
ws = activeWs.get_neighbor(Meta.MotionDirection.RIGHT);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return Clutter.EVENT_PROPAGATE;
|
|
||||||
}
|
|
||||||
Main.wm.actionMoveWorkspace(ws);
|
|
||||||
|
|
||||||
this._canScroll = false;
|
|
||||||
this._scrollTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
|
|
||||||
SCROLL_TIMEOUT_TIME, () => {
|
|
||||||
this._canScroll = true;
|
|
||||||
this._scrollTimeoutId = 0;
|
|
||||||
return GLib.SOURCE_REMOVE;
|
|
||||||
});
|
|
||||||
|
|
||||||
return Clutter.EVENT_STOP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onKeyPressEvent(actor, event) {
|
_onKeyPressEvent(actor, event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user