2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported Workspace */
|
2008-12-02 11:15:00 -05:00
|
|
|
|
2020-12-31 12:19:43 -05:00
|
|
|
const { Clutter, GLib, GObject, Graphene, Meta, St } = imports.gi;
|
2008-12-02 11:15:00 -05:00
|
|
|
|
2020-06-01 18:24:17 -04:00
|
|
|
const Background = imports.ui.background;
|
2009-02-10 11:15:59 -05:00
|
|
|
const DND = imports.ui.dnd;
|
2008-12-02 11:15:00 -05:00
|
|
|
const Main = imports.ui.main;
|
2021-02-05 11:22:18 -05:00
|
|
|
const OverviewControls = imports.ui.overviewControls;
|
2021-02-01 04:09:51 -05:00
|
|
|
const Params = imports.misc.params;
|
2021-02-01 06:08:30 -05:00
|
|
|
const Util = imports.misc.util;
|
2020-06-15 17:03:06 -04:00
|
|
|
const { WindowPreview } = imports.ui.windowPreview;
|
2010-03-09 17:31:06 -05:00
|
|
|
|
2020-12-07 09:24:37 -05:00
|
|
|
var WINDOW_PREVIEW_MAXIMUM_SCALE = 0.95;
|
2012-01-15 09:30:59 -05:00
|
|
|
|
2018-11-19 06:28:28 -05:00
|
|
|
var WINDOW_REPOSITIONING_DELAY = 750;
|
|
|
|
|
2012-08-08 13:27:46 -04:00
|
|
|
// When calculating a layout, we calculate the scale of windows and the percent
|
|
|
|
// of the available area the new layout uses. If the values for the new layout,
|
|
|
|
// when weighted with the values as below, are worse than the previous layout's,
|
|
|
|
// we stop looking for a new layout and use the previous layout.
|
|
|
|
// Otherwise, we keep looking for a new layout.
|
2017-07-18 13:47:27 -04:00
|
|
|
var LAYOUT_SCALE_WEIGHT = 1;
|
|
|
|
var LAYOUT_SPACE_WEIGHT = 0.1;
|
2009-09-04 15:25:17 -04:00
|
|
|
|
2021-02-08 10:33:06 -05:00
|
|
|
const BACKGROUND_CORNER_RADIUS_PIXELS = 30;
|
2021-02-22 06:50:29 -05:00
|
|
|
const BACKGROUND_MARGIN = 12;
|
2021-02-08 10:33:06 -05:00
|
|
|
|
2013-02-28 15:50:57 -05:00
|
|
|
// Window Thumbnail Layout Algorithm
|
|
|
|
// =================================
|
|
|
|
//
|
|
|
|
// General overview
|
|
|
|
// ----------------
|
|
|
|
//
|
|
|
|
// The window thumbnail layout algorithm calculates some optimal layout
|
|
|
|
// by computing layouts with some number of rows, calculating how good
|
|
|
|
// each layout is, and stopping iterating when it finds one that is worse
|
|
|
|
// than the previous layout. A layout consists of which windows are in
|
|
|
|
// which rows, row sizes and other general state tracking that would make
|
|
|
|
// calculating window positions from this information fairly easy.
|
|
|
|
//
|
|
|
|
// After a layout is computed that's considered the best layout, we
|
|
|
|
// compute the layout scale to fit it in the area, and then compute
|
|
|
|
// slots (sizes and positions) for each thumbnail.
|
|
|
|
//
|
|
|
|
// Layout generation
|
|
|
|
// -----------------
|
|
|
|
//
|
|
|
|
// Layout generation is naive and simple: we simply add windows to a row
|
|
|
|
// until we've added too many windows to a row, and then make a new row,
|
|
|
|
// until we have our required N rows. The potential issue with this strategy
|
|
|
|
// is that we may have too many windows at the bottom in some pathological
|
|
|
|
// cases, which tends to make the thumbnails have the shape of a pile of
|
|
|
|
// sand with a peak, with one window at the top.
|
|
|
|
//
|
|
|
|
// Scaling factors
|
|
|
|
// ---------------
|
|
|
|
//
|
|
|
|
// Thumbnail position is mostly straightforward -- the main issue is
|
|
|
|
// computing an optimal scale for each window that fits the constraints,
|
|
|
|
// and doesn't make the thumbnail too small to see. There are two factors
|
|
|
|
// involved in thumbnail scale to make sure that these two goals are met:
|
|
|
|
// the window scale (calculated by _computeWindowScale) and the layout
|
|
|
|
// scale (calculated by computeSizeAndScale).
|
|
|
|
//
|
|
|
|
// The calculation logic becomes slightly more complicated because row
|
|
|
|
// and column spacing are not scaled, they're constant, so we can't
|
|
|
|
// simply generate a bunch of window positions and then scale it. In
|
|
|
|
// practice, it's not too bad -- we can simply try to fit the layout
|
|
|
|
// in the input area minus whatever spacing we have, and then add
|
|
|
|
// it back afterwards.
|
|
|
|
//
|
|
|
|
// The window scale is constant for the window's size regardless of the
|
|
|
|
// input area or the layout scale or rows or anything else, and right
|
|
|
|
// now just enlarges the window if it's too small. The fact that this
|
|
|
|
// factor is stable makes it easy to calculate, so there's no sense
|
|
|
|
// in not applying it in most calculations.
|
|
|
|
//
|
|
|
|
// The layout scale depends on the input area, the rows, etc, but is the
|
|
|
|
// same for the entire layout, rather than being per-window. After
|
|
|
|
// generating the rows of windows, we basically do some basic math to
|
|
|
|
// fit the full, unscaled layout to the input area, as described above.
|
|
|
|
//
|
|
|
|
// With these two factors combined, the final scale of each thumbnail is
|
|
|
|
// simply windowScale * layoutScale... almost.
|
|
|
|
//
|
|
|
|
// There's one additional constraint: the thumbnail scale must never be
|
2020-06-08 03:23:08 -04:00
|
|
|
// larger than WINDOW_PREVIEW_MAXIMUM_SCALE, which means that the inequality:
|
2013-02-28 15:50:57 -05:00
|
|
|
//
|
2020-06-08 03:23:08 -04:00
|
|
|
// windowScale * layoutScale <= WINDOW_PREVIEW_MAXIMUM_SCALE
|
2013-02-28 15:50:57 -05:00
|
|
|
//
|
|
|
|
// must always be true. This is for each individual window -- while we
|
|
|
|
// could adjust layoutScale to make the largest thumbnail smaller than
|
2020-06-08 03:23:08 -04:00
|
|
|
// WINDOW_PREVIEW_MAXIMUM_SCALE, it would shrink windows which are already
|
2013-02-28 16:08:19 -05:00
|
|
|
// under the inequality. To solve this, we simply cheat: we simply keep
|
|
|
|
// each window's "cell" area to be the same, but we shrink the thumbnail
|
|
|
|
// and center it horizontally, and align it to the bottom vertically.
|
2013-02-28 15:50:57 -05:00
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var LayoutStrategy = class {
|
2021-02-01 04:09:51 -05:00
|
|
|
constructor(params) {
|
|
|
|
params = Params.parse(params, {
|
|
|
|
monitor: null,
|
|
|
|
rowSpacing: 0,
|
|
|
|
columnSpacing: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!params.monitor)
|
|
|
|
throw new Error(`No monitor param passed to ${this.constructor.name}`);
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2021-02-01 04:09:51 -05:00
|
|
|
this._monitor = params.monitor;
|
|
|
|
this._rowSpacing = params.rowSpacing;
|
|
|
|
this._columnSpacing = params.columnSpacing;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2021-02-01 05:07:33 -05:00
|
|
|
// Compute a strategy-specific overall layout given a list of WindowPreviews
|
|
|
|
// @windows and the strategy-specific @layoutParams.
|
2021-02-01 04:39:41 -05:00
|
|
|
//
|
2021-02-01 05:07:33 -05:00
|
|
|
// Returns a strategy-specific layout object that is opaque to the user.
|
|
|
|
computeLayout(_windows, _layoutParams) {
|
2021-02-01 04:39:41 -05:00
|
|
|
throw new GObject.NotImplementedError(`computeLayout in ${this.constructor.name}`);
|
|
|
|
}
|
|
|
|
|
2021-02-01 05:36:10 -05:00
|
|
|
// Given @layout and @area, compute the overall scale of the layout and
|
|
|
|
// space occupied by the layout.
|
2021-02-01 04:39:41 -05:00
|
|
|
//
|
2021-02-01 05:36:10 -05:00
|
|
|
// This method returns an array where the first element is the scale and
|
|
|
|
// the second element is the space.
|
2021-02-01 04:39:41 -05:00
|
|
|
//
|
2021-02-01 05:36:10 -05:00
|
|
|
// This method must be called before calling computeWindowSlots(), as it
|
|
|
|
// sets the fixed overall scale of the layout.
|
|
|
|
computeScaleAndSpace(_layout, _area) {
|
2021-02-01 04:39:41 -05:00
|
|
|
throw new GObject.NotImplementedError(`computeScaleAndSpace in ${this.constructor.name}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns an array with final position and size information for each
|
|
|
|
// window of the layout, given a bounding area that it will be inside of.
|
|
|
|
computeWindowSlots(_layout, _area) {
|
|
|
|
throw new GObject.NotImplementedError(`computeWindowSlots in ${this.constructor.name}`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var UnalignedLayoutStrategy = class extends LayoutStrategy {
|
2017-10-30 20:03:21 -04:00
|
|
|
_newRow() {
|
2012-08-08 13:27:46 -04:00
|
|
|
// Row properties:
|
|
|
|
//
|
|
|
|
// * x, y are the position of row, relative to area
|
|
|
|
//
|
|
|
|
// * width, height are the scaled versions of fullWidth, fullHeight
|
|
|
|
//
|
|
|
|
// * width also has the spacing in between windows. It's not in
|
|
|
|
// fullWidth, as the spacing is constant, whereas fullWidth is
|
|
|
|
// meant to be scaled
|
|
|
|
//
|
|
|
|
// * neither height/fullHeight have any sort of spacing or padding
|
|
|
|
return { x: 0, y: 0,
|
|
|
|
width: 0, height: 0,
|
|
|
|
fullWidth: 0, fullHeight: 0,
|
|
|
|
windows: [] };
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2013-02-28 15:00:59 -05:00
|
|
|
// Computes and returns an individual scaling factor for @window,
|
2019-05-15 15:32:29 -04:00
|
|
|
// to be applied in addition to the overall layout scale.
|
2017-10-30 20:03:21 -04:00
|
|
|
_computeWindowScale(window) {
|
2012-10-26 11:43:38 -04:00
|
|
|
// Since we align windows next to each other, the height of the
|
|
|
|
// thumbnails is much more important to preserve than the width of
|
|
|
|
// them, so two windows with equal height, but maybe differering
|
|
|
|
// widths line up.
|
2020-05-31 17:33:00 -04:00
|
|
|
let ratio = window.boundingBox.height / this._monitor.height;
|
2012-10-26 11:43:38 -04:00
|
|
|
|
|
|
|
// The purpose of this manipulation here is to prevent windows
|
|
|
|
// from getting too small. For something like a calculator window,
|
|
|
|
// we need to bump up the size just a bit to make sure it looks
|
|
|
|
// good. We'll use a multiplier of 1.5 for this.
|
|
|
|
|
|
|
|
// Map from [0, 1] to [1.5, 1]
|
2021-02-01 06:08:30 -05:00
|
|
|
return Util.lerp(1.5, 1, ratio);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2021-02-01 04:39:41 -05:00
|
|
|
_computeRowSizes(layout) {
|
|
|
|
let { rows, scale } = layout;
|
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
|
|
let row = rows[i];
|
|
|
|
row.width = row.fullWidth * scale + (row.windows.length - 1) * this._columnSpacing;
|
|
|
|
row.height = row.fullHeight * scale;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2021-02-01 04:39:41 -05:00
|
|
|
_keepSameRow(row, window, width, idealRowWidth) {
|
|
|
|
if (row.fullWidth + width <= idealRowWidth)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
let oldRatio = row.fullWidth / idealRowWidth;
|
|
|
|
let newRatio = (row.fullWidth + width) / idealRowWidth;
|
|
|
|
|
|
|
|
if (Math.abs(1 - newRatio) < Math.abs(1 - oldRatio))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2021-02-01 04:39:41 -05:00
|
|
|
_sortRow(row) {
|
|
|
|
// Sort windows horizontally to minimize travel distance.
|
|
|
|
// This affects in what order the windows end up in a row.
|
|
|
|
row.windows.sort((a, b) => a.windowCenter.x - b.windowCenter.x);
|
|
|
|
}
|
|
|
|
|
2021-02-01 05:07:33 -05:00
|
|
|
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;
|
2021-02-01 04:39:41 -05:00
|
|
|
|
|
|
|
let rows = [];
|
|
|
|
let totalWidth = 0;
|
|
|
|
for (let i = 0; i < windows.length; i++) {
|
|
|
|
let window = windows[i];
|
|
|
|
let s = this._computeWindowScale(window);
|
|
|
|
totalWidth += window.boundingBox.width * s;
|
|
|
|
}
|
|
|
|
|
|
|
|
let idealRowWidth = totalWidth / numRows;
|
|
|
|
|
|
|
|
// Sort windows vertically to minimize travel distance.
|
|
|
|
// This affects what rows the windows get placed in.
|
|
|
|
let sortedWindows = windows.slice();
|
|
|
|
sortedWindows.sort((a, b) => a.windowCenter.y - b.windowCenter.y);
|
|
|
|
|
|
|
|
let windowIdx = 0;
|
|
|
|
for (let i = 0; i < numRows; i++) {
|
|
|
|
let row = this._newRow();
|
|
|
|
rows.push(row);
|
|
|
|
|
|
|
|
for (; windowIdx < sortedWindows.length; windowIdx++) {
|
|
|
|
let window = sortedWindows[windowIdx];
|
|
|
|
let s = this._computeWindowScale(window);
|
|
|
|
let width = window.boundingBox.width * s;
|
|
|
|
let height = window.boundingBox.height * s;
|
|
|
|
row.fullHeight = Math.max(row.fullHeight, height);
|
|
|
|
|
|
|
|
// either new width is < idealWidth or new width is nearer from idealWidth then oldWidth
|
|
|
|
if (this._keepSameRow(row, window, width, idealRowWidth) || (i === numRows - 1)) {
|
|
|
|
row.windows.push(window);
|
|
|
|
row.fullWidth += width;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let gridHeight = 0;
|
|
|
|
let maxRow;
|
|
|
|
for (let i = 0; i < numRows; i++) {
|
|
|
|
let row = rows[i];
|
|
|
|
this._sortRow(row);
|
|
|
|
|
|
|
|
if (!maxRow || row.fullWidth > maxRow.fullWidth)
|
|
|
|
maxRow = row;
|
|
|
|
gridHeight += row.fullHeight;
|
|
|
|
}
|
|
|
|
|
2021-02-01 05:07:33 -05:00
|
|
|
return {
|
|
|
|
numRows,
|
|
|
|
rows,
|
|
|
|
maxColumns: maxRow.windows.length,
|
|
|
|
gridWidth: maxRow.fullWidth,
|
|
|
|
gridHeight,
|
|
|
|
};
|
2021-02-01 04:39:41 -05:00
|
|
|
}
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2021-02-01 05:36:10 -05:00
|
|
|
computeScaleAndSpace(layout, area) {
|
2012-08-08 13:27:46 -04:00
|
|
|
let hspacing = (layout.maxColumns - 1) * this._columnSpacing;
|
2012-12-13 13:28:25 -05:00
|
|
|
let vspacing = (layout.numRows - 1) * this._rowSpacing;
|
2012-08-08 13:27:46 -04:00
|
|
|
|
|
|
|
let spacedWidth = area.width - hspacing;
|
|
|
|
let spacedHeight = area.height - vspacing;
|
|
|
|
|
|
|
|
let horizontalScale = spacedWidth / layout.gridWidth;
|
|
|
|
let verticalScale = spacedHeight / layout.gridHeight;
|
|
|
|
|
|
|
|
// Thumbnails should be less than 70% of the original size
|
2020-06-08 03:23:08 -04:00
|
|
|
let scale = Math.min(
|
|
|
|
horizontalScale, verticalScale, WINDOW_PREVIEW_MAXIMUM_SCALE);
|
2012-08-08 13:27:46 -04:00
|
|
|
|
|
|
|
let scaledLayoutWidth = layout.gridWidth * scale + hspacing;
|
|
|
|
let scaledLayoutHeight = layout.gridHeight * scale + vspacing;
|
|
|
|
let space = (scaledLayoutWidth * scaledLayoutHeight) / (area.width * area.height);
|
|
|
|
|
|
|
|
layout.scale = scale;
|
2021-02-01 05:36:10 -05:00
|
|
|
|
|
|
|
return [scale, space];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
computeWindowSlots(layout, area) {
|
2012-08-08 13:27:46 -04:00
|
|
|
this._computeRowSizes(layout);
|
|
|
|
|
2019-09-12 11:19:51 -04:00
|
|
|
let { rows, scale } = layout;
|
2012-08-08 13:27:46 -04:00
|
|
|
|
|
|
|
let slots = [];
|
|
|
|
|
2013-02-25 21:40:13 -05:00
|
|
|
// Do this in three parts.
|
2015-03-03 14:07:22 -05:00
|
|
|
let heightWithoutSpacing = 0;
|
2013-02-25 21:40:13 -05:00
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
|
|
let row = rows[i];
|
2015-03-03 14:07:22 -05:00
|
|
|
heightWithoutSpacing += row.height;
|
2013-02-25 21:40:13 -05:00
|
|
|
}
|
|
|
|
|
2015-03-03 14:07:22 -05:00
|
|
|
let verticalSpacing = (rows.length - 1) * this._rowSpacing;
|
|
|
|
let additionalVerticalScale = Math.min(1, (area.height - verticalSpacing) / heightWithoutSpacing);
|
2013-02-25 21:40:13 -05:00
|
|
|
|
2015-03-03 14:07:22 -05:00
|
|
|
// keep track how much smaller the grid becomes due to scaling
|
|
|
|
// so it can be centered again
|
2019-01-28 20:18:52 -05:00
|
|
|
let compensation = 0;
|
2012-08-08 13:27:46 -04:00
|
|
|
let y = 0;
|
2013-02-25 21:40:13 -05:00
|
|
|
|
2012-08-08 13:27:46 -04:00
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
|
|
let row = rows[i];
|
2013-04-22 18:04:56 -04:00
|
|
|
|
|
|
|
// If this window layout row doesn't fit in the actual
|
|
|
|
// geometry, then apply an additional scale to it.
|
2015-03-03 14:07:22 -05:00
|
|
|
let horizontalSpacing = (row.windows.length - 1) * this._columnSpacing;
|
|
|
|
let widthWithoutSpacing = row.width - horizontalSpacing;
|
|
|
|
let additionalHorizontalScale = Math.min(1, (area.width - horizontalSpacing) / widthWithoutSpacing);
|
|
|
|
|
|
|
|
if (additionalHorizontalScale < additionalVerticalScale) {
|
|
|
|
row.additionalScale = additionalHorizontalScale;
|
|
|
|
// Only consider the scaling in addition to the vertical scaling for centering.
|
|
|
|
compensation += (additionalVerticalScale - additionalHorizontalScale) * row.height;
|
|
|
|
} else {
|
|
|
|
row.additionalScale = additionalVerticalScale;
|
|
|
|
// No compensation when scaling vertically since centering based on a too large
|
|
|
|
// height would undo what vertical scaling is trying to achieve.
|
|
|
|
}
|
2013-04-22 18:04:56 -04:00
|
|
|
|
2019-01-28 20:18:52 -05:00
|
|
|
row.x = area.x + (Math.max(area.width - (widthWithoutSpacing * row.additionalScale + horizontalSpacing), 0) / 2);
|
2015-03-03 14:07:22 -05:00
|
|
|
row.y = area.y + (Math.max(area.height - (heightWithoutSpacing + verticalSpacing), 0) / 2) + y;
|
|
|
|
y += row.height * row.additionalScale + this._rowSpacing;
|
2012-08-08 13:27:46 -04:00
|
|
|
}
|
|
|
|
|
2019-08-19 15:12:21 -04:00
|
|
|
compensation /= 2;
|
2015-03-03 14:07:22 -05:00
|
|
|
|
2012-08-08 13:27:46 -04:00
|
|
|
for (let i = 0; i < rows.length; i++) {
|
2021-02-03 04:37:56 -05:00
|
|
|
const row = rows[i];
|
|
|
|
const rowY = row.y + compensation;
|
|
|
|
const rowHeight = row.height * row.additionalScale;
|
|
|
|
|
2013-02-25 19:23:39 -05:00
|
|
|
let x = row.x;
|
2012-08-08 13:27:46 -04:00
|
|
|
for (let j = 0; j < row.windows.length; j++) {
|
|
|
|
let window = row.windows[j];
|
|
|
|
|
2013-04-22 18:04:56 -04:00
|
|
|
let s = scale * this._computeWindowScale(window) * row.additionalScale;
|
2020-05-31 17:33:00 -04:00
|
|
|
let cellWidth = window.boundingBox.width * s;
|
|
|
|
let cellHeight = window.boundingBox.height * s;
|
2013-02-28 16:08:19 -05:00
|
|
|
|
2020-06-08 03:23:08 -04:00
|
|
|
s = Math.min(s, WINDOW_PREVIEW_MAXIMUM_SCALE);
|
2020-05-31 17:33:00 -04:00
|
|
|
let cloneWidth = window.boundingBox.width * s;
|
2019-09-01 05:49:58 -04:00
|
|
|
const cloneHeight = window.boundingBox.height * s;
|
2013-02-28 16:08:19 -05:00
|
|
|
|
|
|
|
let cloneX = x + (cellWidth - cloneWidth) / 2;
|
2021-02-03 04:37:56 -05:00
|
|
|
let cloneY;
|
|
|
|
|
|
|
|
// If there's only one row, align windows vertically centered inside the row
|
|
|
|
if (rows.length === 1)
|
|
|
|
cloneY = rowY + (rowHeight - cloneHeight) / 2;
|
|
|
|
// If there are multiple rows, align windows to the bottom edge of the row
|
|
|
|
else
|
|
|
|
cloneY = rowY + rowHeight - cellHeight;
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2017-08-22 13:05:11 -04:00
|
|
|
// Align with the pixel grid to prevent blurry windows at scale = 1
|
|
|
|
cloneX = Math.floor(cloneX);
|
|
|
|
cloneY = Math.floor(cloneY);
|
|
|
|
|
2019-09-01 05:49:58 -04:00
|
|
|
slots.push([cloneX, cloneY, cloneWidth, cloneHeight, window]);
|
2013-02-28 16:08:19 -05:00
|
|
|
x += cellWidth + this._columnSpacing;
|
2012-08-08 13:27:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return slots;
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2020-06-03 12:10:09 -04:00
|
|
|
function animateAllocation(actor, box) {
|
|
|
|
actor.save_easing_state();
|
|
|
|
actor.set_easing_mode(Clutter.AnimationMode.EASE_OUT_QUAD);
|
|
|
|
actor.set_easing_duration(200);
|
|
|
|
|
|
|
|
actor.allocate(box);
|
|
|
|
|
|
|
|
actor.restore_easing_state();
|
|
|
|
|
|
|
|
return actor.get_transition('allocation');
|
|
|
|
}
|
|
|
|
|
|
|
|
var WorkspaceLayout = GObject.registerClass({
|
|
|
|
Properties: {
|
|
|
|
'spacing': GObject.ParamSpec.double(
|
|
|
|
'spacing', 'Spacing', 'Spacing',
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
0, Infinity, 20),
|
|
|
|
'layout-frozen': GObject.ParamSpec.boolean(
|
|
|
|
'layout-frozen', 'Layout frozen', 'Layout frozen',
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
false),
|
|
|
|
},
|
|
|
|
}, class WorkspaceLayout extends Clutter.LayoutManager {
|
2021-02-16 17:11:30 -05:00
|
|
|
_init(metaWorkspace, monitorIndex, overviewAdjustment) {
|
2020-06-03 12:10:09 -04:00
|
|
|
super._init();
|
|
|
|
|
|
|
|
this._spacing = 20;
|
|
|
|
this._layoutFrozen = false;
|
|
|
|
|
2021-02-05 11:39:13 -05:00
|
|
|
this._metaWorkspace = metaWorkspace;
|
2020-06-03 12:10:09 -04:00
|
|
|
this._monitorIndex = monitorIndex;
|
2021-02-16 17:11:30 -05:00
|
|
|
this._overviewAdjustment = overviewAdjustment;
|
2020-06-03 12:10:09 -04:00
|
|
|
|
|
|
|
this._container = null;
|
|
|
|
this._windows = new Map();
|
|
|
|
this._sortedWindows = [];
|
|
|
|
this._lastBox = null;
|
|
|
|
this._windowSlots = [];
|
|
|
|
this._layout = null;
|
|
|
|
|
|
|
|
this._stateAdjustment = new St.Adjustment({
|
2020-07-07 06:44:50 -04:00
|
|
|
value: 0,
|
2020-06-03 12:10:09 -04:00
|
|
|
lower: 0,
|
|
|
|
upper: 1,
|
|
|
|
});
|
|
|
|
|
2020-06-26 11:06:38 -04:00
|
|
|
this._stateAdjustment.connect('notify::value', () => {
|
2021-02-05 11:39:13 -05:00
|
|
|
this.syncOverlays();
|
2020-06-26 11:06:38 -04:00
|
|
|
this.layout_changed();
|
|
|
|
});
|
2021-03-16 16:26:33 -04:00
|
|
|
|
|
|
|
this._workarea = null;
|
|
|
|
this._workareasChangedId = 0;
|
2020-06-03 12:10:09 -04:00
|
|
|
}
|
|
|
|
|
2021-02-01 05:36:10 -05:00
|
|
|
_isBetterScaleAndSpace(oldScale, oldSpace, scale, space) {
|
|
|
|
let spacePower = (space - oldSpace) * LAYOUT_SPACE_WEIGHT;
|
|
|
|
let scalePower = (scale - oldScale) * LAYOUT_SCALE_WEIGHT;
|
2020-06-03 12:10:09 -04:00
|
|
|
|
2021-02-01 05:36:10 -05:00
|
|
|
if (scale > oldScale && space > oldSpace) {
|
2020-06-03 12:10:09 -04:00
|
|
|
// Win win -- better scale and better space
|
|
|
|
return true;
|
2021-02-01 05:36:10 -05:00
|
|
|
} else if (scale > oldScale && space <= oldSpace) {
|
2020-06-03 12:10:09 -04:00
|
|
|
// Keep new layout only if scale gain outweighs aspect space loss
|
|
|
|
return scalePower > spacePower;
|
2021-02-01 05:36:10 -05:00
|
|
|
} else if (scale <= oldScale && space > oldSpace) {
|
2020-06-03 12:10:09 -04:00
|
|
|
// Keep new layout only if aspect space gain outweighs scale loss
|
|
|
|
return spacePower > scalePower;
|
|
|
|
} else {
|
|
|
|
// Lose -- worse scale and space
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_adjustSpacingAndPadding(rowSpacing, colSpacing, containerBox) {
|
|
|
|
if (this._sortedWindows.length === 0)
|
2021-03-03 10:02:03 -05:00
|
|
|
return [rowSpacing, colSpacing, containerBox];
|
2020-06-03 12:10:09 -04:00
|
|
|
|
|
|
|
// All of the overlays have the same chrome sizes,
|
|
|
|
// so just pick the first one.
|
|
|
|
const window = this._sortedWindows[0];
|
|
|
|
|
|
|
|
const [topOversize, bottomOversize] = window.chromeHeights();
|
|
|
|
const [leftOversize, rightOversize] = window.chromeWidths();
|
|
|
|
|
2021-01-14 16:48:15 -05:00
|
|
|
const oversize =
|
|
|
|
Math.max(topOversize, bottomOversize, leftOversize, rightOversize);
|
|
|
|
|
2021-02-08 12:58:27 -05:00
|
|
|
if (rowSpacing !== null)
|
2021-01-14 16:48:15 -05:00
|
|
|
rowSpacing += oversize;
|
2021-02-08 12:58:27 -05:00
|
|
|
if (colSpacing !== null)
|
2021-01-14 16:48:15 -05:00
|
|
|
colSpacing += oversize;
|
2020-06-03 12:10:09 -04:00
|
|
|
|
|
|
|
if (containerBox) {
|
2021-02-12 10:40:36 -05:00
|
|
|
const monitor = Main.layoutManager.monitors[this._monitorIndex];
|
2021-01-14 16:48:15 -05:00
|
|
|
|
2021-02-12 10:40:36 -05:00
|
|
|
const bottomPoint = new Graphene.Point3D({ y: containerBox.y2 });
|
|
|
|
const transformedBottomPoint =
|
|
|
|
this._container.apply_transform_to_point(bottomPoint);
|
|
|
|
const bottomFreeSpace =
|
|
|
|
(monitor.y + monitor.height) - transformedBottomPoint.y;
|
|
|
|
|
|
|
|
const [, bottomOverlap] = window.overlapHeights();
|
|
|
|
|
|
|
|
if ((bottomOverlap + oversize) > bottomFreeSpace)
|
|
|
|
containerBox.y2 -= (bottomOverlap + oversize) - bottomFreeSpace;
|
2020-06-03 12:10:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return [rowSpacing, colSpacing, containerBox];
|
|
|
|
}
|
|
|
|
|
|
|
|
_createBestLayout(area) {
|
2021-02-01 04:09:51 -05:00
|
|
|
const [rowSpacing, columnSpacing] =
|
2020-06-03 12:10:09 -04:00
|
|
|
this._adjustSpacingAndPadding(this._spacing, this._spacing, null);
|
|
|
|
|
|
|
|
// We look for the largest scale that allows us to fit the
|
|
|
|
// largest row/tallest column on the workspace.
|
2021-02-01 05:40:50 -05:00
|
|
|
this._layoutStrategy = new UnalignedLayoutStrategy({
|
2021-02-01 04:09:51 -05:00
|
|
|
monitor: Main.layoutManager.monitors[this._monitorIndex],
|
2020-06-03 12:10:09 -04:00
|
|
|
rowSpacing,
|
2021-02-01 04:09:51 -05:00
|
|
|
columnSpacing,
|
|
|
|
});
|
2020-06-03 12:10:09 -04:00
|
|
|
|
2021-02-01 05:07:33 -05:00
|
|
|
let lastLayout = null;
|
|
|
|
let lastNumColumns = -1;
|
2021-02-01 05:36:10 -05:00
|
|
|
let lastScale = 0;
|
|
|
|
let lastSpace = 0;
|
2020-06-03 12:10:09 -04:00
|
|
|
|
|
|
|
for (let numRows = 1; ; numRows++) {
|
2021-02-01 05:07:33 -05:00
|
|
|
const numColumns = Math.ceil(this._sortedWindows.length / numRows);
|
2020-06-03 12:10:09 -04:00
|
|
|
|
|
|
|
// 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)
|
2021-02-01 05:07:33 -05:00
|
|
|
if (numColumns === lastNumColumns)
|
2020-06-03 12:10:09 -04:00
|
|
|
break;
|
|
|
|
|
2021-02-01 05:40:50 -05:00
|
|
|
const layout = this._layoutStrategy.computeLayout(this._sortedWindows, {
|
2021-02-01 05:07:33 -05:00
|
|
|
numRows,
|
|
|
|
});
|
|
|
|
|
2021-02-01 05:40:50 -05:00
|
|
|
const [scale, space] = this._layoutStrategy.computeScaleAndSpace(layout, area);
|
2020-06-03 12:10:09 -04:00
|
|
|
|
2021-02-16 07:37:17 -05:00
|
|
|
if (lastLayout && !this._isBetterScaleAndSpace(lastScale, lastSpace, scale, space))
|
2020-06-03 12:10:09 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
lastLayout = layout;
|
2021-02-01 05:07:33 -05:00
|
|
|
lastNumColumns = numColumns;
|
2021-02-01 05:36:10 -05:00
|
|
|
lastScale = scale;
|
|
|
|
lastSpace = space;
|
2020-06-03 12:10:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return lastLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
_getWindowSlots(containerBox) {
|
|
|
|
[, , containerBox] =
|
|
|
|
this._adjustSpacingAndPadding(null, null, containerBox);
|
|
|
|
|
|
|
|
const availArea = {
|
|
|
|
x: parseInt(containerBox.x1),
|
|
|
|
y: parseInt(containerBox.y1),
|
|
|
|
width: parseInt(containerBox.get_width()),
|
|
|
|
height: parseInt(containerBox.get_height()),
|
|
|
|
};
|
|
|
|
|
2021-02-01 05:40:50 -05:00
|
|
|
return this._layoutStrategy.computeWindowSlots(this._layout, availArea);
|
2020-06-03 12:10:09 -04:00
|
|
|
}
|
|
|
|
|
2020-06-25 20:56:35 -04:00
|
|
|
_getAdjustedWorkarea(container) {
|
|
|
|
const workarea = this._workarea.copy();
|
|
|
|
|
|
|
|
if (container instanceof St.Widget) {
|
|
|
|
const themeNode = container.get_theme_node();
|
|
|
|
workarea.width -= themeNode.get_horizontal_padding();
|
|
|
|
workarea.height -= themeNode.get_vertical_padding();
|
|
|
|
}
|
|
|
|
|
|
|
|
return workarea;
|
|
|
|
}
|
|
|
|
|
2021-03-16 16:26:33 -04:00
|
|
|
_syncWorkareaTracking() {
|
|
|
|
if (this._container) {
|
|
|
|
if (this._workAreaChangedId)
|
|
|
|
return;
|
|
|
|
this._workarea = Main.layoutManager.getWorkAreaForMonitor(this._monitorIndex);
|
|
|
|
this._workareasChangedId =
|
|
|
|
global.display.connect('workareas-changed', () => {
|
|
|
|
this._workarea = Main.layoutManager.getWorkAreaForMonitor(this._monitorIndex);
|
|
|
|
this.layout_changed();
|
|
|
|
});
|
|
|
|
} else if (this._workareasChangedId) {
|
|
|
|
global.display.disconnect(this._workareasChangedId);
|
|
|
|
this._workareasChangedId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 12:10:09 -04:00
|
|
|
vfunc_set_container(container) {
|
|
|
|
this._container = container;
|
2021-03-16 16:26:33 -04:00
|
|
|
this._syncWorkareaTracking();
|
2020-06-03 12:10:09 -04:00
|
|
|
this._stateAdjustment.actor = container;
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_get_preferred_width(container, forHeight) {
|
2020-06-25 20:56:35 -04:00
|
|
|
const workarea = this._getAdjustedWorkarea(container);
|
2020-06-03 12:10:09 -04:00
|
|
|
if (forHeight === -1)
|
2020-06-25 20:56:35 -04:00
|
|
|
return [0, workarea.width];
|
2020-06-03 12:10:09 -04:00
|
|
|
|
2020-06-25 20:56:35 -04:00
|
|
|
const workAreaAspectRatio = workarea.width / workarea.height;
|
2020-06-03 12:10:09 -04:00
|
|
|
const widthPreservingAspectRatio = forHeight * workAreaAspectRatio;
|
|
|
|
|
|
|
|
return [0, widthPreservingAspectRatio];
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_get_preferred_height(container, forWidth) {
|
2020-06-25 20:56:35 -04:00
|
|
|
const workarea = this._getAdjustedWorkarea(container);
|
2020-06-03 12:10:09 -04:00
|
|
|
if (forWidth === -1)
|
2020-06-25 20:56:35 -04:00
|
|
|
return [0, workarea.height];
|
2020-06-03 12:10:09 -04:00
|
|
|
|
2020-06-25 20:56:35 -04:00
|
|
|
const workAreaAspectRatio = workarea.width / workarea.height;
|
2020-06-03 12:10:09 -04:00
|
|
|
const heightPreservingAspectRatio = forWidth / workAreaAspectRatio;
|
|
|
|
|
|
|
|
return [0, heightPreservingAspectRatio];
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_allocate(container, box) {
|
2020-06-25 21:22:29 -04:00
|
|
|
const containerBox = container.allocation;
|
2021-03-10 07:24:07 -05:00
|
|
|
const [containerWidth, containerHeight] = containerBox.get_size();
|
2020-06-03 12:10:09 -04:00
|
|
|
const containerAllocationChanged =
|
2020-06-25 21:22:29 -04:00
|
|
|
this._lastBox === null || !this._lastBox.equal(containerBox);
|
|
|
|
this._lastBox = containerBox.copy();
|
2020-06-03 12:10:09 -04:00
|
|
|
|
|
|
|
// If the containers size changed, we can no longer keep around
|
2020-12-27 12:39:22 -05:00
|
|
|
// the old windowSlots, so we must unfreeze the layout.
|
|
|
|
//
|
|
|
|
// However, if the overview animation is in progress, don't unfreeze
|
|
|
|
// the layout. This is needed to prevent windows "snapping" to their
|
|
|
|
// new positions during the overview closing animation when the
|
|
|
|
// allocation subtly expands every frame.
|
|
|
|
if (this._layoutFrozen && containerAllocationChanged && !Main.overview.animationInProgress) {
|
2020-06-03 12:10:09 -04:00
|
|
|
this._layoutFrozen = false;
|
|
|
|
this.notify('layout-frozen');
|
|
|
|
}
|
|
|
|
|
2021-03-10 07:24:07 -05:00
|
|
|
const { ControlsState } = OverviewControls;
|
|
|
|
const inSessionTransition =
|
|
|
|
this._overviewAdjustment.value <= ControlsState.WINDOW_PICKER;
|
|
|
|
|
|
|
|
const window = this._sortedWindows[0];
|
|
|
|
|
|
|
|
if (inSessionTransition || !window) {
|
|
|
|
container.remove_clip();
|
|
|
|
} else {
|
|
|
|
const [, bottomOversize] = window.chromeHeights();
|
|
|
|
const [containerX, containerY] = containerBox.get_origin();
|
|
|
|
|
|
|
|
const extraHeightProgress = this._overviewAdjustment.value -
|
|
|
|
OverviewControls.ControlsState.WINDOW_PICKER;
|
|
|
|
|
|
|
|
const extraClipHeight = bottomOversize * (1 - extraHeightProgress);
|
|
|
|
|
|
|
|
container.set_clip(containerX, containerY,
|
|
|
|
containerWidth, containerHeight + extraClipHeight);
|
|
|
|
}
|
|
|
|
|
2020-06-03 12:10:09 -04:00
|
|
|
let layoutChanged = false;
|
|
|
|
if (!this._layoutFrozen) {
|
|
|
|
if (this._layout === null) {
|
|
|
|
this._layout = this._createBestLayout(this._workarea);
|
|
|
|
layoutChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layoutChanged || containerAllocationChanged)
|
|
|
|
this._windowSlots = this._getWindowSlots(box.copy());
|
|
|
|
}
|
|
|
|
|
2021-02-25 06:13:21 -05:00
|
|
|
const workareaX = this._workarea.x;
|
|
|
|
const workareaY = this._workarea.y;
|
|
|
|
const workareaWidth = this._workarea.width;
|
|
|
|
const stateAdjustementValue = this._stateAdjustment.value;
|
|
|
|
|
2021-03-10 07:24:07 -05:00
|
|
|
const allocationScale = containerWidth / workareaWidth;
|
2020-06-03 12:10:09 -04:00
|
|
|
|
2021-02-25 11:20:42 -05:00
|
|
|
const childBox = new Clutter.ActorBox();
|
2020-06-03 12:10:09 -04:00
|
|
|
|
2021-02-25 05:50:44 -05:00
|
|
|
const nSlots = this._windowSlots.length;
|
|
|
|
for (let i = 0; i < nSlots; i++) {
|
2021-02-25 11:20:42 -05:00
|
|
|
let [x, y, width, height, child] = this._windowSlots[i];
|
2021-02-17 09:01:44 -05:00
|
|
|
if (!child.visible)
|
2020-06-03 12:10:09 -04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
const windowInfo = this._windows.get(child);
|
|
|
|
|
2021-02-25 11:20:42 -05:00
|
|
|
let workspaceBoxX, workspaceBoxY;
|
|
|
|
let workspaceBoxWidth, workspaceBoxHeight;
|
|
|
|
|
2020-06-25 14:25:22 -04:00
|
|
|
if (windowInfo.metaWindow.showing_on_its_workspace()) {
|
2021-02-25 11:20:42 -05:00
|
|
|
workspaceBoxX = (child.boundingBox.x - workareaX) * allocationScale;
|
|
|
|
workspaceBoxY = (child.boundingBox.y - workareaY) * allocationScale;
|
|
|
|
workspaceBoxWidth = child.boundingBox.width * allocationScale;
|
|
|
|
workspaceBoxHeight = child.boundingBox.height * allocationScale;
|
2020-06-25 14:25:22 -04:00
|
|
|
} else {
|
2021-02-25 11:20:42 -05:00
|
|
|
workspaceBoxX = workareaX * allocationScale;
|
|
|
|
workspaceBoxY = workareaY * allocationScale;
|
|
|
|
workspaceBoxWidth = 0;
|
|
|
|
workspaceBoxHeight = 0;
|
2020-06-25 14:25:22 -04:00
|
|
|
|
2021-02-25 06:13:21 -05:00
|
|
|
child.opacity = stateAdjustementValue * 255;
|
2020-06-25 14:25:22 -04:00
|
|
|
}
|
2020-06-03 12:10:09 -04:00
|
|
|
|
2021-02-16 17:11:30 -05:00
|
|
|
// Don't allow the scaled floating size to drop below
|
|
|
|
// the target layout size.
|
|
|
|
// We only want to apply this when the scaled floating size is
|
|
|
|
// actually larger than the target layout size, that is while
|
|
|
|
// animating between the session and the window picker.
|
|
|
|
if (inSessionTransition) {
|
2021-02-25 11:20:42 -05:00
|
|
|
workspaceBoxWidth = Math.max(workspaceBoxWidth, width);
|
|
|
|
workspaceBoxHeight = Math.max(workspaceBoxHeight, height);
|
2021-02-16 17:11:30 -05:00
|
|
|
}
|
2020-06-03 12:10:09 -04:00
|
|
|
|
2021-02-25 11:20:42 -05:00
|
|
|
x = Util.lerp(workspaceBoxX, x, stateAdjustementValue);
|
|
|
|
y = Util.lerp(workspaceBoxY, y, stateAdjustementValue);
|
|
|
|
width = Util.lerp(workspaceBoxWidth, width, stateAdjustementValue);
|
|
|
|
height = Util.lerp(workspaceBoxHeight, height, stateAdjustementValue);
|
2020-06-03 12:10:09 -04:00
|
|
|
|
2021-02-25 11:20:42 -05:00
|
|
|
childBox.set_origin(x, y);
|
|
|
|
childBox.set_size(width, height);
|
2020-06-03 12:10:09 -04:00
|
|
|
|
|
|
|
if (windowInfo.currentTransition) {
|
|
|
|
windowInfo.currentTransition.get_interval().set_final(childBox);
|
2020-10-24 14:25:49 -04:00
|
|
|
|
|
|
|
// The timeline of the transition might not have been updated
|
|
|
|
// before this allocation cycle, so make sure the child
|
|
|
|
// still updates needs_allocation to FALSE.
|
|
|
|
// Unfortunately, this relies on the fast paths in
|
|
|
|
// clutter_actor_allocate(), otherwise we'd start a new
|
|
|
|
// transition on the child, replacing the current one.
|
|
|
|
child.allocate(child.allocation);
|
2020-06-03 12:10:09 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want layout changes (ie. larger changes to the layout like
|
|
|
|
// reshuffling the window order) to be animated, but small changes
|
|
|
|
// like changes to the container size to happen immediately (for
|
|
|
|
// example if the container height is being animated, we want to
|
|
|
|
// avoid animating the children allocations to make sure they
|
|
|
|
// don't "lag behind" the other animation).
|
2020-06-25 13:54:54 -04:00
|
|
|
if (layoutChanged && !Main.overview.animationInProgress) {
|
2020-06-03 12:10:09 -04:00
|
|
|
const transition = animateAllocation(child, childBox);
|
|
|
|
if (transition) {
|
|
|
|
windowInfo.currentTransition = transition;
|
|
|
|
windowInfo.currentTransition.connect('stopped', () => {
|
|
|
|
windowInfo.currentTransition = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
child.allocate(childBox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 11:06:38 -04:00
|
|
|
_syncOverlay(preview) {
|
2021-02-05 11:39:13 -05:00
|
|
|
const active = this._metaWorkspace?.active ?? true;
|
|
|
|
preview.overlayEnabled = active && this._stateAdjustment.value === 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* syncOverlays:
|
|
|
|
*
|
|
|
|
* Synchronizes the overlay state of all window previews.
|
|
|
|
*/
|
|
|
|
syncOverlays() {
|
|
|
|
[...this._windows.keys()].forEach(preview => this._syncOverlay(preview));
|
2020-06-26 11:06:38 -04:00
|
|
|
}
|
|
|
|
|
2020-06-03 12:10:09 -04:00
|
|
|
/**
|
|
|
|
* addWindow:
|
|
|
|
* @param {WindowPreview} window: the window to add
|
|
|
|
* @param {Meta.Window} metaWindow: the MetaWindow of the window
|
|
|
|
*
|
|
|
|
* Adds @window to the workspace, it will be shown immediately if
|
|
|
|
* the layout isn't frozen using the layout-frozen property.
|
|
|
|
*
|
|
|
|
* If @window is already part of the workspace, nothing will happen.
|
|
|
|
*/
|
|
|
|
addWindow(window, metaWindow) {
|
|
|
|
if (this._windows.has(window))
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._windows.set(window, {
|
|
|
|
metaWindow,
|
|
|
|
sizeChangedId: metaWindow.connect('size-changed', () => {
|
|
|
|
this._layout = null;
|
|
|
|
this.layout_changed();
|
|
|
|
}),
|
|
|
|
destroyId: window.connect('destroy', () =>
|
|
|
|
this.removeWindow(window)),
|
|
|
|
currentTransition: null,
|
|
|
|
});
|
|
|
|
|
|
|
|
this._sortedWindows.push(window);
|
|
|
|
this._sortedWindows.sort((a, b) => {
|
|
|
|
const winA = this._windows.get(a).metaWindow;
|
|
|
|
const winB = this._windows.get(b).metaWindow;
|
|
|
|
|
|
|
|
return winA.get_stable_sequence() - winB.get_stable_sequence();
|
|
|
|
});
|
|
|
|
|
2020-06-26 11:06:38 -04:00
|
|
|
this._syncOverlay(window);
|
2020-06-03 12:10:09 -04:00
|
|
|
this._container.add_child(window);
|
|
|
|
|
|
|
|
this._layout = null;
|
|
|
|
this.layout_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* removeWindow:
|
|
|
|
* @param {WindowPreview} window: the window to remove
|
|
|
|
*
|
|
|
|
* Removes @window from the workspace if @window is a part of the
|
|
|
|
* workspace. If the layout-frozen property is set to true, the
|
|
|
|
* window will still be visible until the property is set to false.
|
|
|
|
*/
|
|
|
|
removeWindow(window) {
|
|
|
|
const windowInfo = this._windows.get(window);
|
|
|
|
if (!windowInfo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
windowInfo.metaWindow.disconnect(windowInfo.sizeChangedId);
|
|
|
|
window.disconnect(windowInfo.destroyId);
|
|
|
|
if (windowInfo.currentTransition)
|
|
|
|
window.remove_transition('allocation');
|
|
|
|
|
|
|
|
this._windows.delete(window);
|
|
|
|
this._sortedWindows.splice(this._sortedWindows.indexOf(window), 1);
|
|
|
|
|
|
|
|
// The layout might be frozen and we might not update the windowSlots
|
|
|
|
// on the next allocation, so remove the slot now already
|
2021-02-27 01:59:21 -05:00
|
|
|
const index = this._windowSlots.findIndex(s => s[4] === window);
|
|
|
|
if (index !== -1)
|
|
|
|
this._windowSlots.splice(index, 1);
|
2020-06-03 12:10:09 -04:00
|
|
|
|
|
|
|
// The window might have been reparented by DND
|
|
|
|
if (window.get_parent() === this._container)
|
|
|
|
this._container.remove_child(window);
|
|
|
|
|
|
|
|
this._layout = null;
|
|
|
|
this.layout_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
syncStacking(stackIndices) {
|
|
|
|
const windows = [...this._windows.keys()];
|
|
|
|
windows.sort((a, b) => {
|
|
|
|
const seqA = this._windows.get(a).metaWindow.get_stable_sequence();
|
|
|
|
const seqB = this._windows.get(b).metaWindow.get_stable_sequence();
|
|
|
|
|
|
|
|
return stackIndices[seqA] - stackIndices[seqB];
|
|
|
|
});
|
|
|
|
|
2021-02-17 09:01:44 -05:00
|
|
|
let lastWindow = null;
|
2020-06-03 12:10:09 -04:00
|
|
|
for (const window of windows) {
|
|
|
|
window.setStackAbove(lastWindow);
|
|
|
|
lastWindow = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._layout = null;
|
|
|
|
this.layout_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getFocusChain:
|
|
|
|
*
|
|
|
|
* Gets the focus chain of the workspace. This function will return
|
|
|
|
* an empty array if the floating window layout is used.
|
|
|
|
*
|
|
|
|
* @returns {Array} an array of {Clutter.Actor}s
|
|
|
|
*/
|
|
|
|
getFocusChain() {
|
|
|
|
if (this._stateAdjustment.value === 0)
|
|
|
|
return [];
|
|
|
|
|
|
|
|
// The fifth element in the slot array is the WindowPreview
|
|
|
|
return this._windowSlots.map(s => s[4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An StAdjustment for controlling and transitioning between
|
|
|
|
* the alignment of windows using the layout strategy and the
|
|
|
|
* floating window layout.
|
|
|
|
*
|
|
|
|
* A value of 0 of the adjustment completely uses the floating
|
|
|
|
* window layout while a value of 1 completely aligns windows using
|
|
|
|
* the layout strategy.
|
|
|
|
*
|
|
|
|
* @type {St.Adjustment}
|
|
|
|
*/
|
|
|
|
get stateAdjustment() {
|
|
|
|
return this._stateAdjustment;
|
|
|
|
}
|
|
|
|
|
|
|
|
get spacing() {
|
|
|
|
return this._spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
set spacing(s) {
|
|
|
|
if (this._spacing === s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._spacing = s;
|
|
|
|
|
|
|
|
this._layout = null;
|
|
|
|
this.notify('spacing');
|
|
|
|
this.layout_changed();
|
|
|
|
}
|
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get layoutFrozen() {
|
2020-06-03 12:10:09 -04:00
|
|
|
return this._layoutFrozen;
|
|
|
|
}
|
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
set layoutFrozen(f) {
|
2020-06-03 12:10:09 -04:00
|
|
|
if (this._layoutFrozen === f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._layoutFrozen = f;
|
|
|
|
|
|
|
|
this.notify('layout-frozen');
|
|
|
|
if (!this._layoutFrozen)
|
|
|
|
this.layout_changed();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-01 18:24:17 -04:00
|
|
|
var WorkspaceBackground = GObject.registerClass(
|
|
|
|
class WorkspaceBackground extends St.Widget {
|
2021-02-18 17:47:49 -05:00
|
|
|
_init(monitorIndex, stateAdjustment) {
|
2020-06-01 18:24:17 -04:00
|
|
|
super._init({
|
|
|
|
style_class: 'workspace-background',
|
|
|
|
layout_manager: new Clutter.BinLayout(),
|
2021-02-17 09:01:44 -05:00
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
2020-06-01 18:24:17 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
this._monitorIndex = monitorIndex;
|
2020-06-26 16:41:22 -04:00
|
|
|
this._workarea = Main.layoutManager.getWorkAreaForMonitor(monitorIndex);
|
|
|
|
|
2021-02-18 17:47:49 -05:00
|
|
|
this._stateAdjustment = stateAdjustment;
|
2021-02-17 09:36:10 -05:00
|
|
|
stateAdjustment.connect('notify::value', () => {
|
|
|
|
this._updateBorderRadius();
|
|
|
|
this.queue_relayout();
|
|
|
|
});
|
2021-02-18 17:47:49 -05:00
|
|
|
|
2020-06-26 16:41:22 -04:00
|
|
|
this._bin = new Clutter.Actor({
|
|
|
|
layout_manager: new Clutter.BinLayout(),
|
|
|
|
clip_to_allocation: true,
|
|
|
|
});
|
2020-06-01 18:24:17 -04:00
|
|
|
|
|
|
|
this._backgroundGroup = new Meta.BackgroundGroup({
|
2020-06-26 16:41:22 -04:00
|
|
|
layout_manager: new Clutter.BinLayout(),
|
2020-06-01 18:24:17 -04:00
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
|
|
|
});
|
2020-06-26 16:41:22 -04:00
|
|
|
this._bin.add_child(this._backgroundGroup);
|
|
|
|
this.add_child(this._bin);
|
2020-06-01 18:24:17 -04:00
|
|
|
|
|
|
|
this._bgManager = new Background.BackgroundManager({
|
|
|
|
container: this._backgroundGroup,
|
|
|
|
monitorIndex: this._monitorIndex,
|
|
|
|
controlPosition: false,
|
|
|
|
useContentSize: false,
|
|
|
|
});
|
|
|
|
|
2021-02-15 15:35:24 -05:00
|
|
|
this._workareasChangedId =
|
|
|
|
global.display.connect('workareas-changed', () => {
|
|
|
|
this._workarea = Main.layoutManager.getWorkAreaForMonitor(monitorIndex);
|
|
|
|
this._updateRoundedClipBounds();
|
|
|
|
this.queue_relayout();
|
|
|
|
});
|
|
|
|
this._updateRoundedClipBounds();
|
|
|
|
|
2020-06-01 18:24:17 -04:00
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
|
|
|
}
|
|
|
|
|
2021-02-18 17:47:49 -05:00
|
|
|
_updateBorderRadius() {
|
|
|
|
const { scaleFactor } = St.ThemeContext.get_for_stage(global.stage);
|
|
|
|
const cornerRadius = scaleFactor * BACKGROUND_CORNER_RADIUS_PIXELS;
|
|
|
|
|
|
|
|
const backgroundContent = this._bgManager.backgroundActor.content;
|
|
|
|
backgroundContent.rounded_clip_radius =
|
|
|
|
Util.lerp(0, cornerRadius, this._stateAdjustment.value);
|
|
|
|
}
|
|
|
|
|
2021-02-15 15:35:24 -05:00
|
|
|
_updateRoundedClipBounds() {
|
|
|
|
const monitor = Main.layoutManager.monitors[this._monitorIndex];
|
|
|
|
|
|
|
|
const rect = new Graphene.Rect();
|
|
|
|
rect.origin.x = this._workarea.x - monitor.x;
|
|
|
|
rect.origin.y = this._workarea.y - monitor.y;
|
|
|
|
rect.size.width = this._workarea.width;
|
|
|
|
rect.size.height = this._workarea.height;
|
|
|
|
|
|
|
|
this._bgManager.backgroundActor.content.set_rounded_clip_bounds(rect);
|
|
|
|
}
|
|
|
|
|
2020-06-26 16:41:22 -04:00
|
|
|
vfunc_allocate(box) {
|
2021-02-22 06:50:29 -05:00
|
|
|
const [width, height] = box.get_size();
|
|
|
|
const { scaleFactor } = St.ThemeContext.get_for_stage(global.stage);
|
|
|
|
const scaledHeight = height - (BACKGROUND_MARGIN * 2 * scaleFactor);
|
|
|
|
const scaledWidth = (scaledHeight / height) * width;
|
2021-02-17 09:36:10 -05:00
|
|
|
|
2021-02-22 06:50:29 -05:00
|
|
|
const scaledBox = box.copy();
|
2021-02-17 09:36:10 -05:00
|
|
|
scaledBox.set_origin(
|
2021-02-22 06:50:29 -05:00
|
|
|
box.x1 + (width - scaledWidth) / 2,
|
|
|
|
box.y1 + (height - scaledHeight) / 2);
|
|
|
|
scaledBox.set_size(scaledWidth, scaledHeight);
|
2021-02-17 09:36:10 -05:00
|
|
|
|
|
|
|
const progress = this._stateAdjustment.value;
|
|
|
|
|
|
|
|
if (progress === 1)
|
|
|
|
box = scaledBox;
|
|
|
|
else if (progress !== 0)
|
|
|
|
box = box.interpolate(scaledBox, progress);
|
|
|
|
|
2020-06-26 16:41:22 -04:00
|
|
|
this.set_allocation(box);
|
|
|
|
|
|
|
|
const themeNode = this.get_theme_node();
|
|
|
|
const contentBox = themeNode.get_content_box(box);
|
|
|
|
|
|
|
|
this._bin.allocate(contentBox);
|
|
|
|
|
|
|
|
const [contentWidth, contentHeight] = contentBox.get_size();
|
|
|
|
const monitor = Main.layoutManager.monitors[this._monitorIndex];
|
2021-06-18 13:11:34 -04:00
|
|
|
const [mX1, mX2] = [monitor.x, monitor.x + monitor.width];
|
|
|
|
const [mY1, mY2] = [monitor.y, monitor.y + monitor.height];
|
|
|
|
const [wX1, wX2] = [this._workarea.x, this._workarea.x + this._workarea.width];
|
|
|
|
const [wY1, wY2] = [this._workarea.y, this._workarea.y + this._workarea.height];
|
|
|
|
const xScale = contentWidth / this._workarea.width;
|
|
|
|
const yScale = contentHeight / this._workarea.height;
|
|
|
|
const leftOffset = wX1 - mX1;
|
|
|
|
const topOffset = wY1 - mY1;
|
|
|
|
const rightOffset = mX2 - wX2;
|
|
|
|
const bottomOffset = mY2 - wY2;
|
|
|
|
|
|
|
|
contentBox.set_origin(-leftOffset * xScale, -topOffset * yScale);
|
|
|
|
contentBox.set_size(
|
|
|
|
contentWidth + (leftOffset + rightOffset) * xScale,
|
|
|
|
contentHeight + (topOffset + bottomOffset) * yScale);
|
2020-06-26 16:41:22 -04:00
|
|
|
this._backgroundGroup.allocate(contentBox);
|
|
|
|
}
|
|
|
|
|
2020-06-01 18:24:17 -04:00
|
|
|
_onDestroy() {
|
|
|
|
if (this._bgManager) {
|
|
|
|
this._bgManager.destroy();
|
|
|
|
this._bgManager = null;
|
|
|
|
}
|
2021-02-15 15:35:24 -05:00
|
|
|
|
|
|
|
if (this._workareasChangedId) {
|
|
|
|
global.display.disconnect(this._workareasChangedId);
|
|
|
|
delete this._workareasChangedId;
|
|
|
|
}
|
2020-06-01 18:24:17 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2009-07-23 17:36:41 -04:00
|
|
|
/**
|
2011-03-03 16:33:27 -05:00
|
|
|
* @metaWorkspace: a #Meta.Workspace, or null
|
2009-07-23 17:36:41 -04:00
|
|
|
*/
|
2019-07-16 05:24:13 -04:00
|
|
|
var Workspace = GObject.registerClass(
|
|
|
|
class Workspace extends St.Widget {
|
2021-02-05 11:22:18 -05:00
|
|
|
_init(metaWorkspace, monitorIndex, overviewAdjustment) {
|
2020-06-03 12:17:54 -04:00
|
|
|
super._init({
|
|
|
|
style_class: 'window-picker',
|
2020-12-31 12:19:43 -05:00
|
|
|
pivot_point: new Graphene.Point({ x: 0.5, y: 0.5 }),
|
2021-02-17 08:36:36 -05:00
|
|
|
layout_manager: new Clutter.BinLayout(),
|
|
|
|
});
|
|
|
|
|
2021-02-16 17:11:30 -05:00
|
|
|
const layoutManager = new WorkspaceLayout(metaWorkspace, monitorIndex,
|
|
|
|
overviewAdjustment);
|
2021-02-18 17:47:49 -05:00
|
|
|
|
2021-02-17 09:01:44 -05:00
|
|
|
// Background
|
2021-02-18 17:47:49 -05:00
|
|
|
this._background =
|
|
|
|
new WorkspaceBackground(monitorIndex, layoutManager.stateAdjustment);
|
2021-02-17 09:01:44 -05:00
|
|
|
this.add_child(this._background);
|
|
|
|
|
|
|
|
// Window previews
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container = new Clutter.Actor({
|
2020-06-01 18:24:17 -04:00
|
|
|
reactive: true,
|
2021-02-17 08:36:36 -05:00
|
|
|
x_expand: true,
|
|
|
|
y_expand: true,
|
2020-06-03 12:17:54 -04:00
|
|
|
});
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager = layoutManager;
|
|
|
|
this.add_child(this._container);
|
2019-07-16 05:24:13 -04:00
|
|
|
|
2010-02-14 18:32:57 -05:00
|
|
|
this.metaWorkspace = metaWorkspace;
|
2021-02-05 11:39:13 -05:00
|
|
|
this._activeWorkspaceChangedId =
|
|
|
|
this.metaWorkspace?.connect('notify::active', () => {
|
2021-02-17 08:36:36 -05:00
|
|
|
layoutManager.syncOverlays();
|
2021-02-05 11:39:13 -05:00
|
|
|
});
|
2013-02-25 18:25:27 -05:00
|
|
|
|
2021-02-05 11:22:18 -05:00
|
|
|
this._overviewAdjustment = overviewAdjustment;
|
2021-02-17 09:09:31 -05:00
|
|
|
|
2011-03-01 03:14:56 -05:00
|
|
|
this.monitorIndex = monitorIndex;
|
2011-06-13 09:54:05 -04:00
|
|
|
this._monitor = Main.layoutManager.monitors[this.monitorIndex];
|
2010-01-21 21:33:48 -05:00
|
|
|
|
2012-12-13 13:28:25 -05:00
|
|
|
if (monitorIndex != Main.layoutManager.primaryIndex)
|
2019-07-16 05:24:13 -04:00
|
|
|
this.add_style_class_name('external-monitor');
|
2010-02-14 18:32:57 -05:00
|
|
|
|
2020-06-01 18:24:17 -04:00
|
|
|
const clickAction = new Clutter.ClickAction();
|
|
|
|
clickAction.connect('clicked', action => {
|
2021-02-05 11:22:18 -05:00
|
|
|
// 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();
|
|
|
|
}
|
2020-06-01 18:24:17 -04:00
|
|
|
});
|
|
|
|
this.bind_property('mapped', clickAction, 'enabled', GObject.BindingFlags.SYNC_CREATE);
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.add_action(clickAction);
|
2020-06-01 18:24:17 -04:00
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
this.connect('style-changed', this._onStyleChanged.bind(this));
|
2019-07-16 05:24:13 -04:00
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
2008-12-22 16:51:34 -05:00
|
|
|
|
2020-06-08 03:50:41 -04:00
|
|
|
const windows = global.get_window_actors().map(a => a.meta_window)
|
|
|
|
.filter(this._isMyWindow, this);
|
2008-12-22 16:51:34 -05:00
|
|
|
|
2011-02-19 18:39:10 -05:00
|
|
|
// Create clones for windows that should be
|
2009-08-11 07:46:10 -04:00
|
|
|
// visible in the Overview
|
2010-07-15 10:21:32 -04:00
|
|
|
this._windows = [];
|
2008-12-22 16:51:34 -05:00
|
|
|
for (let i = 0; i < windows.length; i++) {
|
2018-11-19 06:28:28 -05:00
|
|
|
if (this._isOverviewWindow(windows[i]))
|
2020-06-03 12:17:54 -04:00
|
|
|
this._addWindowClone(windows[i]);
|
2008-12-22 16:51:34 -05:00
|
|
|
}
|
2008-12-22 17:06:47 -05:00
|
|
|
|
2021-02-02 16:31:32 -05:00
|
|
|
// Track window changes, but let the window tracker process them first
|
2011-03-03 16:33:27 -05:00
|
|
|
if (this.metaWorkspace) {
|
2021-02-02 16:31:32 -05:00
|
|
|
this._windowAddedId = this.metaWorkspace.connect_after(
|
|
|
|
'window-added', this._windowAdded.bind(this));
|
|
|
|
this._windowRemovedId = this.metaWorkspace.connect_after(
|
|
|
|
'window-removed', this._windowRemoved.bind(this));
|
2011-03-03 16:33:27 -05:00
|
|
|
}
|
2021-02-02 16:31:32 -05:00
|
|
|
this._windowEnteredMonitorId = global.display.connect_after(
|
|
|
|
'window-entered-monitor', this._windowEnteredMonitor.bind(this));
|
|
|
|
this._windowLeftMonitorId = global.display.connect_after(
|
|
|
|
'window-left-monitor', this._windowLeftMonitor.bind(this));
|
2020-06-03 12:17:54 -04:00
|
|
|
this._layoutFrozenId = 0;
|
2014-05-08 13:16:10 -04:00
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
// DND requires this to be set
|
|
|
|
this._delegate = this;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2008-12-22 17:06:47 -05:00
|
|
|
|
2021-02-05 11:22:18 -05:00
|
|
|
_shouldLeaveOverview() {
|
|
|
|
if (!this.metaWorkspace || this.metaWorkspace.active)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const overviewState = this._overviewAdjustment.value;
|
|
|
|
return overviewState > OverviewControls.ControlsState.WINDOW_PICKER;
|
|
|
|
}
|
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
vfunc_get_focus_chain() {
|
2021-02-17 08:36:36 -05:00
|
|
|
return this._container.layout_manager.getFocusChain();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
Restructure the way we handle positioning zooming in Workspace
We currently show the workspace in the overview in a rectangle
with the same aspect ratio as the screen. Originally this was
probably done since it showed the desktop, but we don't do this
anymore, and the positioning of the windows in the overview is
strictly a grid, so its not in any way related to monitor geometry.
Additionally, in the multihead case the screen aspect ratio is
very different from the overview monitor geometry, so a lot of
space is lost.
So, instead we just fill the entire inner rectangle of the overview
with the workspace. However, the way the zoom into and out of the
workspace right now is by scaling the workspace so that it covers
the entire monitor. This cannot really work anymore when the workspace
is a different aspect ratio. Furthermore the coordinates of the
window clone actors are of two very different types in the "original
window" case and the "window in a slot case". One is screen relative,
the other is workspace relative. This makes it very hard to compute
the cost of window motion distance in computeWindowMotion.
In order to handle this we change the way workspace actor positioning
and scaling work. All workspace window clone actors are stored in
true screen coordingates, both the original window positions and the
in-a-slot ones. Global scaling of the workspace is never done, we
just reposition everything in both the initial zoom and when the
controls appear from the side.
There is one issue in the initial and final animations, which is that
the clip region we normally have for the workspacesView will limit the
animation of the clones to/from the original positions, so we disable
the clip region during these animations.
https://bugzilla.gnome.org/show_bug.cgi?id=643786
2011-03-02 11:04:03 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_lookupIndex(metaWindow) {
|
2018-11-19 06:28:29 -05:00
|
|
|
return this._windows.findIndex(w => w.metaWindow == metaWindow);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-07-31 17:20:26 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
containsMetaWindow(metaWindow) {
|
2009-09-01 14:15:29 -04:00
|
|
|
return this._lookupIndex(metaWindow) >= 0;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-09-01 14:15:29 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
isEmpty() {
|
2011-01-21 13:47:54 -05:00
|
|
|
return this._windows.length == 0;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-21 13:47:54 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
syncStacking(stackIndices) {
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager.syncStacking(stackIndices);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-02-28 01:56:04 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_doRemoveWindow(metaWin) {
|
2018-07-09 05:50:25 -04:00
|
|
|
let clone = this._removeWindowClone(metaWin);
|
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
if (!clone)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clone.destroy();
|
2010-02-28 01:56:04 -05:00
|
|
|
|
|
|
|
// We need to reposition the windows; to avoid shuffling windows
|
|
|
|
// around while the user is interacting with the workspace, we delay
|
|
|
|
// the positioning until the pointer remains still for at least 750 ms
|
|
|
|
// or is moved outside the workspace
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager.layout_frozen = true;
|
2010-02-28 01:56:04 -05:00
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
if (this._layoutFrozenId > 0) {
|
|
|
|
GLib.source_remove(this._layoutFrozenId);
|
|
|
|
this._layoutFrozenId = 0;
|
2010-02-28 01:56:04 -05:00
|
|
|
}
|
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
let [oldX, oldY] = global.get_pointer();
|
|
|
|
|
|
|
|
this._layoutFrozenId = GLib.timeout_add(
|
|
|
|
GLib.PRIORITY_DEFAULT,
|
|
|
|
WINDOW_REPOSITIONING_DELAY,
|
|
|
|
() => {
|
|
|
|
const [newX, newY] = global.get_pointer();
|
|
|
|
const pointerHasMoved = oldX !== newX || oldY !== newY;
|
|
|
|
const actorUnderPointer = global.stage.get_actor_at_pos(
|
|
|
|
Clutter.PickMode.REACTIVE, newX, newY);
|
|
|
|
|
|
|
|
if ((pointerHasMoved && this.contains(actorUnderPointer)) ||
|
|
|
|
this._windows.some(w => w.contains(actorUnderPointer))) {
|
|
|
|
oldX = newX;
|
|
|
|
oldY = newY;
|
|
|
|
return GLib.SOURCE_CONTINUE;
|
|
|
|
}
|
2010-02-28 01:56:04 -05:00
|
|
|
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager.layout_frozen = false;
|
2020-06-03 12:17:54 -04:00
|
|
|
this._layoutFrozenId = 0;
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
|
|
|
|
|
|
|
GLib.Source.set_name_by_id(this._layoutFrozenId,
|
|
|
|
'[gnome-shell] this._layoutFrozenId');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-01-23 14:21:20 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_doAddWindow(metaWin) {
|
2009-02-04 09:50:50 -05:00
|
|
|
let win = metaWin.get_compositor_private();
|
|
|
|
|
|
|
|
if (!win) {
|
|
|
|
// Newly-created windows are added to a workspace before
|
|
|
|
// the compositor finds out about them...
|
2019-08-19 14:50:33 -04:00
|
|
|
let id = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
2019-07-16 05:24:13 -04:00
|
|
|
if (metaWin.get_compositor_private() &&
|
2017-10-30 20:38:18 -04:00
|
|
|
metaWin.get_workspace() == this.metaWorkspace)
|
|
|
|
this._doAddWindow(metaWin);
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
2014-04-10 13:26:52 -04:00
|
|
|
GLib.Source.set_name_by_id(id, '[gnome-shell] this._doAddWindow');
|
2009-02-04 09:50:50 -05:00
|
|
|
return;
|
|
|
|
}
|
2010-01-21 21:33:48 -05:00
|
|
|
|
2011-03-01 03:14:56 -05:00
|
|
|
// We might have the window in our list already if it was on all workspaces and
|
|
|
|
// now was moved to this workspace
|
2018-11-19 06:28:28 -05:00
|
|
|
if (this._lookupIndex(metaWin) != -1)
|
2011-03-01 03:14:56 -05:00
|
|
|
return;
|
|
|
|
|
2020-06-08 03:50:41 -04:00
|
|
|
if (!this._isMyWindow(metaWin))
|
2012-08-29 18:51:53 -04:00
|
|
|
return;
|
|
|
|
|
2020-06-08 03:50:41 -04:00
|
|
|
if (!this._isOverviewWindow(metaWin)) {
|
2018-06-19 06:45:18 -04:00
|
|
|
if (metaWin.get_transient_for() == null)
|
|
|
|
return;
|
2012-08-29 18:51:53 -04:00
|
|
|
|
2018-06-19 06:45:18 -04:00
|
|
|
// Let the top-most ancestor handle all transients
|
|
|
|
let parent = metaWin.find_root_ancestor();
|
|
|
|
let clone = this._windows.find(c => c.metaWindow == parent);
|
|
|
|
|
|
|
|
// If no clone was found, the parent hasn't been created yet
|
|
|
|
// and will take care of the dialog when added
|
|
|
|
if (clone)
|
|
|
|
clone.addDialog(metaWin);
|
2012-08-29 18:51:53 -04:00
|
|
|
|
2010-01-21 21:33:48 -05:00
|
|
|
return;
|
2012-08-29 18:51:53 -04:00
|
|
|
}
|
2009-02-04 09:50:50 -05:00
|
|
|
|
2020-06-03 12:32:45 -04:00
|
|
|
const clone = this._addWindowClone(metaWin);
|
|
|
|
|
|
|
|
clone.set_pivot_point(0.5, 0.5);
|
|
|
|
clone.scale_x = 0;
|
|
|
|
clone.scale_y = 0;
|
|
|
|
clone.ease({
|
|
|
|
scale_x: 1,
|
|
|
|
scale_y: 1,
|
|
|
|
duration: 250,
|
|
|
|
onStopped: () => clone.set_pivot_point(0, 0),
|
|
|
|
});
|
2009-02-04 09:50:50 -05:00
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
if (this._layoutFrozenId > 0) {
|
|
|
|
// If a window was closed before, unfreeze the layout to ensure
|
|
|
|
// the new window is immediately shown
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager.layout_frozen = false;
|
2018-11-19 06:28:28 -05:00
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
GLib.source_remove(this._layoutFrozenId);
|
|
|
|
this._layoutFrozenId = 0;
|
2009-02-04 09:50:50 -05:00
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-01-23 14:21:20 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_windowAdded(metaWorkspace, metaWin) {
|
2011-03-01 03:14:56 -05:00
|
|
|
this._doAddWindow(metaWin);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-03-01 03:14:56 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_windowRemoved(metaWorkspace, metaWin) {
|
2011-03-01 03:14:56 -05:00
|
|
|
this._doRemoveWindow(metaWin);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-03-01 03:14:56 -05:00
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
_windowEnteredMonitor(metaDisplay, monitorIndex, metaWin) {
|
2019-08-19 20:51:42 -04:00
|
|
|
if (monitorIndex == this.monitorIndex)
|
2011-03-01 03:14:56 -05:00
|
|
|
this._doAddWindow(metaWin);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-03-01 03:14:56 -05:00
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
_windowLeftMonitor(metaDisplay, monitorIndex, metaWin) {
|
2019-08-19 20:51:42 -04:00
|
|
|
if (monitorIndex == this.monitorIndex)
|
2011-03-01 03:14:56 -05:00
|
|
|
this._doRemoveWindow(metaWin);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-03-01 03:14:56 -05:00
|
|
|
|
2010-01-05 22:53:36 -05:00
|
|
|
// check for maximized windows on the workspace
|
2017-10-30 20:03:21 -04:00
|
|
|
hasMaximizedWindows() {
|
2010-07-15 10:21:32 -04:00
|
|
|
for (let i = 0; i < this._windows.length; i++) {
|
2010-01-05 22:53:36 -05:00
|
|
|
let metaWindow = this._windows[i].metaWindow;
|
|
|
|
if (metaWindow.showing_on_its_workspace() &&
|
|
|
|
metaWindow.maximized_horizontally &&
|
|
|
|
metaWindow.maximized_vertically)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-01-05 22:53:36 -05:00
|
|
|
|
2021-01-01 11:07:06 -05:00
|
|
|
prepareToLeaveOverview() {
|
2018-07-20 15:46:19 -04:00
|
|
|
for (let i = 0; i < this._windows.length; i++)
|
|
|
|
this._windows[i].remove_all_transitions();
|
2009-07-23 17:36:41 -04:00
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
if (this._layoutFrozenId > 0) {
|
|
|
|
GLib.source_remove(this._layoutFrozenId);
|
|
|
|
this._layoutFrozenId = 0;
|
2010-03-14 10:47:42 -04:00
|
|
|
}
|
2020-06-03 12:17:54 -04:00
|
|
|
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager.layout_frozen = true;
|
2017-12-01 19:27:35 -05:00
|
|
|
this._overviewHiddenId = Main.overview.connect('hidden', this._doneLeavingOverview.bind(this));
|
2021-01-01 11:07:06 -05:00
|
|
|
}
|
|
|
|
|
2018-07-20 15:46:19 -04:00
|
|
|
_onDestroy() {
|
2010-03-17 18:23:32 -04:00
|
|
|
if (this._overviewHiddenId) {
|
|
|
|
Main.overview.disconnect(this._overviewHiddenId);
|
|
|
|
this._overviewHiddenId = 0;
|
|
|
|
}
|
2009-02-04 09:50:50 -05:00
|
|
|
|
2011-03-03 16:33:27 -05:00
|
|
|
if (this.metaWorkspace) {
|
|
|
|
this.metaWorkspace.disconnect(this._windowAddedId);
|
|
|
|
this.metaWorkspace.disconnect(this._windowRemovedId);
|
2021-02-05 11:39:13 -05:00
|
|
|
this.metaWorkspace.disconnect(this._activeWorkspaceChangedId);
|
2011-03-03 16:33:27 -05:00
|
|
|
}
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.disconnect(this._windowEnteredMonitorId);
|
|
|
|
global.display.disconnect(this._windowLeftMonitorId);
|
2010-02-07 09:25:16 -05:00
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
if (this._layoutFrozenId > 0) {
|
|
|
|
GLib.source_remove(this._layoutFrozenId);
|
|
|
|
this._layoutFrozenId = 0;
|
2017-06-27 05:09:16 -04:00
|
|
|
}
|
2013-09-10 20:42:11 -04:00
|
|
|
|
2010-03-17 18:23:32 -04:00
|
|
|
this._windows = [];
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2008-12-22 16:51:34 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_doneLeavingOverview() {
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager.layout_frozen = false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-03-17 18:22:25 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_doneShowingOverview() {
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager.layout_frozen = false;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-07-14 13:06:08 -04:00
|
|
|
|
2020-06-08 03:50:41 -04:00
|
|
|
_isMyWindow(window) {
|
|
|
|
const isOnWorkspace = this.metaWorkspace === null ||
|
|
|
|
window.located_on_workspace(this.metaWorkspace);
|
|
|
|
const isOnMonitor = window.get_monitor() === this.monitorIndex;
|
|
|
|
|
|
|
|
return isOnWorkspace && isOnMonitor;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2008-12-22 16:51:34 -05:00
|
|
|
|
2020-06-08 03:50:41 -04:00
|
|
|
_isOverviewWindow(window) {
|
|
|
|
return !window.skip_taskbar;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2008-12-22 16:51:34 -05:00
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
// Create a clone of a (non-desktop) window and add it to the window list
|
2020-06-03 12:17:54 -04:00
|
|
|
_addWindowClone(metaWindow) {
|
2021-02-04 15:14:42 -05:00
|
|
|
let clone = new WindowPreview(metaWindow, this, this._overviewAdjustment);
|
2009-11-11 19:26:52 -05:00
|
|
|
|
2009-01-29 16:21:50 -05:00
|
|
|
clone.connect('selected',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._onCloneSelected.bind(this));
|
2017-10-30 20:38:18 -04:00
|
|
|
clone.connect('drag-begin', () => {
|
2020-06-08 03:58:22 -04:00
|
|
|
Main.overview.beginWindowDrag(metaWindow);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
clone.connect('drag-cancelled', () => {
|
2020-06-08 03:58:22 -04:00
|
|
|
Main.overview.cancelledWindowDrag(metaWindow);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
clone.connect('drag-end', () => {
|
2020-06-08 03:58:22 -04:00
|
|
|
Main.overview.endWindowDrag(metaWindow);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2020-06-02 07:56:03 -04:00
|
|
|
clone.connect('show-chrome', () => {
|
2017-10-09 18:04:56 -04:00
|
|
|
let focus = global.stage.key_focus;
|
2019-07-16 05:24:13 -04:00
|
|
|
if (focus == null || this.contains(focus))
|
2018-11-14 13:26:33 -05:00
|
|
|
clone.grab_key_focus();
|
2018-11-19 06:28:28 -05:00
|
|
|
|
2020-06-02 07:56:03 -04:00
|
|
|
this._windows.forEach(c => {
|
|
|
|
if (c !== clone)
|
|
|
|
c.hideOverlay(true);
|
2018-11-19 06:28:28 -05:00
|
|
|
});
|
2017-10-09 18:04:56 -04:00
|
|
|
});
|
2020-06-02 07:56:03 -04:00
|
|
|
clone.connect('destroy', () => {
|
2020-06-03 12:17:54 -04:00
|
|
|
this._doRemoveWindow(metaWindow);
|
2020-06-02 07:56:03 -04:00
|
|
|
});
|
|
|
|
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager.addWindow(clone, metaWindow);
|
2009-11-19 19:39:00 -05:00
|
|
|
|
2013-02-20 13:33:29 -05:00
|
|
|
if (this._windows.length == 0)
|
2021-02-17 09:01:44 -05:00
|
|
|
clone.setStackAbove(null);
|
2013-02-20 13:33:29 -05:00
|
|
|
else
|
2018-11-14 13:26:33 -05:00
|
|
|
clone.setStackAbove(this._windows[this._windows.length - 1]);
|
2013-02-20 13:33:29 -05:00
|
|
|
|
2009-01-23 14:21:20 -05:00
|
|
|
this._windows.push(clone);
|
|
|
|
|
2020-06-02 07:56:03 -04:00
|
|
|
return clone;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2008-12-22 16:51:34 -05:00
|
|
|
|
2018-07-09 05:50:25 -04:00
|
|
|
_removeWindowClone(metaWin) {
|
|
|
|
// find the position of the window in our list
|
2018-11-19 06:28:28 -05:00
|
|
|
let index = this._lookupIndex(metaWin);
|
2018-07-09 05:50:25 -04:00
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
return null;
|
|
|
|
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager.removeWindow(this._windows[index]);
|
2009-01-21 15:35:20 -05:00
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
return this._windows.splice(index, 1).pop();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2012-08-08 13:27:46 -04:00
|
|
|
|
2020-06-03 12:17:54 -04:00
|
|
|
_onStyleChanged() {
|
|
|
|
const themeNode = this.get_theme_node();
|
2021-02-17 08:36:36 -05:00
|
|
|
this._container.layout_manager.spacing = themeNode.get_length('spacing');
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2009-09-18 15:08:56 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_onCloneSelected(clone, time) {
|
2020-08-12 14:59:01 -04:00
|
|
|
const wsIndex = this.metaWorkspace?.index();
|
2021-02-05 11:22:18 -05:00
|
|
|
|
|
|
|
if (this._shouldLeaveOverview())
|
|
|
|
Main.activateWindow(clone.metaWindow, time, wsIndex);
|
|
|
|
else
|
|
|
|
this.metaWorkspace?.activate(time);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2008-12-22 17:06:47 -05:00
|
|
|
|
2009-02-10 11:15:59 -05:00
|
|
|
// Draggable target interface
|
2019-01-31 09:08:10 -05:00
|
|
|
handleDragOver(source, _actor, _x, _y, _time) {
|
2020-06-08 03:50:41 -04:00
|
|
|
if (source.metaWindow && !this._isMyWindow(source.metaWindow))
|
2010-09-09 22:00:28 -04:00
|
|
|
return DND.DragMotionResult.MOVE_DROP;
|
2019-05-02 11:04:03 -04:00
|
|
|
if (source.app && source.app.can_open_new_window())
|
2019-08-02 06:58:34 -04:00
|
|
|
return DND.DragMotionResult.COPY_DROP;
|
|
|
|
if (!source.app && source.shellWorkspaceLaunch)
|
2010-09-09 22:00:28 -04:00
|
|
|
return DND.DragMotionResult.COPY_DROP;
|
|
|
|
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-09-09 22:00:28 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
acceptDrop(source, actor, x, y, time) {
|
2019-08-02 06:58:34 -04:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
let workspaceIndex = this.metaWorkspace
|
|
|
|
? this.metaWorkspace.index()
|
|
|
|
: workspaceManager.get_active_workspace_index();
|
|
|
|
|
2020-06-08 03:50:41 -04:00
|
|
|
if (source.metaWindow) {
|
|
|
|
const window = source.metaWindow;
|
|
|
|
if (this._isMyWindow(window))
|
2009-02-10 11:15:59 -05:00
|
|
|
return false;
|
|
|
|
|
2011-03-03 16:33:27 -05:00
|
|
|
// We need to move the window before changing the workspace, because
|
|
|
|
// the move itself could cause a workspace change if the window enters
|
|
|
|
// the primary monitor
|
2020-06-08 03:50:41 -04:00
|
|
|
if (window.get_monitor() != this.monitorIndex)
|
|
|
|
window.move_to_monitor(this.monitorIndex);
|
2011-03-03 16:33:27 -05:00
|
|
|
|
2020-06-08 03:50:41 -04:00
|
|
|
window.change_workspace_by_index(workspaceIndex, false);
|
2019-08-02 06:58:34 -04:00
|
|
|
return true;
|
2019-05-02 11:04:03 -04:00
|
|
|
} else if (source.app && source.app.can_open_new_window()) {
|
2019-09-15 05:45:47 -04:00
|
|
|
if (source.animateLaunchAtPos)
|
|
|
|
source.animateLaunchAtPos(actor.x, actor.y);
|
|
|
|
|
2019-08-02 06:58:34 -04:00
|
|
|
source.app.open_new_window(workspaceIndex);
|
2009-02-10 11:15:59 -05:00
|
|
|
return true;
|
2019-08-02 06:58:34 -04:00
|
|
|
} else if (!source.app && source.shellWorkspaceLaunch) {
|
|
|
|
// While unused in our own drag sources, shellWorkspaceLaunch allows
|
|
|
|
// extensions to define custom actions for their drag sources.
|
|
|
|
source.shellWorkspaceLaunch({ workspace: workspaceIndex,
|
2011-01-30 16:09:58 -05:00
|
|
|
timestamp: time });
|
2009-02-10 11:15:59 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2008-12-22 16:51:34 -05:00
|
|
|
}
|
2021-01-01 11:10:19 -05:00
|
|
|
|
|
|
|
get stateAdjustment() {
|
2021-02-17 08:36:36 -05:00
|
|
|
return this._container.layout_manager.stateAdjustment;
|
2021-01-01 11:10:19 -05:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|