workspaceThumbnail: Use scroll adjustment

This will allow it to share adjustment with WorkspacesDisplay in the next
commit.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/821
This commit is contained in:
Alexander Mikhaylenko 2019-06-28 01:51:10 +05:00 committed by Florian Müllner
parent 8f4414de97
commit f55ff01239

View File

@ -658,7 +658,6 @@ var ThumbnailsBox = GObject.registerClass({
this._pendingScaleUpdate = false; this._pendingScaleUpdate = false;
this._stateUpdateQueued = false; this._stateUpdateQueued = false;
this._animatingIndicator = false; this._animatingIndicator = false;
this._indicatorY = 0; // only used when _animatingIndicator is true
this._stateCounts = {}; this._stateCounts = {};
for (let key in ThumbnailState) for (let key in ThumbnailState)
@ -701,6 +700,21 @@ var ThumbnailsBox = GObject.registerClass({
this._nWorkspacesNotifyId = 0; this._nWorkspacesNotifyId = 0;
this._syncStackingId = 0; this._syncStackingId = 0;
this._workareasChangedId = 0; this._workareasChangedId = 0;
let workspaceManager = global.workspace_manager;
let activeWorkspaceIndex = workspaceManager.get_active_workspace_index();
this._scrollAdjustment = new St.Adjustment({
value: activeWorkspaceIndex,
lower: 0,
page_increment: 1,
page_size: 1,
step_increment: 0,
upper: workspaceManager.n_workspaces,
});
this._scrollAdjustment.connect('notify::value', () => {
this.queue_relayout();
});
} }
_updateSwitcherVisibility() { _updateSwitcherVisibility() {
@ -968,6 +982,8 @@ var ThumbnailsBox = GObject.registerClass({
let oldNumWorkspaces = validThumbnails.length; let oldNumWorkspaces = validThumbnails.length;
let newNumWorkspaces = workspaceManager.n_workspaces; let newNumWorkspaces = workspaceManager.n_workspaces;
this._scrollAdjustment.upper = newNumWorkspaces;
if (newNumWorkspaces > oldNumWorkspaces) { if (newNumWorkspaces > oldNumWorkspaces) {
this.addThumbnails(oldNumWorkspaces, newNumWorkspaces - oldNumWorkspaces); this.addThumbnails(oldNumWorkspaces, newNumWorkspaces - oldNumWorkspaces);
} else { } else {
@ -1056,21 +1072,6 @@ var ThumbnailsBox = GObject.registerClass({
return this._scale; return this._scale;
} }
// eslint-disable-next-line camelcase
set indicator_y(indicatorY) {
if (this._indicatorY == indicatorY)
return;
this._indicatorY = indicatorY;
this.notify('indicator-y');
this.queue_relayout();
}
// eslint-disable-next-line camelcase
get indicator_y() {
return this._indicatorY;
}
_setThumbnailState(thumbnail, state) { _setThumbnailState(thumbnail, state) {
this._stateCounts[thumbnail.state]--; this._stateCounts[thumbnail.state]--;
thumbnail.state = state; thumbnail.state = state;
@ -1263,13 +1264,16 @@ var ThumbnailsBox = GObject.registerClass({
else else
slideOffset = thumbnailWidth + themeNode.get_padding(St.Side.RIGHT); slideOffset = thumbnailWidth + themeNode.get_padding(St.Side.RIGHT);
let indicatorY1 = this._indicatorY; let indicatorValue = this._scrollAdjustment.value;
let indicatorY2; let indicatorUpperWs = Math.ceil(indicatorValue);
// when not animating, the workspace position overrides this._indicatorY let indicatorLowerWs = Math.floor(indicatorValue);
let activeWorkspace = workspaceManager.get_active_workspace();
let indicatorWorkspace = !this._animatingIndicator ? activeWorkspace : null;
let indicatorThemeNode = this._indicator.get_theme_node();
let indicatorLowerY1 = 0;
let indicatorLowerY2 = 0;
let indicatorUpperY1 = 0;
let indicatorUpperY2 = 0;
let indicatorThemeNode = this._indicator.get_theme_node();
let indicatorTopFullBorder = indicatorThemeNode.get_padding(St.Side.TOP) + indicatorThemeNode.get_border_width(St.Side.TOP); let indicatorTopFullBorder = indicatorThemeNode.get_padding(St.Side.TOP) + indicatorThemeNode.get_border_width(St.Side.TOP);
let indicatorBottomFullBorder = indicatorThemeNode.get_padding(St.Side.BOTTOM) + indicatorThemeNode.get_border_width(St.Side.BOTTOM); let indicatorBottomFullBorder = indicatorThemeNode.get_padding(St.Side.BOTTOM) + indicatorThemeNode.get_border_width(St.Side.BOTTOM);
let indicatorLeftFullBorder = indicatorThemeNode.get_padding(St.Side.LEFT) + indicatorThemeNode.get_border_width(St.Side.LEFT); let indicatorLeftFullBorder = indicatorThemeNode.get_padding(St.Side.LEFT) + indicatorThemeNode.get_border_width(St.Side.LEFT);
@ -1321,9 +1325,13 @@ var ThumbnailsBox = GObject.registerClass({
let y2 = Math.round(y + thumbnailHeight); let y2 = Math.round(y + thumbnailHeight);
let roundedVScale = (y2 - y1) / portholeHeight; let roundedVScale = (y2 - y1) / portholeHeight;
if (thumbnail.metaWorkspace == indicatorWorkspace) { if (i === indicatorUpperWs) {
indicatorY1 = y1; indicatorUpperY1 = y1;
indicatorY2 = y2; indicatorUpperY2 = y2;
}
if (i === indicatorLowerWs) {
indicatorLowerY1 = y1;
indicatorLowerY2 = y2;
} }
// Allocating a scaled actor is funny - x1/y1 correspond to the origin // Allocating a scaled actor is funny - x1/y1 correspond to the origin
@ -1349,23 +1357,22 @@ var ThumbnailsBox = GObject.registerClass({
childBox.x1 = box.x2 - thumbnailWidth; childBox.x1 = box.x2 - thumbnailWidth;
childBox.x2 = box.x2; childBox.x2 = box.x2;
} }
let indicatorY1 = indicatorLowerY1 +
(indicatorUpperY1 - indicatorLowerY1) * (indicatorValue % 1);
let indicatorY2 = indicatorLowerY2 +
(indicatorUpperY2 - indicatorLowerY2) * (indicatorValue % 1);
childBox.x1 -= indicatorLeftFullBorder; childBox.x1 -= indicatorLeftFullBorder;
childBox.x2 += indicatorRightFullBorder; childBox.x2 += indicatorRightFullBorder;
childBox.y1 = indicatorY1 - indicatorTopFullBorder; childBox.y1 = indicatorY1 - indicatorTopFullBorder;
childBox.y2 = (indicatorY2 ? indicatorY2 : indicatorY1 + thumbnailHeight) + indicatorBottomFullBorder; childBox.y2 = indicatorY2 + indicatorBottomFullBorder;
this._indicator.allocate(childBox, flags); this._indicator.allocate(childBox, flags);
} }
_activeWorkspaceChanged(_wm, _from, _to, _direction) { _activeWorkspaceChanged(_wm, from, to, _direction) {
let workspaceManager = global.workspace_manager; this._scrollAdjustment.value = from;
let activeWorkspace = workspaceManager.get_active_workspace();
let thumbnail = this._thumbnails.find(t => t.metaWorkspace == activeWorkspace);
this._animatingIndicator = true; this._animatingIndicator = true;
let indicatorThemeNode = this._indicator.get_theme_node(); this._scrollAdjustment.ease(to, {
let indicatorTopFullBorder = indicatorThemeNode.get_padding(St.Side.TOP) + indicatorThemeNode.get_border_width(St.Side.TOP);
this.indicator_y = this._indicator.allocation.y1 + indicatorTopFullBorder;
this.ease_property('indicator-y', thumbnail.allocation.y1, {
progress_mode: Clutter.AnimationMode.EASE_OUT_QUAD, progress_mode: Clutter.AnimationMode.EASE_OUT_QUAD,
duration: WorkspacesView.WORKSPACE_SWITCH_TIME, duration: WorkspacesView.WORKSPACE_SWITCH_TIME,
onComplete: () => { onComplete: () => {