[gnome-shell] workspace: Make computeLayout() return a layout object
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] workspace: Make computeLayout() return a layout object
- Date: Mon, 1 Feb 2021 13:16:18 +0000 (UTC)
commit 8d9a92fe98b27a45070ec61ba83375f7cf1ea442
Author: Jonas Dreßler <verdre v0yd nl>
Date: Mon Feb 1 11:07:33 2021 +0100
workspace: Make computeLayout() return a layout object
Start cleaning up the whole mess around the layout object a bit and
return a new object in the LayoutStrategies computeLayout()
implementation. This object is supposed to be opaque to the API user and
will only be passed to the layout strategy.
For now, keep setting a few things on that object from outside, we'll
clean that up later.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1617>
js/ui/workspace.js | 51 +++++++++++++++++++++++++++++++--------------------
1 file changed, 31 insertions(+), 20 deletions(-)
---
diff --git a/js/ui/workspace.js b/js/ui/workspace.js
index 9ee108fc72..c152794d60 100644
--- a/js/ui/workspace.js
+++ b/js/ui/workspace.js
@@ -114,16 +114,11 @@ var LayoutStrategy = class {
this._columnSpacing = params.columnSpacing;
}
- // Compute strategy-specific window slots for each window in
- // @windows, given the @layout. The strategy may also use @layout
- // as strategy-specific storage.
+ // Compute a strategy-specific overall layout given a list of WindowPreviews
+ // @windows and the strategy-specific @layoutParams.
//
- // This must calculate:
- // * maxColumns - The maximum number of columns used by the layout.
- // * gridWidth - The total width used by the grid, unscaled, unspaced.
- // * gridHeight - The totial height used by the grid, unscaled, unspaced.
- // * rows - A list of rows, which should be instantiated by _newRow.
- computeLayout(_windows, _layout) {
+ // Returns a strategy-specific layout object that is opaque to the user.
+ computeLayout(_windows, _layoutParams) {
throw new GObject.NotImplementedError(`computeLayout in ${this.constructor.name}`);
}
@@ -210,8 +205,15 @@ var UnalignedLayoutStrategy = class extends LayoutStrategy {
row.windows.sort((a, b) => a.windowCenter.x - b.windowCenter.x);
}
- computeLayout(windows, layout) {
- let numRows = layout.numRows;
+ computeLayout(windows, layoutParams) {
+ layoutParams = Params.parse(layoutParams, {
+ numRows: 0,
+ });
+
+ if (layoutParams.numRows === 0)
+ throw new Error(`${this.constructor.name}: No numRows given in layout params`);
+
+ const numRows = layoutParams.numRows;
let rows = [];
let totalWidth = 0;
@@ -261,10 +263,13 @@ var UnalignedLayoutStrategy = class extends LayoutStrategy {
gridHeight += row.fullHeight;
}
- layout.rows = rows;
- layout.maxColumns = maxRow.windows.length;
- layout.gridWidth = maxRow.fullWidth;
- layout.gridHeight = gridHeight;
+ return {
+ numRows,
+ rows,
+ maxColumns: maxRow.windows.length,
+ gridWidth: maxRow.fullWidth,
+ gridHeight,
+ };
}
computeScaleAndSpace(layout) {
@@ -491,25 +496,31 @@ var WorkspaceLayout = GObject.registerClass({
columnSpacing,
});
- let lastLayout = {};
+ let lastLayout = null;
+ let lastNumColumns = -1;
for (let numRows = 1; ; numRows++) {
- let numColumns = Math.ceil(this._sortedWindows.length / numRows);
+ const numColumns = Math.ceil(this._sortedWindows.length / numRows);
// If adding a new row does not change column count just stop
// (for instance: 9 windows, with 3 rows -> 3 columns, 4 rows ->
// 3 columns as well => just use 3 rows then)
- if (numColumns === lastLayout.numColumns)
+ if (numColumns === lastNumColumns)
break;
- let layout = { area, strategy, numRows, numColumns };
- strategy.computeLayout(this._sortedWindows, layout);
+ const layout = strategy.computeLayout(this._sortedWindows, {
+ numRows,
+ });
+ layout.area = area;
+ layout.strategy = strategy;
+
strategy.computeScaleAndSpace(layout);
if (!this._isBetterLayout(lastLayout, layout))
break;
lastLayout = layout;
+ lastNumColumns = numColumns;
}
return lastLayout;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]