2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported Workspace */
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2019-10-17 09:22:30 +00:00
|
|
|
const { Atk, Clutter, GLib, GObject,
|
|
|
|
Graphene, Meta, Pango, Shell, St } = imports.gi;
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2009-02-10 16:15:59 +00:00
|
|
|
const DND = imports.ui.dnd;
|
2008-12-02 16:15:00 +00:00
|
|
|
const Main = imports.ui.main;
|
2009-08-11 11:46:10 +00:00
|
|
|
const Overview = imports.ui.overview;
|
2008-12-02 16:15:00 +00:00
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var WINDOW_DND_SIZE = 256;
|
2010-03-09 22:31:06 +00:00
|
|
|
|
2020-06-08 07:23:08 +00:00
|
|
|
var WINDOW_PREVIEW_MAXIMUM_SCALE = 1.0;
|
2012-01-15 14:30:59 +00:00
|
|
|
|
2018-11-19 11:28:28 +00:00
|
|
|
var WINDOW_OVERLAY_IDLE_HIDE_TIMEOUT = 750;
|
2020-06-02 12:01:32 +00:00
|
|
|
var WINDOW_OVERLAY_FADE_TIME = 200;
|
2009-09-04 19:25:17 +00:00
|
|
|
|
2018-11-19 11:28:28 +00:00
|
|
|
var WINDOW_REPOSITIONING_DELAY = 750;
|
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var DRAGGING_WINDOW_OPACITY = 100;
|
2010-03-09 22:31:06 +00:00
|
|
|
|
2012-08-08 17:27:46 +00: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 17:47:27 +00:00
|
|
|
var LAYOUT_SCALE_WEIGHT = 1;
|
|
|
|
var LAYOUT_SPACE_WEIGHT = 0.1;
|
2009-09-04 19:25:17 +00:00
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var WINDOW_ANIMATION_MAX_NUMBER_BLENDING = 3;
|
2014-07-14 17:06:08 +00:00
|
|
|
|
2009-09-04 19:25:17 +00:00
|
|
|
function _interpolate(start, end, step) {
|
|
|
|
return start + (end - start) * step;
|
|
|
|
}
|
|
|
|
|
2020-06-08 07:23:08 +00:00
|
|
|
var WindowPreviewLayout = GObject.registerClass({
|
2020-06-01 12:41:25 +00:00
|
|
|
Properties: {
|
|
|
|
'bounding-box': GObject.ParamSpec.boxed(
|
|
|
|
'bounding-box', 'Bounding box', 'Bounding box',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
Clutter.ActorBox.$gtype),
|
|
|
|
},
|
2020-06-08 07:23:08 +00:00
|
|
|
}, class WindowPreviewLayout extends Clutter.LayoutManager {
|
2020-06-01 12:41:25 +00:00
|
|
|
_init() {
|
2017-10-31 01:23:39 +00:00
|
|
|
super._init();
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2020-06-01 12:41:25 +00:00
|
|
|
this._container = null;
|
|
|
|
this._boundingBox = new Clutter.ActorBox();
|
|
|
|
this._windows = new Map();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2020-06-01 12:41:25 +00:00
|
|
|
_layoutChanged() {
|
|
|
|
let frameRect;
|
|
|
|
|
|
|
|
for (const windowInfo of this._windows.values()) {
|
|
|
|
const frame = windowInfo.metaWindow.get_frame_rect();
|
|
|
|
frameRect = frameRect ? frameRect.union(frame) : frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!frameRect)
|
|
|
|
frameRect = new Meta.Rectangle();
|
|
|
|
|
|
|
|
const oldBox = this._boundingBox.copy();
|
|
|
|
this._boundingBox.set_origin(frameRect.x, frameRect.y);
|
|
|
|
this._boundingBox.set_size(frameRect.width, frameRect.height);
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2020-06-01 12:41:25 +00:00
|
|
|
if (!this._boundingBox.equal(oldBox))
|
|
|
|
this.notify('bounding-box');
|
|
|
|
|
|
|
|
// Always call layout_changed(), a size or position change of an
|
|
|
|
// attached dialog might not affect the boundingBox
|
2012-08-29 22:51:53 +00:00
|
|
|
this.layout_changed();
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2020-06-01 12:41:25 +00:00
|
|
|
vfunc_set_container(container) {
|
|
|
|
this._container = container;
|
|
|
|
}
|
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
vfunc_get_preferred_height(_container, _forWidth) {
|
2020-06-01 12:41:25 +00:00
|
|
|
return [0, this._boundingBox.get_height()];
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
vfunc_get_preferred_width(_container, _forHeight) {
|
2020-06-01 12:41:25 +00:00
|
|
|
return [0, this._boundingBox.get_width()];
|
2017-10-31 01:23:39 +00:00
|
|
|
}
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2020-06-01 12:36:08 +00:00
|
|
|
vfunc_allocate(container, box) {
|
|
|
|
// If the scale isn't 1, we weren't allocated our preferred size
|
|
|
|
// and have to scale the children allocations accordingly.
|
2020-06-01 12:41:25 +00:00
|
|
|
const scaleX = box.get_width() / this._boundingBox.get_width();
|
|
|
|
const scaleY = box.get_height() / this._boundingBox.get_height();
|
2020-06-01 12:36:08 +00:00
|
|
|
|
|
|
|
const childBox = new Clutter.ActorBox();
|
|
|
|
|
2020-06-01 12:41:25 +00:00
|
|
|
for (const child of container) {
|
|
|
|
if (!child.visible)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const windowInfo = this._windows.get(child);
|
|
|
|
if (windowInfo) {
|
|
|
|
const bufferRect = windowInfo.metaWindow.get_buffer_rect();
|
|
|
|
childBox.set_origin(
|
|
|
|
bufferRect.x - this._boundingBox.x1,
|
|
|
|
bufferRect.y - this._boundingBox.y1);
|
|
|
|
|
|
|
|
const [, , natWidth, natHeight] = child.get_preferred_size();
|
|
|
|
childBox.set_size(natWidth, natHeight);
|
|
|
|
|
|
|
|
childBox.x1 *= scaleX;
|
|
|
|
childBox.x2 *= scaleX;
|
|
|
|
childBox.y1 *= scaleY;
|
|
|
|
childBox.y2 *= scaleY;
|
|
|
|
|
|
|
|
child.allocate(childBox);
|
|
|
|
} else {
|
|
|
|
child.allocate_preferred_size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2020-06-01 12:41:25 +00:00
|
|
|
addWindow(clone, metaWindow) {
|
|
|
|
if (this._windows.has(clone))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const windowActor = metaWindow.get_compositor_private();
|
|
|
|
|
|
|
|
this._windows.set(clone, {
|
|
|
|
metaWindow,
|
|
|
|
windowActor,
|
|
|
|
sizeChangedId: metaWindow.connect('size-changed', () =>
|
|
|
|
this._layoutChanged()),
|
|
|
|
positionChangedId: metaWindow.connect('position-changed', () =>
|
|
|
|
this._layoutChanged()),
|
|
|
|
destroyId: windowActor.connect('destroy', () =>
|
|
|
|
clone.destroy()),
|
|
|
|
cloneDestroyId: clone.connect('destroy', () =>
|
|
|
|
this.removeWindow(clone)),
|
|
|
|
});
|
2020-06-01 12:36:08 +00:00
|
|
|
|
2020-06-01 12:41:25 +00:00
|
|
|
this._container.add_child(clone);
|
2020-06-01 12:36:08 +00:00
|
|
|
|
2020-06-01 12:41:25 +00:00
|
|
|
this._layoutChanged();
|
|
|
|
}
|
2020-06-01 12:36:08 +00:00
|
|
|
|
2020-06-01 12:41:25 +00:00
|
|
|
removeWindow(clone) {
|
|
|
|
const windowInfo = this._windows.get(clone);
|
|
|
|
if (!windowInfo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
windowInfo.metaWindow.disconnect(windowInfo.sizeChangedId);
|
|
|
|
windowInfo.metaWindow.disconnect(windowInfo.positionChangedId);
|
|
|
|
windowInfo.windowActor.disconnect(windowInfo.destroyId);
|
|
|
|
clone.disconnect(windowInfo.cloneDestroyId);
|
|
|
|
|
|
|
|
this._windows.delete(clone);
|
|
|
|
this._container.remove_child(clone);
|
|
|
|
|
|
|
|
this._layoutChanged();
|
|
|
|
}
|
|
|
|
|
2020-06-08 12:47:43 +00:00
|
|
|
/**
|
|
|
|
* getWindows:
|
|
|
|
*
|
|
|
|
* Gets an array of all ClutterActors that were added to the layout
|
|
|
|
* using addWindow(), ordered by the insertion order.
|
|
|
|
*
|
|
|
|
* @returns {Array} An array including all windows
|
|
|
|
*/
|
|
|
|
getWindows() {
|
|
|
|
return [...this._windows.keys()];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getMetaWindow:
|
|
|
|
* @param {Clutter.Actor} window: the window to get the MetaWindow for
|
|
|
|
*
|
|
|
|
* Gets the MetaWindow associated to the ClutterActor @window that was
|
|
|
|
* added to the layout using addWindow(). If @window is not found,
|
|
|
|
* null is returned.
|
|
|
|
*
|
|
|
|
* @returns {Meta.Window} The metaWindow of the window
|
|
|
|
*/
|
|
|
|
getMetaWindow(window) {
|
|
|
|
const windowInfo = this._windows.get(window);
|
|
|
|
if (!windowInfo)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return windowInfo.metaWindow;
|
|
|
|
}
|
|
|
|
|
2020-06-01 12:41:25 +00:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
get bounding_box() {
|
|
|
|
return this._boundingBox;
|
2014-07-17 22:59:06 +00:00
|
|
|
}
|
2012-08-29 22:51:53 +00:00
|
|
|
});
|
|
|
|
|
2020-06-08 07:23:08 +00:00
|
|
|
var WindowPreview = GObject.registerClass({
|
2018-11-14 18:26:33 +00:00
|
|
|
Signals: {
|
|
|
|
'drag-begin': {},
|
|
|
|
'drag-cancelled': {},
|
|
|
|
'drag-end': {},
|
|
|
|
'selected': { param_types: [GObject.TYPE_UINT] },
|
|
|
|
'show-chrome': {},
|
2019-08-20 21:43:54 +00:00
|
|
|
'size-changed': {},
|
2018-11-14 18:26:33 +00:00
|
|
|
},
|
2020-06-08 07:23:08 +00:00
|
|
|
}, class WindowPreview extends St.Widget {
|
2018-11-14 18:26:33 +00:00
|
|
|
_init(realWindow, workspace) {
|
2009-01-29 21:21:50 +00:00
|
|
|
this.realWindow = realWindow;
|
2009-02-04 14:50:50 +00:00
|
|
|
this.metaWindow = realWindow.meta_window;
|
2009-09-10 01:14:31 +00:00
|
|
|
this.metaWindow._delegate = this;
|
2011-11-25 23:02:13 +00:00
|
|
|
this._workspace = workspace;
|
2011-08-29 16:25:11 +00:00
|
|
|
|
2018-11-14 18:26:33 +00:00
|
|
|
super._init({
|
|
|
|
reactive: true,
|
|
|
|
can_focus: true,
|
|
|
|
accessible_role: Atk.Role.PUSH_BUTTON,
|
2020-06-04 15:15:45 +00:00
|
|
|
offscreen_redirect: Clutter.OffscreenRedirect.AUTOMATIC_FOR_OPACITY,
|
2018-11-14 18:26:33 +00:00
|
|
|
});
|
2011-08-29 16:25:11 +00:00
|
|
|
|
2020-06-02 11:52:33 +00:00
|
|
|
this._windowContainer = new Clutter.Actor();
|
|
|
|
// gjs currently can't handle setting an actors layout manager during
|
|
|
|
// the initialization of the actor if that layout manager keeps track
|
|
|
|
// of its container, so set the layout manager after creating the
|
|
|
|
// container
|
2020-06-08 07:23:08 +00:00
|
|
|
this._windowContainer.layout_manager = new WindowPreviewLayout();
|
2020-06-02 11:52:33 +00:00
|
|
|
this.add_child(this._windowContainer);
|
|
|
|
|
2020-05-31 21:15:06 +00:00
|
|
|
this._addWindow(realWindow.meta_window);
|
2011-08-29 16:25:11 +00:00
|
|
|
|
2018-11-14 18:26:33 +00:00
|
|
|
this._delegate = this;
|
2009-01-29 21:21:50 +00:00
|
|
|
|
2017-08-20 09:19:39 +00:00
|
|
|
this.slotId = 0;
|
2009-09-28 23:48:03 +00:00
|
|
|
this._stackAbove = null;
|
|
|
|
|
2020-06-02 11:52:33 +00:00
|
|
|
this._windowContainer.layout_manager.connect(
|
2020-06-13 23:02:52 +00:00
|
|
|
'notify::bounding-box', layout => {
|
|
|
|
// A bounding box of 0x0 means all windows were removed
|
|
|
|
if (layout.bounding_box.get_area() > 0)
|
|
|
|
this.emit('size-changed');
|
|
|
|
});
|
2020-05-31 20:47:27 +00:00
|
|
|
|
|
|
|
this._windowDestroyId =
|
2020-06-01 12:41:25 +00:00
|
|
|
this.realWindow.connect('destroy', () => this.destroy());
|
2012-08-29 22:51:53 +00:00
|
|
|
|
|
|
|
this._updateAttachedDialogs();
|
2020-05-31 20:47:27 +00:00
|
|
|
this.x = this.boundingBox.x;
|
|
|
|
this.y = this.boundingBox.y;
|
2011-01-30 22:03:12 +00:00
|
|
|
|
2011-09-21 00:54:06 +00:00
|
|
|
let clickAction = new Clutter.ClickAction();
|
2020-06-08 12:49:09 +00:00
|
|
|
clickAction.connect('clicked', () => this._activate());
|
2017-12-02 00:27:35 +00:00
|
|
|
clickAction.connect('long-press', this._onLongPress.bind(this));
|
2018-11-14 18:26:33 +00:00
|
|
|
this.add_action(clickAction);
|
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
2017-07-19 00:29:16 +00:00
|
|
|
|
2018-11-14 18:26:33 +00:00
|
|
|
this._draggable = DND.makeDraggable(this,
|
2010-05-20 14:44:45 +00:00
|
|
|
{ restoreOnSuccess: true,
|
2011-09-21 00:54:06 +00:00
|
|
|
manualMode: true,
|
2010-05-20 14:44:45 +00:00
|
|
|
dragActorMaxSize: WINDOW_DND_SIZE,
|
2010-03-19 20:46:08 +00:00
|
|
|
dragActorOpacity: DRAGGING_WINDOW_OPACITY });
|
2017-12-02 00:27:35 +00:00
|
|
|
this._draggable.connect('drag-begin', this._onDragBegin.bind(this));
|
|
|
|
this._draggable.connect('drag-cancelled', this._onDragCancelled.bind(this));
|
|
|
|
this._draggable.connect('drag-end', this._onDragEnd.bind(this));
|
2010-03-19 20:46:08 +00:00
|
|
|
this.inDrag = false;
|
2009-09-28 23:48:03 +00:00
|
|
|
|
2010-02-15 22:11:09 +00:00
|
|
|
this._selected = false;
|
2018-06-19 10:45:18 +00:00
|
|
|
this._closeRequested = false;
|
2020-06-02 11:52:33 +00:00
|
|
|
this._idleHideOverlayId = 0;
|
|
|
|
|
|
|
|
this._border = new St.Widget({
|
|
|
|
visible: false,
|
|
|
|
style_class: 'window-clone-border',
|
|
|
|
});
|
|
|
|
this._borderConstraint = new Clutter.BindConstraint({
|
|
|
|
source: this._windowContainer,
|
|
|
|
coordinate: Clutter.BindCoordinate.SIZE,
|
|
|
|
});
|
|
|
|
this._border.add_constraint(this._borderConstraint);
|
|
|
|
this._border.add_constraint(new Clutter.AlignConstraint({
|
|
|
|
source: this._windowContainer,
|
|
|
|
align_axis: Clutter.AlignAxis.BOTH,
|
|
|
|
factor: 0.5,
|
|
|
|
}));
|
2020-06-14 04:14:57 +00:00
|
|
|
this._borderCenter = new Clutter.Actor();
|
|
|
|
this._border.bind_property('visible', this._borderCenter, 'visible',
|
|
|
|
GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
this._borderCenterConstraint = new Clutter.BindConstraint({
|
|
|
|
source: this._windowContainer,
|
|
|
|
coordinate: Clutter.BindCoordinate.SIZE,
|
|
|
|
});
|
|
|
|
this._borderCenter.add_constraint(this._borderCenterConstraint);
|
|
|
|
this._borderCenter.add_constraint(new Clutter.AlignConstraint({
|
|
|
|
source: this._windowContainer,
|
|
|
|
align_axis: Clutter.AlignAxis.BOTH,
|
|
|
|
factor: 0.5,
|
|
|
|
}));
|
2020-06-02 11:52:33 +00:00
|
|
|
this._border.connect('style-changed',
|
|
|
|
this._onBorderStyleChanged.bind(this));
|
|
|
|
|
|
|
|
this._title = new St.Label({
|
|
|
|
visible: false,
|
|
|
|
style_class: 'window-caption',
|
|
|
|
text: this._getCaption(),
|
|
|
|
reactive: true,
|
|
|
|
});
|
2020-06-14 04:14:57 +00:00
|
|
|
this._title.add_constraint(new Clutter.BindConstraint({
|
|
|
|
source: this._borderCenter,
|
|
|
|
coordinate: Clutter.BindCoordinate.POSITION,
|
|
|
|
}));
|
2020-06-02 11:52:33 +00:00
|
|
|
this._title.add_constraint(new Clutter.AlignConstraint({
|
2020-06-14 04:14:57 +00:00
|
|
|
source: this._borderCenter,
|
2020-06-02 11:52:33 +00:00
|
|
|
align_axis: Clutter.AlignAxis.X_AXIS,
|
|
|
|
factor: 0.5,
|
|
|
|
}));
|
|
|
|
this._title.add_constraint(new Clutter.AlignConstraint({
|
2020-06-14 04:14:57 +00:00
|
|
|
source: this._borderCenter,
|
2020-06-02 11:52:33 +00:00
|
|
|
align_axis: Clutter.AlignAxis.Y_AXIS,
|
|
|
|
pivot_point: new Graphene.Point({ x: -1, y: 0.5 }),
|
|
|
|
factor: 1,
|
|
|
|
}));
|
|
|
|
this._title.clutter_text.ellipsize = Pango.EllipsizeMode.END;
|
|
|
|
this.label_actor = this._title;
|
|
|
|
this._updateCaptionId = this.metaWindow.connect('notify::title', () => {
|
|
|
|
this._title.text = this._getCaption();
|
|
|
|
});
|
|
|
|
|
|
|
|
const layout = Meta.prefs_get_button_layout();
|
2020-06-08 15:52:57 +00:00
|
|
|
this._closeButtonSide =
|
|
|
|
layout.left_buttons.includes(Meta.ButtonFunction.CLOSE)
|
|
|
|
? St.Side.LEFT : St.Side.RIGHT;
|
2020-06-02 11:52:33 +00:00
|
|
|
|
|
|
|
this._closeButton = new St.Button({
|
|
|
|
visible: false,
|
|
|
|
style_class: 'window-close',
|
|
|
|
child: new St.Icon({ icon_name: 'window-close-symbolic' }),
|
|
|
|
});
|
|
|
|
this._closeButton.add_constraint(new Clutter.BindConstraint({
|
2020-06-14 04:23:33 +00:00
|
|
|
source: this._borderCenter,
|
2020-06-02 11:52:33 +00:00
|
|
|
coordinate: Clutter.BindCoordinate.POSITION,
|
|
|
|
}));
|
|
|
|
this._closeButton.add_constraint(new Clutter.AlignConstraint({
|
2020-06-14 04:23:33 +00:00
|
|
|
source: this._borderCenter,
|
2020-06-02 11:52:33 +00:00
|
|
|
align_axis: Clutter.AlignAxis.X_AXIS,
|
|
|
|
pivot_point: new Graphene.Point({ x: 0.5, y: -1 }),
|
2020-06-08 15:52:57 +00:00
|
|
|
factor: this._closeButtonSide === St.Side.LEFT ? 0 : 1,
|
2020-06-02 11:52:33 +00:00
|
|
|
}));
|
|
|
|
this._closeButton.add_constraint(new Clutter.AlignConstraint({
|
2020-06-14 04:23:33 +00:00
|
|
|
source: this._borderCenter,
|
2020-06-02 11:52:33 +00:00
|
|
|
align_axis: Clutter.AlignAxis.Y_AXIS,
|
|
|
|
pivot_point: new Graphene.Point({ x: -1, y: 0.5 }),
|
|
|
|
factor: 0,
|
|
|
|
}));
|
|
|
|
this._closeButton.connect('clicked', () => this.deleteAll());
|
|
|
|
|
2020-06-14 04:14:57 +00:00
|
|
|
this.add_child(this._borderCenter);
|
2020-06-02 11:52:33 +00:00
|
|
|
this.add_child(this._border);
|
|
|
|
this.add_child(this._title);
|
|
|
|
this.add_child(this._closeButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_get_preferred_width(forHeight) {
|
|
|
|
const themeNode = this.get_theme_node();
|
|
|
|
|
|
|
|
// Only include window previews in size request, not chrome
|
|
|
|
const [minWidth, natWidth] =
|
|
|
|
this._windowContainer.get_preferred_width(
|
|
|
|
themeNode.adjust_for_height(forHeight));
|
|
|
|
|
|
|
|
return themeNode.adjust_preferred_width(minWidth, natWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_get_preferred_height(forWidth) {
|
|
|
|
const themeNode = this.get_theme_node();
|
|
|
|
const [minHeight, natHeight] =
|
|
|
|
this._windowContainer.get_preferred_height(
|
|
|
|
themeNode.adjust_for_width(forWidth));
|
|
|
|
|
|
|
|
return themeNode.adjust_preferred_height(minHeight, natHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_allocate(box) {
|
|
|
|
this.set_allocation(box);
|
|
|
|
|
|
|
|
for (const child of this)
|
|
|
|
child.allocate_available_size(0, 0, box.get_width(), box.get_height());
|
|
|
|
}
|
|
|
|
|
|
|
|
_onBorderStyleChanged() {
|
|
|
|
let borderNode = this._border.get_theme_node();
|
|
|
|
this._borderSize = borderNode.get_border_width(St.Side.TOP);
|
|
|
|
|
|
|
|
// Increase the size of the border actor so the border outlines
|
|
|
|
// the bounding box
|
|
|
|
this._borderConstraint.offset = this._borderSize * 2;
|
2020-06-14 04:14:57 +00:00
|
|
|
this._borderCenterConstraint.offset = this._borderSize;
|
2020-06-02 11:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_windowCanClose() {
|
|
|
|
return this.metaWindow.can_close() &&
|
|
|
|
!this.hasAttachedDialogs();
|
|
|
|
}
|
|
|
|
|
|
|
|
_getCaption() {
|
|
|
|
if (this.metaWindow.title)
|
|
|
|
return this.metaWindow.title;
|
|
|
|
|
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
|
|
|
let app = tracker.get_window_app(this.metaWindow);
|
|
|
|
return app.get_name();
|
|
|
|
}
|
|
|
|
|
|
|
|
chromeHeights() {
|
|
|
|
this._border.ensure_style();
|
|
|
|
this._title.ensure_style();
|
|
|
|
const [, closeButtonHeight] = this._closeButton.get_preferred_height(-1);
|
|
|
|
const [, titleHeight] = this._title.get_preferred_height(-1);
|
|
|
|
|
2020-06-14 04:23:33 +00:00
|
|
|
const topOversize = (this._borderSize / 2) + (closeButtonHeight / 2);
|
2020-06-08 15:52:57 +00:00
|
|
|
const bottomOversize = Math.max(
|
|
|
|
this._borderSize,
|
|
|
|
(titleHeight / 2) + (this._borderSize / 2));
|
|
|
|
|
|
|
|
return [topOversize, bottomOversize];
|
2020-06-02 11:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chromeWidths() {
|
|
|
|
this._border.ensure_style();
|
|
|
|
const [, closeButtonWidth] = this._closeButton.get_preferred_width(-1);
|
|
|
|
|
2020-06-08 15:52:57 +00:00
|
|
|
const leftOversize = this._closeButtonSide === St.Side.LEFT
|
2020-06-14 04:23:33 +00:00
|
|
|
? (this._borderSize / 2) + (closeButtonWidth / 2)
|
2020-06-08 15:52:57 +00:00
|
|
|
: this._borderSize;
|
|
|
|
const rightOversize = this._closeButtonSide === St.Side.LEFT
|
|
|
|
? this._borderSize
|
2020-06-14 04:23:33 +00:00
|
|
|
: (this._borderSize / 2) + (closeButtonWidth / 2);
|
2020-06-08 15:52:57 +00:00
|
|
|
|
|
|
|
return [leftOversize, rightOversize];
|
2020-06-02 11:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
showOverlay(animate) {
|
|
|
|
const ongoingTransition = this._border.get_transition('opacity');
|
|
|
|
|
|
|
|
// Don't do anything if we're fully visible already
|
|
|
|
if (this._border.visible && !ongoingTransition)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we're supposed to animate and an animation in our direction
|
|
|
|
// is already happening, let that one continue
|
|
|
|
if (animate &&
|
|
|
|
ongoingTransition &&
|
|
|
|
ongoingTransition.get_interval().peek_final_value() === 255)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const toShow = this._windowCanClose()
|
|
|
|
? [this._border, this._title, this._closeButton]
|
|
|
|
: [this._border, this._title];
|
|
|
|
|
|
|
|
toShow.forEach(a => {
|
|
|
|
a.opacity = 0;
|
|
|
|
a.show();
|
|
|
|
a.ease({
|
|
|
|
opacity: 255,
|
|
|
|
duration: animate ? WINDOW_OVERLAY_FADE_TIME : 0,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
});
|
|
|
|
});
|
2020-06-02 11:56:03 +00:00
|
|
|
|
|
|
|
this.emit('show-chrome');
|
2020-06-02 11:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hideOverlay(animate) {
|
|
|
|
const ongoingTransition = this._border.get_transition('opacity');
|
|
|
|
|
|
|
|
// Don't do anything if we're fully hidden already
|
|
|
|
if (!this._border.visible && !ongoingTransition)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we're supposed to animate and an animation in our direction
|
|
|
|
// is already happening, let that one continue
|
|
|
|
if (animate &&
|
|
|
|
ongoingTransition &&
|
|
|
|
ongoingTransition.get_interval().peek_final_value() === 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
[this._border, this._title, this._closeButton].forEach(a => {
|
|
|
|
a.opacity = 255;
|
|
|
|
a.ease({
|
|
|
|
opacity: 0,
|
|
|
|
duration: animate ? WINDOW_OVERLAY_FADE_TIME : 0,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
onComplete: () => a.hide(),
|
|
|
|
});
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-01-29 21:21:50 +00:00
|
|
|
|
2020-05-31 21:15:06 +00:00
|
|
|
_addWindow(metaWindow) {
|
|
|
|
const windowActor = metaWindow.get_compositor_private();
|
|
|
|
const clone = new Clutter.Clone({ source: windowActor });
|
|
|
|
|
|
|
|
// We expect this to be used for all interaction rather than
|
|
|
|
// the ClutterClone; as the former is reactive and the latter
|
|
|
|
// is not, this just works for most cases. However, for DND all
|
|
|
|
// actors are picked, so DND operations would operate on the clone.
|
|
|
|
// To avoid this, we hide it from pick.
|
|
|
|
Shell.util_set_hidden_from_pick(clone, true);
|
|
|
|
|
2020-06-02 11:52:33 +00:00
|
|
|
this._windowContainer.layout_manager.addWindow(clone, metaWindow);
|
2020-05-31 21:15:06 +00:00
|
|
|
}
|
|
|
|
|
2018-11-13 16:24:37 +00:00
|
|
|
vfunc_has_overlaps() {
|
|
|
|
return this.hasAttachedDialogs();
|
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
deleteAll() {
|
2020-06-02 11:52:33 +00:00
|
|
|
const windows = this._windowContainer.layout_manager.getWindows();
|
2020-06-08 12:50:23 +00:00
|
|
|
|
2012-08-29 22:51:53 +00:00
|
|
|
// Delete all windows, starting from the bottom-most (most-modal) one
|
2020-06-08 12:50:23 +00:00
|
|
|
for (const window of windows.reverse()) {
|
2020-06-02 11:52:33 +00:00
|
|
|
const metaWindow =
|
|
|
|
this._windowContainer.layout_manager.getMetaWindow(window);
|
2012-08-29 22:51:53 +00:00
|
|
|
|
|
|
|
metaWindow.delete(global.get_current_time());
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:45:18 +00:00
|
|
|
this._closeRequested = true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2018-06-19 10:45:18 +00:00
|
|
|
addDialog(win) {
|
|
|
|
let parent = win.get_transient_for();
|
|
|
|
while (parent.is_attached_dialog())
|
|
|
|
parent = parent.get_transient_for();
|
|
|
|
|
|
|
|
// Display dialog if it is attached to our metaWindow
|
2020-05-31 20:47:27 +00:00
|
|
|
if (win.is_attached_dialog() && parent == this.metaWindow)
|
2020-05-31 21:15:06 +00:00
|
|
|
this._addWindow(win);
|
2018-06-19 10:45:18 +00:00
|
|
|
|
|
|
|
// The dialog popped up after the user tried to close the window,
|
|
|
|
// assume it's a close confirmation and leave the overview
|
|
|
|
if (this._closeRequested)
|
|
|
|
this._activate();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
hasAttachedDialogs() {
|
2020-06-02 11:52:33 +00:00
|
|
|
return this._windowContainer.layout_manager.getWindows().length > 1;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-05-08 09:21:34 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateAttachedDialogs() {
|
2017-10-31 00:38:18 +00:00
|
|
|
let iter = win => {
|
2012-08-29 22:51:53 +00:00
|
|
|
let actor = win.get_compositor_private();
|
|
|
|
|
|
|
|
if (!actor)
|
|
|
|
return false;
|
|
|
|
if (!win.is_attached_dialog())
|
|
|
|
return false;
|
|
|
|
|
2020-05-31 21:15:06 +00:00
|
|
|
this._addWindow(win);
|
2012-08-29 22:51:53 +00:00
|
|
|
win.foreach_transient(iter);
|
|
|
|
return true;
|
2017-10-31 00:38:18 +00:00
|
|
|
};
|
2012-08-29 22:51:53 +00:00
|
|
|
this.metaWindow.foreach_transient(iter);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-29 22:51:53 +00:00
|
|
|
|
|
|
|
get boundingBox() {
|
2020-06-02 11:52:33 +00:00
|
|
|
const box = this._windowContainer.layout_manager.bounding_box;
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2020-05-31 20:47:27 +00:00
|
|
|
return {
|
|
|
|
x: box.x1,
|
|
|
|
y: box.y1,
|
|
|
|
width: box.get_width(),
|
|
|
|
height: box.get_height(),
|
|
|
|
};
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2019-10-15 11:35:18 +00:00
|
|
|
get windowCenter() {
|
2020-06-02 11:52:33 +00:00
|
|
|
const box = this._windowContainer.layout_manager.bounding_box;
|
2019-10-15 11:35:18 +00:00
|
|
|
|
2020-05-31 20:48:28 +00:00
|
|
|
return new Graphene.Point({
|
2019-10-15 11:35:18 +00:00
|
|
|
x: box.get_x() + box.get_width() / 2,
|
|
|
|
y: box.get_y() + box.get_height() / 2,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-19 11:28:28 +00:00
|
|
|
// Find the actor just below us, respecting reparenting done by DND code
|
2017-10-31 00:03:21 +00:00
|
|
|
getActualStackAbove() {
|
2013-01-19 01:22:15 +00:00
|
|
|
if (this._stackAbove == null)
|
|
|
|
return null;
|
|
|
|
|
2013-06-29 09:47:59 +00:00
|
|
|
if (this.inDrag) {
|
2013-01-19 01:22:15 +00:00
|
|
|
if (this._stackAbove._delegate)
|
|
|
|
return this._stackAbove._delegate.getActualStackAbove();
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return this._stackAbove;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-01-19 01:22:15 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setStackAbove(actor) {
|
2009-09-28 23:48:03 +00:00
|
|
|
this._stackAbove = actor;
|
2012-10-22 14:46:36 +00:00
|
|
|
if (this.inDrag)
|
|
|
|
// We'll fix up the stack after the drag
|
2009-09-28 23:48:03 +00:00
|
|
|
return;
|
2013-01-19 01:22:15 +00:00
|
|
|
|
2019-11-05 19:17:19 +00:00
|
|
|
let parent = this.get_parent();
|
2013-01-19 01:22:15 +00:00
|
|
|
let actualAbove = this.getActualStackAbove();
|
|
|
|
if (actualAbove == null)
|
2019-11-05 19:17:19 +00:00
|
|
|
parent.set_child_below_sibling(this, null);
|
2010-07-15 14:21:32 +00:00
|
|
|
else
|
2019-11-05 19:17:19 +00:00
|
|
|
parent.set_child_above_sibling(this, actualAbove);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-02-10 16:15:59 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onDestroy() {
|
2020-05-31 20:47:27 +00:00
|
|
|
this.realWindow.disconnect(this._windowDestroyId);
|
2011-02-03 18:25:59 +00:00
|
|
|
|
2010-03-17 22:23:32 +00:00
|
|
|
this.metaWindow._delegate = null;
|
2018-11-14 18:26:33 +00:00
|
|
|
this._delegate = null;
|
2010-03-17 22:23:32 +00:00
|
|
|
|
2020-06-02 11:52:33 +00:00
|
|
|
this.metaWindow.disconnect(this._updateCaptionId);
|
|
|
|
|
2019-07-12 11:53:33 +00:00
|
|
|
if (this._longPressLater) {
|
|
|
|
Meta.later_remove(this._longPressLater);
|
|
|
|
delete this._longPressLater;
|
|
|
|
}
|
|
|
|
|
2020-06-02 11:52:33 +00:00
|
|
|
if (this._idleHideOverlayId > 0) {
|
|
|
|
GLib.source_remove(this._idleHideOverlayId);
|
|
|
|
this._idleHideOverlayId = 0;
|
|
|
|
}
|
|
|
|
|
2010-03-19 20:46:08 +00:00
|
|
|
if (this.inDrag) {
|
2010-03-18 20:39:11 +00:00
|
|
|
this.emit('drag-end');
|
2010-03-19 20:46:08 +00:00
|
|
|
this.inDrag = false;
|
2010-03-18 20:39:11 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-02-07 14:25:16 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_activate() {
|
2010-02-15 22:11:09 +00:00
|
|
|
this._selected = true;
|
2011-09-21 00:54:06 +00:00
|
|
|
this.emit('selected', global.get_current_time());
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-09-21 00:54:06 +00:00
|
|
|
|
2019-09-10 05:42:48 +00:00
|
|
|
vfunc_enter_event(crossingEvent) {
|
2020-06-02 11:56:03 +00:00
|
|
|
this.showOverlay(true);
|
2019-09-10 05:42:48 +00:00
|
|
|
return super.vfunc_enter_event(crossingEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_leave_event(crossingEvent) {
|
2020-06-02 11:52:33 +00:00
|
|
|
if (this._idleHideOverlayId > 0)
|
|
|
|
GLib.source_remove(this._idleHideOverlayId);
|
|
|
|
|
|
|
|
this._idleHideOverlayId = GLib.timeout_add(
|
|
|
|
GLib.PRIORITY_DEFAULT,
|
|
|
|
WINDOW_OVERLAY_IDLE_HIDE_TIMEOUT, () => {
|
|
|
|
if (this._closeButton['has-pointer'] ||
|
|
|
|
this._title['has-pointer'])
|
|
|
|
return GLib.SOURCE_CONTINUE;
|
|
|
|
|
|
|
|
if (!this['has-pointer'])
|
|
|
|
this.hideOverlay(true);
|
|
|
|
|
|
|
|
this._idleHideOverlayId = 0;
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
|
|
|
|
|
|
|
GLib.Source.set_name_by_id(this._idleHideOverlayId, '[gnome-shell] this._idleHideOverlayId');
|
|
|
|
|
2019-09-10 05:42:48 +00:00
|
|
|
return super.vfunc_leave_event(crossingEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_key_focus_in() {
|
|
|
|
super.vfunc_key_focus_in();
|
2020-06-02 11:56:03 +00:00
|
|
|
this.showOverlay(true);
|
2019-09-10 05:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_key_focus_out() {
|
|
|
|
super.vfunc_key_focus_out();
|
2020-06-02 11:52:33 +00:00
|
|
|
this.hideOverlay(true);
|
2019-09-10 05:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vfunc_key_press_event(keyEvent) {
|
|
|
|
let symbol = keyEvent.keyval;
|
2019-08-19 19:38:51 +00:00
|
|
|
let isEnter = symbol == Clutter.KEY_Return || symbol == Clutter.KEY_KP_Enter;
|
2013-11-04 22:23:44 +00:00
|
|
|
if (isEnter) {
|
|
|
|
this._activate();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-03 12:43:16 +00:00
|
|
|
return super.vfunc_key_press_event(keyEvent);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-11-04 22:23:44 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onLongPress(action, actor, state) {
|
2011-09-21 00:54:06 +00:00
|
|
|
// Take advantage of the Clutter policy to consider
|
|
|
|
// a long-press canceled when the pointer movement
|
|
|
|
// exceeds dnd-drag-threshold to manually start the drag
|
|
|
|
if (state == Clutter.LongPressState.CANCEL) {
|
2015-10-16 16:32:42 +00:00
|
|
|
let event = Clutter.get_current_event();
|
|
|
|
this._dragTouchSequence = event.get_event_sequence();
|
|
|
|
|
2019-07-12 11:53:33 +00:00
|
|
|
if (this._longPressLater)
|
|
|
|
return true;
|
|
|
|
|
2011-09-21 00:54:06 +00:00
|
|
|
// A click cancels a long-press before any click handler is
|
|
|
|
// run - make sure to not start a drag in that case
|
2019-07-12 11:53:33 +00:00
|
|
|
this._longPressLater = Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
|
|
|
|
delete this._longPressLater;
|
2017-10-31 00:38:18 +00:00
|
|
|
if (this._selected)
|
|
|
|
return;
|
|
|
|
let [x, y] = action.get_coords();
|
|
|
|
action.release();
|
2019-12-13 17:14:51 +00:00
|
|
|
this._draggable.startDrag(x, y, global.get_current_time(), this._dragTouchSequence, event.get_device());
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-07-19 00:31:04 +00:00
|
|
|
} else {
|
2020-06-02 11:56:03 +00:00
|
|
|
this.showOverlay(true);
|
2011-09-21 00:54:06 +00:00
|
|
|
}
|
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-01-29 21:21:50 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
_onDragBegin(_draggable, _time) {
|
2010-03-19 20:46:08 +00:00
|
|
|
this.inDrag = true;
|
2020-06-02 11:56:03 +00:00
|
|
|
this.hideOverlay(false);
|
2009-07-23 21:36:41 +00:00
|
|
|
this.emit('drag-begin');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-01-29 21:21:50 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
handleDragOver(source, actor, x, y, time) {
|
2011-11-25 23:02:13 +00:00
|
|
|
return this._workspace.handleDragOver(source, actor, x, y, time);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-06-07 21:15:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
acceptDrop(source, actor, x, y, time) {
|
2019-05-02 15:49:21 +00:00
|
|
|
return this._workspace.acceptDrop(source, actor, x, y, time);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-06-07 21:15:33 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
_onDragCancelled(_draggable, _time) {
|
2011-03-08 13:44:47 +00:00
|
|
|
this.emit('drag-cancelled');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-03-08 13:44:47 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
_onDragEnd(_draggable, _time, _snapback) {
|
2010-03-19 20:46:08 +00:00
|
|
|
this.inDrag = false;
|
2009-01-29 21:21:50 +00:00
|
|
|
|
2009-09-28 23:48:03 +00:00
|
|
|
// We may not have a parent if DnD completed successfully, in
|
|
|
|
// which case our clone will shortly be destroyed and replaced
|
|
|
|
// with a new one on the target workspace.
|
2019-11-05 19:17:19 +00:00
|
|
|
let parent = this.get_parent();
|
|
|
|
if (parent !== null) {
|
2010-07-15 14:21:32 +00:00
|
|
|
if (this._stackAbove == null)
|
2019-11-05 19:17:19 +00:00
|
|
|
parent.set_child_below_sibling(this, null);
|
2010-07-15 14:21:32 +00:00
|
|
|
else
|
2019-11-05 19:17:19 +00:00
|
|
|
parent.set_child_above_sibling(this, this._stackAbove);
|
2010-01-06 03:53:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 11:56:03 +00:00
|
|
|
if (this['has-pointer'])
|
|
|
|
this.showOverlay(true);
|
2010-01-06 03:53:36 +00:00
|
|
|
|
2010-07-15 14:21:32 +00:00
|
|
|
this.emit('drag-end');
|
2009-01-29 21:21:50 +00:00
|
|
|
}
|
2018-11-14 18:26:33 +00:00
|
|
|
});
|
2009-01-29 21:21:50 +00:00
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
var WindowPositionFlags = {
|
2012-12-11 22:26:09 +00:00
|
|
|
NONE: 0,
|
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 16:04:03 +00:00
|
|
|
INITIAL: 1 << 0,
|
2019-08-20 21:43:54 +00:00
|
|
|
ANIMATE: 1 << 1,
|
2010-01-22 02:33:48 +00:00
|
|
|
};
|
2009-11-12 00:26:52 +00:00
|
|
|
|
2013-02-28 20:50:57 +00: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 07:23:08 +00:00
|
|
|
// larger than WINDOW_PREVIEW_MAXIMUM_SCALE, which means that the inequality:
|
2013-02-28 20:50:57 +00:00
|
|
|
//
|
2020-06-08 07:23:08 +00:00
|
|
|
// windowScale * layoutScale <= WINDOW_PREVIEW_MAXIMUM_SCALE
|
2013-02-28 20:50:57 +00: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 07:23:08 +00:00
|
|
|
// WINDOW_PREVIEW_MAXIMUM_SCALE, it would shrink windows which are already
|
2013-02-28 21:08:19 +00: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 20:50:57 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var LayoutStrategy = class {
|
|
|
|
constructor(monitor, rowSpacing, columnSpacing) {
|
2019-04-18 20:55:34 +00:00
|
|
|
if (this.constructor === LayoutStrategy)
|
|
|
|
throw new TypeError(`Cannot instantiate abstract type ${this.constructor.name}`);
|
2012-08-08 17:27:46 +00:00
|
|
|
|
|
|
|
this._monitor = monitor;
|
|
|
|
this._rowSpacing = rowSpacing;
|
|
|
|
this._columnSpacing = columnSpacing;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_newRow() {
|
2012-08-08 17:27:46 +00: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-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2013-02-28 20:00:59 +00:00
|
|
|
// Computes and returns an individual scaling factor for @window,
|
2019-05-15 19:32:29 +00:00
|
|
|
// to be applied in addition to the overall layout scale.
|
2017-10-31 00:03:21 +00:00
|
|
|
_computeWindowScale(window) {
|
2012-10-26 15:43:38 +00: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 21:33:00 +00:00
|
|
|
let ratio = window.boundingBox.height / this._monitor.height;
|
2012-10-26 15:43:38 +00: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]
|
2013-02-28 20:00:59 +00:00
|
|
|
return _interpolate(1.5, 1, ratio);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
|
|
|
// Compute the size of each row, by assigning to the properties
|
|
|
|
// row.width, row.height, row.fullWidth, row.fullHeight, and
|
2013-02-26 00:23:39 +00:00
|
|
|
// (optionally) for each row in @layout.rows. This method is
|
|
|
|
// intended to be called by subclasses.
|
2019-01-31 14:08:10 +00:00
|
|
|
_computeRowSizes(_layout) {
|
2019-05-21 20:28:07 +00:00
|
|
|
throw new GObject.NotImplementedError(`_computeRowSizes in ${this.constructor.name}`);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
|
|
|
// Compute strategy-specific window slots for each window in
|
|
|
|
// @windows, given the @layout. The strategy may also use @layout
|
|
|
|
// as strategy-specific storage.
|
|
|
|
//
|
|
|
|
// 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.
|
2019-01-31 14:08:10 +00:00
|
|
|
computeLayout(_windows, _layout) {
|
2019-05-21 20:28:07 +00:00
|
|
|
throw new GObject.NotImplementedError(`computeLayout in ${this.constructor.name}`);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
|
|
|
// Given @layout, compute the overall scale and space of the layout.
|
|
|
|
// The scale is the individual, non-fancy scale of each window, and
|
|
|
|
// the space is the percentage of the available area eventually
|
|
|
|
// used by the layout.
|
|
|
|
|
|
|
|
// This method does not return anything, but instead installs
|
|
|
|
// the properties "scale" and "space" on @layout directly.
|
|
|
|
//
|
|
|
|
// Make sure to call this methods before calling computeWindowSlots(),
|
|
|
|
// as it depends on the scale property installed in @layout here.
|
2017-10-31 00:03:21 +00:00
|
|
|
computeScaleAndSpace(layout) {
|
2012-08-08 17:27:46 +00:00
|
|
|
let area = layout.area;
|
|
|
|
|
|
|
|
let hspacing = (layout.maxColumns - 1) * this._columnSpacing;
|
2012-12-13 18:28:25 +00:00
|
|
|
let vspacing = (layout.numRows - 1) * this._rowSpacing;
|
2012-08-08 17:27:46 +00: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 07:23:08 +00:00
|
|
|
let scale = Math.min(
|
|
|
|
horizontalScale, verticalScale, WINDOW_PREVIEW_MAXIMUM_SCALE);
|
2012-08-08 17:27:46 +00:00
|
|
|
|
|
|
|
let scaledLayoutWidth = layout.gridWidth * scale + hspacing;
|
|
|
|
let scaledLayoutHeight = layout.gridHeight * scale + vspacing;
|
|
|
|
let space = (scaledLayoutWidth * scaledLayoutHeight) / (area.width * area.height);
|
|
|
|
|
|
|
|
layout.scale = scale;
|
|
|
|
layout.space = space;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
computeWindowSlots(layout, area) {
|
2012-08-08 17:27:46 +00:00
|
|
|
this._computeRowSizes(layout);
|
|
|
|
|
2019-09-12 15:19:51 +00:00
|
|
|
let { rows, scale } = layout;
|
2012-08-08 17:27:46 +00:00
|
|
|
|
|
|
|
let slots = [];
|
|
|
|
|
2013-02-26 02:40:13 +00:00
|
|
|
// Do this in three parts.
|
2015-03-03 19:07:22 +00:00
|
|
|
let heightWithoutSpacing = 0;
|
2013-02-26 02:40:13 +00:00
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
|
|
let row = rows[i];
|
2015-03-03 19:07:22 +00:00
|
|
|
heightWithoutSpacing += row.height;
|
2013-02-26 02:40:13 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 19:07:22 +00:00
|
|
|
let verticalSpacing = (rows.length - 1) * this._rowSpacing;
|
|
|
|
let additionalVerticalScale = Math.min(1, (area.height - verticalSpacing) / heightWithoutSpacing);
|
2013-02-26 02:40:13 +00:00
|
|
|
|
2015-03-03 19:07:22 +00:00
|
|
|
// keep track how much smaller the grid becomes due to scaling
|
|
|
|
// so it can be centered again
|
2019-01-29 01:18:52 +00:00
|
|
|
let compensation = 0;
|
2012-08-08 17:27:46 +00:00
|
|
|
let y = 0;
|
2013-02-26 02:40:13 +00:00
|
|
|
|
2012-08-08 17:27:46 +00:00
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
|
|
let row = rows[i];
|
2013-04-22 22:04:56 +00:00
|
|
|
|
|
|
|
// If this window layout row doesn't fit in the actual
|
|
|
|
// geometry, then apply an additional scale to it.
|
2015-03-03 19:07:22 +00: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 22:04:56 +00:00
|
|
|
|
2019-01-29 01:18:52 +00:00
|
|
|
row.x = area.x + (Math.max(area.width - (widthWithoutSpacing * row.additionalScale + horizontalSpacing), 0) / 2);
|
2015-03-03 19:07:22 +00:00
|
|
|
row.y = area.y + (Math.max(area.height - (heightWithoutSpacing + verticalSpacing), 0) / 2) + y;
|
|
|
|
y += row.height * row.additionalScale + this._rowSpacing;
|
2012-08-08 17:27:46 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 19:12:21 +00:00
|
|
|
compensation /= 2;
|
2015-03-03 19:07:22 +00:00
|
|
|
|
2012-08-08 17:27:46 +00:00
|
|
|
for (let i = 0; i < rows.length; i++) {
|
|
|
|
let row = rows[i];
|
2013-02-26 00:23:39 +00:00
|
|
|
let x = row.x;
|
2012-08-08 17:27:46 +00:00
|
|
|
for (let j = 0; j < row.windows.length; j++) {
|
|
|
|
let window = row.windows[j];
|
|
|
|
|
2013-04-22 22:04:56 +00:00
|
|
|
let s = scale * this._computeWindowScale(window) * row.additionalScale;
|
2020-05-31 21:33:00 +00:00
|
|
|
let cellWidth = window.boundingBox.width * s;
|
|
|
|
let cellHeight = window.boundingBox.height * s;
|
2013-02-28 21:08:19 +00:00
|
|
|
|
2020-06-08 07:23:08 +00:00
|
|
|
s = Math.min(s, WINDOW_PREVIEW_MAXIMUM_SCALE);
|
2020-05-31 21:33:00 +00:00
|
|
|
let cloneWidth = window.boundingBox.width * s;
|
2019-09-01 09:49:58 +00:00
|
|
|
const cloneHeight = window.boundingBox.height * s;
|
2013-02-28 21:08:19 +00:00
|
|
|
|
|
|
|
let cloneX = x + (cellWidth - cloneWidth) / 2;
|
2015-03-03 19:07:22 +00:00
|
|
|
let cloneY = row.y + row.height * row.additionalScale - cellHeight + compensation;
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2017-08-22 17:05:11 +00:00
|
|
|
// Align with the pixel grid to prevent blurry windows at scale = 1
|
|
|
|
cloneX = Math.floor(cloneX);
|
|
|
|
cloneY = Math.floor(cloneY);
|
|
|
|
|
2019-09-01 09:49:58 +00:00
|
|
|
slots.push([cloneX, cloneY, cloneWidth, cloneHeight, window]);
|
2013-02-28 21:08:19 +00:00
|
|
|
x += cellWidth + this._columnSpacing;
|
2012-08-08 17:27:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return slots;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var UnalignedLayoutStrategy = class extends LayoutStrategy {
|
2017-10-31 00:03:21 +00:00
|
|
|
_computeRowSizes(layout) {
|
2019-09-12 15:19:51 +00:00
|
|
|
let { rows, scale } = layout;
|
2012-08-08 17:27:46 +00:00
|
|
|
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-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_keepSameRow(row, window, width, idealRowWidth) {
|
2012-08-08 17:27:46 +00:00
|
|
|
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-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sortRow(row) {
|
workspace: Sort windows to minimize travel distance
When transitioning to or from the overview, windows travel
a certain distance between their real desktop position and
their place in the overview window grid. The less this travel
distance is, the smoother, more polished, and less jarring
the overall transition looks. This is why it makes sense to
try reordering and repositioning windows to minimize their
travel distance. That being said, there are other factors
that impact the quality of the overview layout, such as how
much the windows get scaled and what portion of the overall
available space they take up.
The existing code tries to minimize the travel distance by
sorting the windows in each row by their horizontal position.
There are, however, two problems with this implementation.
First, it compares the coordinates of windows' left edges as
opposed to their centers, which means it yields unexpected
results when a small window is positioned next to the left
edge of a large window. Second, it completely disregards
vertical coordinates, instead assigning windows to the grid
rows using their monotonically increasing window numbers,
effectively vertically sorting them by the order they were
created in.
This commit changes both vertical and horizontal ordering
to work based on the coordinates of the geometric centers
of the windows. That is to say, windows are first assigned
to grid rows based on the vertical coordinates of their
centers, and subsequently sorted inside each row based on
the horizontal coordinates of said centers. In my testing,
this leads to a much more intuitive and visually pleasing
window placement.
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/267
2018-10-20 13:28:05 +00:00
|
|
|
// Sort windows horizontally to minimize travel distance.
|
|
|
|
// This affects in what order the windows end up in a row.
|
2019-10-15 11:35:18 +00:00
|
|
|
row.windows.sort((a, b) => a.windowCenter.x - b.windowCenter.x);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-04-24 17:53:11 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
computeLayout(windows, layout) {
|
2012-08-08 17:27:46 +00:00
|
|
|
let numRows = layout.numRows;
|
|
|
|
|
|
|
|
let rows = [];
|
|
|
|
let totalWidth = 0;
|
|
|
|
for (let i = 0; i < windows.length; i++) {
|
2013-02-28 21:01:15 +00:00
|
|
|
let window = windows[i];
|
|
|
|
let s = this._computeWindowScale(window);
|
2020-05-31 21:33:00 +00:00
|
|
|
totalWidth += window.boundingBox.width * s;
|
2012-08-08 17:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let idealRowWidth = totalWidth / numRows;
|
workspace: Sort windows to minimize travel distance
When transitioning to or from the overview, windows travel
a certain distance between their real desktop position and
their place in the overview window grid. The less this travel
distance is, the smoother, more polished, and less jarring
the overall transition looks. This is why it makes sense to
try reordering and repositioning windows to minimize their
travel distance. That being said, there are other factors
that impact the quality of the overview layout, such as how
much the windows get scaled and what portion of the overall
available space they take up.
The existing code tries to minimize the travel distance by
sorting the windows in each row by their horizontal position.
There are, however, two problems with this implementation.
First, it compares the coordinates of windows' left edges as
opposed to their centers, which means it yields unexpected
results when a small window is positioned next to the left
edge of a large window. Second, it completely disregards
vertical coordinates, instead assigning windows to the grid
rows using their monotonically increasing window numbers,
effectively vertically sorting them by the order they were
created in.
This commit changes both vertical and horizontal ordering
to work based on the coordinates of the geometric centers
of the windows. That is to say, windows are first assigned
to grid rows based on the vertical coordinates of their
centers, and subsequently sorted inside each row based on
the horizontal coordinates of said centers. In my testing,
this leads to a much more intuitive and visually pleasing
window placement.
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/267
2018-10-20 13:28:05 +00:00
|
|
|
|
|
|
|
// Sort windows vertically to minimize travel distance.
|
|
|
|
// This affects what rows the windows get placed in.
|
|
|
|
let sortedWindows = windows.slice();
|
2019-10-15 11:35:18 +00:00
|
|
|
sortedWindows.sort((a, b) => a.windowCenter.y - b.windowCenter.y);
|
workspace: Sort windows to minimize travel distance
When transitioning to or from the overview, windows travel
a certain distance between their real desktop position and
their place in the overview window grid. The less this travel
distance is, the smoother, more polished, and less jarring
the overall transition looks. This is why it makes sense to
try reordering and repositioning windows to minimize their
travel distance. That being said, there are other factors
that impact the quality of the overview layout, such as how
much the windows get scaled and what portion of the overall
available space they take up.
The existing code tries to minimize the travel distance by
sorting the windows in each row by their horizontal position.
There are, however, two problems with this implementation.
First, it compares the coordinates of windows' left edges as
opposed to their centers, which means it yields unexpected
results when a small window is positioned next to the left
edge of a large window. Second, it completely disregards
vertical coordinates, instead assigning windows to the grid
rows using their monotonically increasing window numbers,
effectively vertically sorting them by the order they were
created in.
This commit changes both vertical and horizontal ordering
to work based on the coordinates of the geometric centers
of the windows. That is to say, windows are first assigned
to grid rows based on the vertical coordinates of their
centers, and subsequently sorted inside each row based on
the horizontal coordinates of said centers. In my testing,
this leads to a much more intuitive and visually pleasing
window placement.
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/267
2018-10-20 13:28:05 +00:00
|
|
|
|
2012-08-08 17:27:46 +00:00
|
|
|
let windowIdx = 0;
|
|
|
|
for (let i = 0; i < numRows; i++) {
|
|
|
|
let row = this._newRow();
|
|
|
|
rows.push(row);
|
|
|
|
|
workspace: Sort windows to minimize travel distance
When transitioning to or from the overview, windows travel
a certain distance between their real desktop position and
their place in the overview window grid. The less this travel
distance is, the smoother, more polished, and less jarring
the overall transition looks. This is why it makes sense to
try reordering and repositioning windows to minimize their
travel distance. That being said, there are other factors
that impact the quality of the overview layout, such as how
much the windows get scaled and what portion of the overall
available space they take up.
The existing code tries to minimize the travel distance by
sorting the windows in each row by their horizontal position.
There are, however, two problems with this implementation.
First, it compares the coordinates of windows' left edges as
opposed to their centers, which means it yields unexpected
results when a small window is positioned next to the left
edge of a large window. Second, it completely disregards
vertical coordinates, instead assigning windows to the grid
rows using their monotonically increasing window numbers,
effectively vertically sorting them by the order they were
created in.
This commit changes both vertical and horizontal ordering
to work based on the coordinates of the geometric centers
of the windows. That is to say, windows are first assigned
to grid rows based on the vertical coordinates of their
centers, and subsequently sorted inside each row based on
the horizontal coordinates of said centers. In my testing,
this leads to a much more intuitive and visually pleasing
window placement.
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/267
2018-10-20 13:28:05 +00:00
|
|
|
for (; windowIdx < sortedWindows.length; windowIdx++) {
|
|
|
|
let window = sortedWindows[windowIdx];
|
2013-02-28 20:00:59 +00:00
|
|
|
let s = this._computeWindowScale(window);
|
2020-05-31 21:33:00 +00:00
|
|
|
let width = window.boundingBox.width * s;
|
|
|
|
let height = window.boundingBox.height * s;
|
2012-08-08 17:27:46 +00:00
|
|
|
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];
|
2013-08-31 20:57:41 +00:00
|
|
|
this._sortRow(row);
|
|
|
|
|
2012-08-08 17:27:46 +00:00
|
|
|
if (!maxRow || row.fullWidth > maxRow.fullWidth)
|
|
|
|
maxRow = row;
|
|
|
|
gridHeight += row.fullHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
layout.rows = rows;
|
|
|
|
layout.maxColumns = maxRow.windows.length;
|
|
|
|
layout.gridWidth = maxRow.fullWidth;
|
|
|
|
layout.gridHeight = gridHeight;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2013-02-26 03:38:30 +00:00
|
|
|
function padArea(area, padding) {
|
|
|
|
return {
|
|
|
|
x: area.x + padding.left,
|
|
|
|
y: area.y + padding.top,
|
|
|
|
width: area.width - padding.left - padding.right,
|
|
|
|
height: area.height - padding.top - padding.bottom,
|
|
|
|
};
|
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2013-09-11 14:41:54 +00:00
|
|
|
function rectEqual(one, two) {
|
|
|
|
if (one == two)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!one || !two)
|
|
|
|
return false;
|
|
|
|
|
2019-08-19 19:38:51 +00:00
|
|
|
return one.x == two.x &&
|
2013-09-11 14:41:54 +00:00
|
|
|
one.y == two.y &&
|
|
|
|
one.width == two.width &&
|
2019-08-19 19:38:51 +00:00
|
|
|
one.height == two.height;
|
2013-09-11 14:41:54 +00:00
|
|
|
}
|
|
|
|
|
2009-07-23 21:36:41 +00:00
|
|
|
/**
|
2011-03-03 21:33:27 +00:00
|
|
|
* @metaWorkspace: a #Meta.Workspace, or null
|
2009-07-23 21:36:41 +00:00
|
|
|
*/
|
2019-07-16 09:24:13 +00:00
|
|
|
var Workspace = GObject.registerClass(
|
|
|
|
class Workspace extends St.Widget {
|
|
|
|
_init(metaWorkspace, monitorIndex) {
|
|
|
|
super._init({ style_class: 'window-picker' });
|
|
|
|
|
2010-03-16 15:51:24 +00:00
|
|
|
// When dragging a window, we use this slot for reserve space.
|
|
|
|
this._reservedSlot = null;
|
2017-06-13 02:24:12 +00:00
|
|
|
this._reservedSlotWindow = null;
|
2010-02-14 23:32:57 +00:00
|
|
|
this.metaWorkspace = metaWorkspace;
|
2013-02-25 23:25:27 +00:00
|
|
|
|
|
|
|
// The full geometry is the geometry we should try and position
|
|
|
|
// windows for. The actual geometry we allocate may be less than
|
|
|
|
// this, like if the workspace switcher is slid out.
|
|
|
|
this._fullGeometry = null;
|
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 16:04:03 +00:00
|
|
|
|
2013-02-25 23:34:17 +00:00
|
|
|
// The actual geometry is the geometry we need to arrange windows
|
|
|
|
// in. If this is a smaller area than the full geometry, we'll
|
|
|
|
// do some simple aspect ratio like math to fit the layout calculated
|
|
|
|
// for the full geometry into this area.
|
|
|
|
this._actualGeometry = null;
|
2017-09-17 08:37:17 +00:00
|
|
|
this._actualGeometryLater = 0;
|
2013-02-25 23:34:17 +00:00
|
|
|
|
|
|
|
this._currentLayout = null;
|
|
|
|
|
2011-03-01 08:14:56 +00:00
|
|
|
this.monitorIndex = monitorIndex;
|
2011-06-13 13:54:05 +00:00
|
|
|
this._monitor = Main.layoutManager.monitors[this.monitorIndex];
|
2010-01-22 02:33:48 +00:00
|
|
|
|
2012-12-13 18:28:25 +00:00
|
|
|
if (monitorIndex != Main.layoutManager.primaryIndex)
|
2019-07-16 09:24:13 +00:00
|
|
|
this.add_style_class_name('external-monitor');
|
|
|
|
this.set_size(0, 0);
|
2010-02-18 15:43:58 +00:00
|
|
|
|
2013-05-09 01:53:20 +00:00
|
|
|
this._dropRect = new Clutter.Actor({ opacity: 0 });
|
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 16:04:03 +00:00
|
|
|
this._dropRect._delegate = this;
|
2010-02-18 15:43:58 +00:00
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
this.add_actor(this._dropRect);
|
2010-02-14 23:32:57 +00:00
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
this.connect('destroy', this._onDestroy.bind(this));
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2011-03-01 08:14:56 +00:00
|
|
|
let windows = global.get_window_actors().filter(this._isMyWindow, this);
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2011-02-19 23:39:10 +00:00
|
|
|
// Create clones for windows that should be
|
2009-08-11 11:46:10 +00:00
|
|
|
// visible in the Overview
|
2010-07-15 14:21:32 +00:00
|
|
|
this._windows = [];
|
2008-12-22 21:51:34 +00:00
|
|
|
for (let i = 0; i < windows.length; i++) {
|
2018-11-19 11:28:28 +00:00
|
|
|
if (this._isOverviewWindow(windows[i]))
|
2013-03-10 18:42:47 +00:00
|
|
|
this._addWindowClone(windows[i], true);
|
2008-12-22 21:51:34 +00:00
|
|
|
}
|
2008-12-22 22:06:47 +00:00
|
|
|
|
2009-02-04 14:50:50 +00:00
|
|
|
// Track window changes
|
2011-03-03 21:33:27 +00:00
|
|
|
if (this.metaWorkspace) {
|
|
|
|
this._windowAddedId = this.metaWorkspace.connect('window-added',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._windowAdded.bind(this));
|
2011-03-03 21:33:27 +00:00
|
|
|
this._windowRemovedId = this.metaWorkspace.connect('window-removed',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._windowRemoved.bind(this));
|
2011-03-03 21:33:27 +00:00
|
|
|
}
|
2018-01-03 07:55:38 +00:00
|
|
|
this._windowEnteredMonitorId = global.display.connect('window-entered-monitor',
|
|
|
|
this._windowEnteredMonitor.bind(this));
|
|
|
|
this._windowLeftMonitorId = global.display.connect('window-left-monitor',
|
|
|
|
this._windowLeftMonitor.bind(this));
|
2010-02-28 06:56:04 +00:00
|
|
|
this._repositionWindowsId = 0;
|
2009-02-04 14:50:50 +00:00
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
this.leavingOverview = false;
|
2012-08-08 17:16:28 +00:00
|
|
|
|
|
|
|
this._positionWindowsFlags = 0;
|
|
|
|
this._positionWindowsId = 0;
|
2019-09-10 05:42:48 +00:00
|
|
|
}
|
2014-05-08 17:16:10 +00:00
|
|
|
|
2019-09-10 05:42:48 +00:00
|
|
|
vfunc_map() {
|
|
|
|
super.vfunc_map();
|
|
|
|
this._syncActualGeometry();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2008-12-22 22:06:47 +00:00
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
vfunc_get_focus_chain() {
|
|
|
|
return this.get_children().filter(c => c.visible).sort((a, b) => {
|
2020-06-08 07:23:08 +00:00
|
|
|
if (a instanceof WindowPreview && b instanceof WindowPreview)
|
2019-07-16 09:24:13 +00:00
|
|
|
return a.slotId - b.slotId;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setFullGeometry(geom) {
|
2013-09-11 14:41:54 +00:00
|
|
|
if (rectEqual(this._fullGeometry, geom))
|
|
|
|
return;
|
|
|
|
|
2013-02-25 23:25:27 +00:00
|
|
|
this._fullGeometry = geom;
|
2014-05-08 17:16:10 +00:00
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
if (this.mapped)
|
2014-05-08 17:16:10 +00:00
|
|
|
this._recalculateWindowPositions(WindowPositionFlags.NONE);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-02-25 23:34:17 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setActualGeometry(geom) {
|
2013-09-11 14:41:54 +00:00
|
|
|
if (rectEqual(this._actualGeometry, geom))
|
|
|
|
return;
|
|
|
|
|
2013-02-25 23:34:17 +00:00
|
|
|
this._actualGeometry = geom;
|
2014-05-08 17:16:10 +00:00
|
|
|
this._actualGeometryDirty = true;
|
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
if (this.mapped)
|
2014-05-08 17:16:10 +00:00
|
|
|
this._syncActualGeometry();
|
2017-10-31 01:19:44 +00: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 16:04:03 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_syncActualGeometry() {
|
2014-05-08 17:16:10 +00:00
|
|
|
if (this._actualGeometryLater || !this._actualGeometryDirty)
|
|
|
|
return;
|
|
|
|
if (!this._actualGeometry)
|
2013-05-22 17:27:17 +00:00
|
|
|
return;
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
this._actualGeometryLater = Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
|
2014-05-08 17:16:10 +00:00
|
|
|
this._actualGeometryLater = 0;
|
2019-07-16 09:24:13 +00:00
|
|
|
if (!this.mapped)
|
2014-05-08 17:16:10 +00:00
|
|
|
return false;
|
|
|
|
|
2013-05-22 17:27:17 +00:00
|
|
|
let geom = this._actualGeometry;
|
|
|
|
|
2013-02-25 22:05:51 +00:00
|
|
|
this._dropRect.set_position(geom.x, geom.y);
|
|
|
|
this._dropRect.set_size(geom.width, geom.height);
|
2013-06-26 09:12:35 +00:00
|
|
|
this._updateWindowPositions(Main.overview.animationInProgress ? WindowPositionFlags.ANIMATE : WindowPositionFlags.NONE);
|
2013-05-22 17:27:17 +00:00
|
|
|
|
2012-08-08 17:16:28 +00:00
|
|
|
return false;
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-10-31 01:19:44 +00: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 16:04:03 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_lookupIndex(metaWindow) {
|
2018-11-19 11:28:29 +00:00
|
|
|
return this._windows.findIndex(w => w.metaWindow == metaWindow);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-07-31 21:20:26 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
containsMetaWindow(metaWindow) {
|
2009-09-01 18:15:29 +00:00
|
|
|
return this._lookupIndex(metaWindow) >= 0;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-09-01 18:15:29 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
isEmpty() {
|
2011-01-21 18:47:54 +00:00
|
|
|
return this._windows.length == 0;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-01-21 18:47:54 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
setReservedSlot(metaWindow) {
|
2014-09-03 14:03:24 +00:00
|
|
|
if (this._reservedSlotWindow == metaWindow)
|
2011-02-10 00:42:01 +00:00
|
|
|
return;
|
|
|
|
|
2014-09-03 14:03:24 +00:00
|
|
|
if (!metaWindow || this.containsMetaWindow(metaWindow)) {
|
|
|
|
this._reservedSlotWindow = null;
|
|
|
|
this._reservedSlot = null;
|
|
|
|
} else {
|
|
|
|
this._reservedSlotWindow = metaWindow;
|
|
|
|
this._reservedSlot = this._windows[this._lookupIndex(metaWindow)];
|
|
|
|
}
|
2012-08-24 02:33:35 +00:00
|
|
|
|
2013-02-26 03:43:36 +00:00
|
|
|
this._recalculateWindowPositions(WindowPositionFlags.ANIMATE);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-03-16 15:51:24 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_recalculateWindowPositions(flags) {
|
2012-08-08 17:16:28 +00:00
|
|
|
this._positionWindowsFlags |= flags;
|
|
|
|
|
|
|
|
if (this._positionWindowsId > 0)
|
|
|
|
return;
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
this._positionWindowsId = Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
|
2013-02-26 03:43:36 +00:00
|
|
|
this._realRecalculateWindowPositions(this._positionWindowsFlags);
|
2012-08-08 17:16:28 +00:00
|
|
|
this._positionWindowsFlags = 0;
|
|
|
|
this._positionWindowsId = 0;
|
|
|
|
return false;
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:16:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_realRecalculateWindowPositions(flags) {
|
2010-02-28 06:56:04 +00:00
|
|
|
if (this._repositionWindowsId > 0) {
|
2019-08-19 18:50:33 +00:00
|
|
|
GLib.source_remove(this._repositionWindowsId);
|
2010-02-28 06:56:04 +00:00
|
|
|
this._repositionWindowsId = 0;
|
|
|
|
}
|
|
|
|
|
2011-02-12 19:03:44 +00:00
|
|
|
let clones = this._windows.slice();
|
2013-02-26 00:42:19 +00:00
|
|
|
if (clones.length == 0)
|
|
|
|
return;
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
clones.sort((a, b) => {
|
2012-08-08 17:27:46 +00:00
|
|
|
return a.metaWindow.get_stable_sequence() - b.metaWindow.get_stable_sequence();
|
|
|
|
});
|
|
|
|
|
2010-03-16 15:51:24 +00:00
|
|
|
if (this._reservedSlot)
|
2011-02-12 19:03:44 +00:00
|
|
|
clones.push(this._reservedSlot);
|
2009-09-01 18:15:29 +00:00
|
|
|
|
2013-02-26 03:43:36 +00:00
|
|
|
this._currentLayout = this._computeLayout(clones);
|
|
|
|
this._updateWindowPositions(flags);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2013-02-26 03:43:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateWindowPositions(flags) {
|
2013-04-22 22:14:02 +00:00
|
|
|
if (this._currentLayout == null) {
|
|
|
|
this._recalculateWindowPositions(flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:06:08 +00:00
|
|
|
// We will reposition windows anyway when enter again overview or when ending the windows
|
2019-05-15 19:32:29 +00:00
|
|
|
// animations with fade animation.
|
2014-07-07 15:26:37 +00:00
|
|
|
// In this way we avoid unwanted animations of windows repositioning while
|
2014-07-14 17:06:08 +00:00
|
|
|
// animating overview.
|
|
|
|
if (this.leavingOverview || this._animatingWindowsFade)
|
2014-07-07 15:26:37 +00:00
|
|
|
return;
|
|
|
|
|
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 16:04:03 +00:00
|
|
|
let initialPositioning = flags & WindowPositionFlags.INITIAL;
|
2010-01-22 02:33:48 +00:00
|
|
|
let animate = flags & WindowPositionFlags.ANIMATE;
|
|
|
|
|
2013-02-26 03:43:36 +00:00
|
|
|
let layout = this._currentLayout;
|
2013-02-26 03:41:40 +00:00
|
|
|
let strategy = layout.strategy;
|
|
|
|
|
|
|
|
let [, , padding] = this._getSpacingAndPadding();
|
2013-02-25 23:34:17 +00:00
|
|
|
let area = padArea(this._actualGeometry, padding);
|
2013-02-26 03:41:40 +00:00
|
|
|
let slots = strategy.computeWindowSlots(layout, area);
|
2009-01-23 19:21:20 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
let currentWorkspace = workspaceManager.get_active_workspace();
|
2011-03-03 21:33:27 +00:00
|
|
|
let isOnCurrentWorkspace = this.metaWorkspace == null || this.metaWorkspace == currentWorkspace;
|
2010-12-16 19:21:12 +00:00
|
|
|
|
2013-02-17 11:12:55 +00:00
|
|
|
for (let i = 0; i < slots.length; i++) {
|
2009-09-18 19:08:56 +00:00
|
|
|
let slot = slots[i];
|
2019-09-01 09:49:58 +00:00
|
|
|
const [x, y, cellWidth, cellHeight, clone] = slot;
|
2018-11-19 11:28:28 +00:00
|
|
|
|
2012-10-19 16:38:20 +00:00
|
|
|
clone.slotId = i;
|
2009-09-01 18:15:29 +00:00
|
|
|
|
2010-03-19 20:46:08 +00:00
|
|
|
// Positioning a window currently being dragged must be avoided;
|
|
|
|
// we'll just leave a blank spot in the layout for it.
|
|
|
|
if (clone.inDrag)
|
|
|
|
continue;
|
|
|
|
|
2019-09-01 09:49:58 +00:00
|
|
|
const cloneWidth = cellWidth;
|
|
|
|
const cloneHeight = cellHeight;
|
2009-01-23 19:21:20 +00:00
|
|
|
|
2013-03-10 18:42:47 +00:00
|
|
|
if (!clone.positioned) {
|
|
|
|
// This window appeared after the overview was already up
|
|
|
|
// Grow the clone from the center of the slot
|
2020-05-30 13:23:41 +00:00
|
|
|
clone.x = x + cloneWidth / 2;
|
|
|
|
clone.y = y + cloneHeight / 2;
|
2019-09-01 09:49:58 +00:00
|
|
|
clone.width = 0;
|
|
|
|
clone.height = 0;
|
2013-03-10 18:42:47 +00:00
|
|
|
clone.positioned = true;
|
|
|
|
}
|
|
|
|
|
2010-12-16 19:21:12 +00:00
|
|
|
if (animate && isOnCurrentWorkspace) {
|
2018-11-19 11:28:28 +00:00
|
|
|
if (!clone.metaWindow.showing_on_its_workspace()) {
|
2010-01-23 07:37:34 +00:00
|
|
|
/* Hidden windows should fade in and grow
|
|
|
|
* therefore we need to resize them now so they
|
|
|
|
* can be scaled up later */
|
2012-08-08 17:21:20 +00:00
|
|
|
if (initialPositioning) {
|
2018-11-14 18:26:33 +00:00
|
|
|
clone.opacity = 0;
|
2020-05-30 13:23:41 +00:00
|
|
|
clone.x = x;
|
|
|
|
clone.y = y;
|
2019-09-01 09:49:58 +00:00
|
|
|
clone.width = cloneWidth;
|
|
|
|
clone.height = cloneHeight;
|
2012-08-08 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 19:46:19 +00:00
|
|
|
clone.ease({
|
|
|
|
opacity: 255,
|
|
|
|
mode: Clutter.AnimationMode.EASE_IN_QUAD,
|
2019-08-20 21:43:54 +00:00
|
|
|
duration: Overview.ANIMATION_TIME,
|
2018-07-20 19:46:19 +00:00
|
|
|
});
|
2010-01-23 07:37:34 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 11:56:03 +00:00
|
|
|
this._animateClone(clone, x, y, cloneWidth, cloneHeight);
|
2010-01-22 02:33:48 +00:00
|
|
|
} else {
|
2012-08-08 17:27:46 +00:00
|
|
|
// cancel any active tweens (otherwise they might override our changes)
|
2018-07-20 19:46:19 +00:00
|
|
|
clone.remove_all_transitions();
|
2020-05-30 13:23:41 +00:00
|
|
|
clone.set_position(x, y);
|
2019-09-01 09:49:58 +00:00
|
|
|
clone.set_size(cloneWidth, cloneHeight);
|
2018-11-14 18:26:33 +00:00
|
|
|
clone.set_opacity(255);
|
2010-01-22 02:33:48 +00:00
|
|
|
}
|
2009-01-23 19:21:20 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-01-23 19:21:20 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
syncStacking(stackIndices) {
|
2011-02-12 19:03:44 +00:00
|
|
|
let clones = this._windows.slice();
|
2017-10-31 00:38:18 +00:00
|
|
|
clones.sort((a, b) => {
|
|
|
|
let indexA = stackIndices[a.metaWindow.get_stable_sequence()];
|
|
|
|
let indexB = stackIndices[b.metaWindow.get_stable_sequence()];
|
|
|
|
return indexA - indexB;
|
|
|
|
});
|
2009-09-28 23:48:03 +00:00
|
|
|
|
2011-02-12 19:03:44 +00:00
|
|
|
for (let i = 0; i < clones.length; i++) {
|
|
|
|
let clone = clones[i];
|
2009-09-28 23:48:03 +00:00
|
|
|
if (i == 0) {
|
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 16:04:03 +00:00
|
|
|
clone.setStackAbove(this._dropRect);
|
2009-09-28 23:48:03 +00:00
|
|
|
} else {
|
2011-02-12 19:03:44 +00:00
|
|
|
let previousClone = clones[i - 1];
|
2018-11-14 18:26:33 +00:00
|
|
|
clone.setStackAbove(previousClone);
|
2009-09-28 23:48:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-09-28 23:48:03 +00:00
|
|
|
|
2020-06-02 11:56:03 +00:00
|
|
|
_animateClone(clone, x, y, width, height) {
|
2018-07-20 19:46:19 +00:00
|
|
|
clone.ease({
|
2020-05-30 13:23:41 +00:00
|
|
|
x, y,
|
2019-09-01 09:49:58 +00:00
|
|
|
width, height,
|
2018-07-20 19:46:19 +00:00
|
|
|
duration: Overview.ANIMATION_TIME,
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-11-22 03:51:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_delayedWindowRepositioning() {
|
2019-02-01 13:41:55 +00:00
|
|
|
let [x, y] = global.get_pointer();
|
2010-02-28 06:56:04 +00:00
|
|
|
|
2019-08-19 19:38:51 +00:00
|
|
|
let pointerHasMoved = this._cursorX != x && this._cursorY != y;
|
|
|
|
let inWorkspace = this._fullGeometry.x < x && x < this._fullGeometry.x + this._fullGeometry.width &&
|
|
|
|
this._fullGeometry.y < y && y < this._fullGeometry.y + this._fullGeometry.height;
|
2010-02-28 06:56:04 +00:00
|
|
|
|
|
|
|
if (pointerHasMoved && inWorkspace) {
|
|
|
|
// store current cursor position
|
|
|
|
this._cursorX = x;
|
|
|
|
this._cursorY = y;
|
2013-11-29 00:45:39 +00:00
|
|
|
return GLib.SOURCE_CONTINUE;
|
2010-02-28 06:56:04 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 09:58:00 +00:00
|
|
|
let actorUnderPointer = global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE, x, y);
|
|
|
|
for (let i = 0; i < this._windows.length; i++) {
|
2018-11-14 18:26:33 +00:00
|
|
|
if (this._windows[i] == actorUnderPointer)
|
2013-11-29 00:45:39 +00:00
|
|
|
return GLib.SOURCE_CONTINUE;
|
2012-01-08 09:58:00 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 03:43:36 +00:00
|
|
|
this._recalculateWindowPositions(WindowPositionFlags.ANIMATE);
|
2013-11-08 03:48:51 +00:00
|
|
|
this._repositionWindowsId = 0;
|
2013-11-29 00:45:39 +00:00
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-02-28 06:56:04 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_doRemoveWindow(metaWin) {
|
2009-02-04 14:50:50 +00:00
|
|
|
let win = metaWin.get_compositor_private();
|
|
|
|
|
2018-07-09 09:50:25 +00:00
|
|
|
let clone = this._removeWindowClone(metaWin);
|
|
|
|
|
|
|
|
if (clone) {
|
|
|
|
// If metaWin.get_compositor_private() returned non-NULL, that
|
|
|
|
// means the window still exists (and is just being moved to
|
|
|
|
// another workspace or something), so set its overviewHint
|
|
|
|
// accordingly. (If it returned NULL, then the window is being
|
|
|
|
// destroyed; we'd like to animate this, but it's too late at
|
|
|
|
// this point.)
|
|
|
|
if (win) {
|
2018-11-14 18:26:33 +00:00
|
|
|
let [stageX, stageY] = clone.get_transformed_position();
|
2019-09-01 09:49:58 +00:00
|
|
|
const [transformedWidth, transformedHeight] =
|
|
|
|
clone.get_transformed_size();
|
|
|
|
|
2018-07-09 09:50:25 +00:00
|
|
|
win._overviewHint = {
|
|
|
|
x: stageX,
|
|
|
|
y: stageY,
|
2019-09-01 09:49:58 +00:00
|
|
|
width: transformedWidth,
|
|
|
|
height: transformedHeight,
|
2018-07-09 09:50:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
clone.destroy();
|
2009-02-04 14:50:50 +00:00
|
|
|
}
|
2010-02-28 06:56:04 +00: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
|
|
|
|
|
|
|
|
// remove old handler
|
|
|
|
if (this._repositionWindowsId > 0) {
|
2019-08-19 18:50:33 +00:00
|
|
|
GLib.source_remove(this._repositionWindowsId);
|
2010-02-28 06:56:04 +00:00
|
|
|
this._repositionWindowsId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup new handler
|
2019-02-01 13:41:55 +00:00
|
|
|
let [x, y] = global.get_pointer();
|
2010-02-28 06:56:04 +00:00
|
|
|
this._cursorX = x;
|
|
|
|
this._cursorY = y;
|
|
|
|
|
2013-04-22 22:20:11 +00:00
|
|
|
this._currentLayout = null;
|
2019-08-19 18:50:33 +00:00
|
|
|
this._repositionWindowsId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, WINDOW_REPOSITIONING_DELAY,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._delayedWindowRepositioning.bind(this));
|
2014-04-10 17:26:52 +00:00
|
|
|
GLib.Source.set_name_by_id(this._repositionWindowsId, '[gnome-shell] this._delayedWindowRepositioning');
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-01-23 19:21:20 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_doAddWindow(metaWin) {
|
2009-08-11 11:46:10 +00:00
|
|
|
if (this.leavingOverview)
|
2009-03-17 22:22:25 +00:00
|
|
|
return;
|
|
|
|
|
2009-02-04 14:50:50 +00: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 18:50:33 +00:00
|
|
|
let id = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
2019-07-16 09:24:13 +00:00
|
|
|
if (metaWin.get_compositor_private() &&
|
2017-10-31 00:38:18 +00:00
|
|
|
metaWin.get_workspace() == this.metaWorkspace)
|
|
|
|
this._doAddWindow(metaWin);
|
|
|
|
return GLib.SOURCE_REMOVE;
|
|
|
|
});
|
2014-04-10 17:26:52 +00:00
|
|
|
GLib.Source.set_name_by_id(id, '[gnome-shell] this._doAddWindow');
|
2009-02-04 14:50:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-22 02:33:48 +00:00
|
|
|
|
2011-03-01 08:14:56 +00: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 11:28:28 +00:00
|
|
|
if (this._lookupIndex(metaWin) != -1)
|
2011-03-01 08:14:56 +00:00
|
|
|
return;
|
|
|
|
|
2012-08-29 22:51:53 +00:00
|
|
|
if (!this._isMyWindow(win))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!this._isOverviewWindow(win)) {
|
2018-06-19 10:45:18 +00:00
|
|
|
if (metaWin.get_transient_for() == null)
|
|
|
|
return;
|
2012-08-29 22:51:53 +00:00
|
|
|
|
2018-06-19 10:45:18 +00: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 22:51:53 +00:00
|
|
|
|
2010-01-22 02:33:48 +00:00
|
|
|
return;
|
2012-08-29 22:51:53 +00:00
|
|
|
}
|
2009-02-04 14:50:50 +00:00
|
|
|
|
2020-06-02 11:56:03 +00:00
|
|
|
let clone = this._addWindowClone(win, false);
|
2009-02-04 14:50:50 +00:00
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
if (win._overviewHint) {
|
2019-07-16 09:24:13 +00:00
|
|
|
let x = win._overviewHint.x - this.x;
|
|
|
|
let y = win._overviewHint.y - this.y;
|
2019-09-01 09:49:58 +00:00
|
|
|
const width = win._overviewHint.width;
|
|
|
|
const height = win._overviewHint.height;
|
2009-08-11 11:46:10 +00:00
|
|
|
delete win._overviewHint;
|
2009-02-04 14:50:50 +00:00
|
|
|
|
2013-03-10 18:42:47 +00:00
|
|
|
clone.positioned = true;
|
2018-11-19 11:28:28 +00:00
|
|
|
|
2020-05-30 13:23:41 +00:00
|
|
|
clone.set_position(x, y);
|
2019-09-01 09:49:58 +00:00
|
|
|
clone.set_size(width, height);
|
2009-02-04 14:50:50 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 22:20:11 +00:00
|
|
|
this._currentLayout = null;
|
2013-02-26 03:43:36 +00:00
|
|
|
this._recalculateWindowPositions(WindowPositionFlags.ANIMATE);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-01-23 19:21:20 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_windowAdded(metaWorkspace, metaWin) {
|
2011-03-01 08:14:56 +00:00
|
|
|
this._doAddWindow(metaWin);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-03-01 08:14:56 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_windowRemoved(metaWorkspace, metaWin) {
|
2011-03-01 08:14:56 +00:00
|
|
|
this._doRemoveWindow(metaWin);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-03-01 08:14:56 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
_windowEnteredMonitor(metaDisplay, monitorIndex, metaWin) {
|
2019-08-20 00:51:42 +00:00
|
|
|
if (monitorIndex == this.monitorIndex)
|
2011-03-01 08:14:56 +00:00
|
|
|
this._doAddWindow(metaWin);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-03-01 08:14:56 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
_windowLeftMonitor(metaDisplay, monitorIndex, metaWin) {
|
2019-08-20 00:51:42 +00:00
|
|
|
if (monitorIndex == this.monitorIndex)
|
2011-03-01 08:14:56 +00:00
|
|
|
this._doRemoveWindow(metaWin);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-03-01 08:14:56 +00:00
|
|
|
|
2010-01-06 03:53:36 +00:00
|
|
|
// check for maximized windows on the workspace
|
2017-10-31 00:03:21 +00:00
|
|
|
hasMaximizedWindows() {
|
2010-07-15 14:21:32 +00:00
|
|
|
for (let i = 0; i < this._windows.length; i++) {
|
2010-01-06 03:53:36 +00: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-31 01:19:44 +00:00
|
|
|
}
|
2010-01-06 03:53:36 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
fadeToOverview() {
|
2014-07-14 17:06:08 +00:00
|
|
|
// We don't want to reposition windows while animating in this way.
|
|
|
|
this._animatingWindowsFade = true;
|
2017-12-02 00:27:35 +00:00
|
|
|
this._overviewShownId = Main.overview.connect('shown', this._doneShowingOverview.bind(this));
|
2014-07-14 17:06:08 +00:00
|
|
|
if (this._windows.length == 0)
|
|
|
|
return;
|
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
let activeWorkspace = workspaceManager.get_active_workspace();
|
|
|
|
if (this.metaWorkspace != null && this.metaWorkspace != activeWorkspace)
|
2014-07-14 17:06:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Special case maximized windows, since it doesn't make sense
|
|
|
|
// to animate windows below in the stack
|
|
|
|
let topMaximizedWindow;
|
|
|
|
// It is ok to treat the case where there is no maximized
|
|
|
|
// window as if the bottom-most window was maximized given that
|
|
|
|
// it won't affect the result of the animation
|
|
|
|
for (topMaximizedWindow = this._windows.length - 1; topMaximizedWindow > 0; topMaximizedWindow--) {
|
|
|
|
let metaWindow = this._windows[topMaximizedWindow].metaWindow;
|
|
|
|
if (metaWindow.maximized_horizontally && metaWindow.maximized_vertically)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
let nTimeSlots = Math.min(WINDOW_ANIMATION_MAX_NUMBER_BLENDING + 1, this._windows.length - topMaximizedWindow);
|
|
|
|
let windowBaseTime = Overview.ANIMATION_TIME / nTimeSlots;
|
|
|
|
|
|
|
|
let topIndex = this._windows.length - 1;
|
|
|
|
for (let i = 0; i < this._windows.length; i++) {
|
|
|
|
if (i < topMaximizedWindow) {
|
|
|
|
// below top-most maximized window, don't animate
|
2020-06-02 11:56:03 +00:00
|
|
|
this._windows[i].hideOverlay(false);
|
2018-11-14 18:26:33 +00:00
|
|
|
this._windows[i].opacity = 0;
|
2014-07-14 17:06:08 +00:00
|
|
|
} else {
|
|
|
|
let fromTop = topIndex - i;
|
|
|
|
let time;
|
|
|
|
if (fromTop < nTimeSlots) // animate top-most windows gradually
|
|
|
|
time = windowBaseTime * (nTimeSlots - fromTop);
|
|
|
|
else
|
|
|
|
time = windowBaseTime;
|
|
|
|
|
2018-11-14 18:26:33 +00:00
|
|
|
this._windows[i].opacity = 255;
|
2014-07-14 17:06:08 +00:00
|
|
|
this._fadeWindow(i, time, 0);
|
|
|
|
}
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-07-14 17:06:08 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
fadeFromOverview() {
|
2014-07-14 17:06:08 +00:00
|
|
|
this.leavingOverview = true;
|
2017-12-02 00:27:35 +00:00
|
|
|
this._overviewHiddenId = Main.overview.connect('hidden', this._doneLeavingOverview.bind(this));
|
2014-07-14 17:06:08 +00:00
|
|
|
if (this._windows.length == 0)
|
|
|
|
return;
|
|
|
|
|
2018-07-20 19:46:19 +00:00
|
|
|
for (let i = 0; i < this._windows.length; i++)
|
|
|
|
this._windows[i].remove_all_transitions();
|
2014-07-14 17:06:08 +00:00
|
|
|
|
|
|
|
if (this._repositionWindowsId > 0) {
|
2019-08-19 18:50:33 +00:00
|
|
|
GLib.source_remove(this._repositionWindowsId);
|
2014-07-14 17:06:08 +00:00
|
|
|
this._repositionWindowsId = 0;
|
|
|
|
}
|
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
let activeWorkspace = workspaceManager.get_active_workspace();
|
|
|
|
if (this.metaWorkspace != null && this.metaWorkspace != activeWorkspace)
|
2014-07-14 17:06:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Special case maximized windows, since it doesn't make sense
|
|
|
|
// to animate windows below in the stack
|
|
|
|
let topMaximizedWindow;
|
|
|
|
// It is ok to treat the case where there is no maximized
|
|
|
|
// window as if the bottom-most window was maximized given that
|
|
|
|
// it won't affect the result of the animation
|
|
|
|
for (topMaximizedWindow = this._windows.length - 1; topMaximizedWindow > 0; topMaximizedWindow--) {
|
|
|
|
let metaWindow = this._windows[topMaximizedWindow].metaWindow;
|
|
|
|
if (metaWindow.maximized_horizontally && metaWindow.maximized_vertically)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
let nTimeSlots = Math.min(WINDOW_ANIMATION_MAX_NUMBER_BLENDING + 1, this._windows.length - topMaximizedWindow);
|
|
|
|
let windowBaseTime = Overview.ANIMATION_TIME / nTimeSlots;
|
|
|
|
|
|
|
|
let topIndex = this._windows.length - 1;
|
|
|
|
for (let i = 0; i < this._windows.length; i++) {
|
|
|
|
if (i < topMaximizedWindow) {
|
|
|
|
// below top-most maximized window, don't animate
|
2020-06-02 11:56:03 +00:00
|
|
|
this._windows[i].hideOverlay(false);
|
2018-11-14 18:26:33 +00:00
|
|
|
this._windows[i].opacity = 0;
|
2014-07-14 17:06:08 +00:00
|
|
|
} else {
|
|
|
|
let fromTop = topIndex - i;
|
|
|
|
let time;
|
|
|
|
if (fromTop < nTimeSlots) // animate top-most windows gradually
|
|
|
|
time = windowBaseTime * (fromTop + 1);
|
|
|
|
else
|
|
|
|
time = windowBaseTime * nTimeSlots;
|
|
|
|
|
2018-11-14 18:26:33 +00:00
|
|
|
this._windows[i].opacity = 0;
|
2014-07-14 17:06:08 +00:00
|
|
|
this._fadeWindow(i, time, 255);
|
|
|
|
}
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-07-14 17:06:08 +00:00
|
|
|
|
2018-07-20 19:46:19 +00:00
|
|
|
_fadeWindow(index, duration, opacity) {
|
2014-07-14 17:06:08 +00:00
|
|
|
let clone = this._windows[index];
|
2020-06-02 11:56:03 +00:00
|
|
|
clone.hideOverlay(false);
|
2014-07-14 17:06:08 +00:00
|
|
|
|
|
|
|
if (clone.metaWindow.showing_on_its_workspace()) {
|
2020-05-31 21:19:59 +00:00
|
|
|
clone.x = clone.boundingBox.x;
|
|
|
|
clone.y = clone.boundingBox.y;
|
2019-09-01 09:49:58 +00:00
|
|
|
clone.width = clone.boundingBox.width;
|
|
|
|
clone.height = clone.boundingBox.height;
|
2018-07-20 19:46:19 +00:00
|
|
|
clone.ease({
|
|
|
|
opacity,
|
|
|
|
duration,
|
2019-08-20 21:43:54 +00:00
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2018-07-20 19:46:19 +00:00
|
|
|
});
|
2014-07-14 17:06:08 +00:00
|
|
|
} else {
|
|
|
|
// The window is hidden
|
2018-11-14 18:26:33 +00:00
|
|
|
clone.opacity = 0;
|
2014-07-14 17:06:08 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-07-14 17:06:08 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
zoomToOverview() {
|
2009-08-10 22:31:39 +00:00
|
|
|
// Position and scale the windows.
|
2013-02-26 03:43:36 +00:00
|
|
|
this._recalculateWindowPositions(WindowPositionFlags.ANIMATE | WindowPositionFlags.INITIAL);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
zoomFromOverview() {
|
2018-01-03 07:55:38 +00:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
let currentWorkspace = workspaceManager.get_active_workspace();
|
2010-12-16 19:21:12 +00:00
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
this.leavingOverview = true;
|
2009-07-23 21:36:41 +00:00
|
|
|
|
2018-07-20 19:46:19 +00:00
|
|
|
for (let i = 0; i < this._windows.length; i++)
|
|
|
|
this._windows[i].remove_all_transitions();
|
2009-07-23 21:36:41 +00:00
|
|
|
|
2010-03-14 14:47:42 +00:00
|
|
|
if (this._repositionWindowsId > 0) {
|
2019-08-19 18:50:33 +00:00
|
|
|
GLib.source_remove(this._repositionWindowsId);
|
2010-03-14 14:47:42 +00:00
|
|
|
this._repositionWindowsId = 0;
|
|
|
|
}
|
2017-12-02 00:27:35 +00:00
|
|
|
this._overviewHiddenId = Main.overview.connect('hidden', this._doneLeavingOverview.bind(this));
|
2009-08-10 22:31:39 +00:00
|
|
|
|
2011-03-03 21:33:27 +00:00
|
|
|
if (this.metaWorkspace != null && this.metaWorkspace != currentWorkspace)
|
2010-12-16 19:21:12 +00:00
|
|
|
return;
|
|
|
|
|
2009-08-10 22:31:39 +00:00
|
|
|
// Position and scale the windows.
|
2014-07-14 17:06:08 +00:00
|
|
|
for (let i = 0; i < this._windows.length; i++)
|
2019-01-29 19:36:54 +00:00
|
|
|
this._zoomWindowFromOverview(i);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-01-23 07:37:34 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_zoomWindowFromOverview(index) {
|
2014-07-14 17:06:08 +00:00
|
|
|
let clone = this._windows[index];
|
2020-06-02 11:56:03 +00:00
|
|
|
clone.hideOverlay(false);
|
2014-07-14 17:06:08 +00:00
|
|
|
|
|
|
|
if (clone.metaWindow.showing_on_its_workspace()) {
|
2018-07-20 19:46:19 +00:00
|
|
|
clone.ease({
|
2020-05-31 21:19:59 +00:00
|
|
|
x: clone.boundingBox.x,
|
|
|
|
y: clone.boundingBox.y,
|
2019-09-01 09:49:58 +00:00
|
|
|
width: clone.boundingBox.width,
|
|
|
|
height: clone.boundingBox.height,
|
2018-07-20 19:46:19 +00:00
|
|
|
opacity: 255,
|
|
|
|
duration: Overview.ANIMATION_TIME,
|
2019-08-20 21:43:54 +00:00
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2018-07-20 19:46:19 +00:00
|
|
|
});
|
2014-07-14 17:06:08 +00:00
|
|
|
} else {
|
|
|
|
// The window is hidden, make it shrink and fade it out
|
2018-07-20 19:46:19 +00:00
|
|
|
clone.ease({
|
2019-09-01 09:49:58 +00:00
|
|
|
width: 0,
|
|
|
|
height: 0,
|
2018-07-20 19:46:19 +00:00
|
|
|
opacity: 0,
|
|
|
|
duration: Overview.ANIMATION_TIME,
|
2019-08-20 21:43:54 +00:00
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
|
2018-07-20 19:46:19 +00:00
|
|
|
});
|
2008-12-22 21:51:34 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2018-07-20 19:46:19 +00:00
|
|
|
_onDestroy() {
|
2010-03-17 22:23:32 +00:00
|
|
|
if (this._overviewHiddenId) {
|
|
|
|
Main.overview.disconnect(this._overviewHiddenId);
|
|
|
|
this._overviewHiddenId = 0;
|
|
|
|
}
|
2009-02-04 14:50:50 +00:00
|
|
|
|
2011-03-03 21:33:27 +00:00
|
|
|
if (this.metaWorkspace) {
|
|
|
|
this.metaWorkspace.disconnect(this._windowAddedId);
|
|
|
|
this.metaWorkspace.disconnect(this._windowRemovedId);
|
|
|
|
}
|
2018-01-03 07:55:38 +00:00
|
|
|
global.display.disconnect(this._windowEnteredMonitorId);
|
|
|
|
global.display.disconnect(this._windowLeftMonitorId);
|
2010-02-07 14:25:16 +00:00
|
|
|
|
2017-06-27 09:09:16 +00:00
|
|
|
if (this._repositionWindowsId > 0) {
|
2019-08-19 18:50:33 +00:00
|
|
|
GLib.source_remove(this._repositionWindowsId);
|
2017-06-27 09:09:16 +00:00
|
|
|
this._repositionWindowsId = 0;
|
|
|
|
}
|
2012-08-08 17:16:28 +00:00
|
|
|
|
2017-06-27 09:09:16 +00:00
|
|
|
if (this._positionWindowsId > 0) {
|
2012-08-08 17:16:28 +00:00
|
|
|
Meta.later_remove(this._positionWindowsId);
|
2017-06-27 09:09:16 +00:00
|
|
|
this._positionWindowsId = 0;
|
|
|
|
}
|
2013-09-11 00:42:11 +00:00
|
|
|
|
2017-06-27 09:09:16 +00:00
|
|
|
if (this._actualGeometryLater > 0) {
|
2013-09-11 00:42:11 +00:00
|
|
|
Meta.later_remove(this._actualGeometryLater);
|
2017-06-27 09:09:16 +00:00
|
|
|
this._actualGeometryLater = 0;
|
|
|
|
}
|
2013-09-11 00:42:11 +00:00
|
|
|
|
2010-03-17 22:23:32 +00:00
|
|
|
this._windows = [];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
// Sets this.leavingOverview flag to false.
|
2017-10-31 00:03:21 +00:00
|
|
|
_doneLeavingOverview() {
|
2009-08-11 11:46:10 +00:00
|
|
|
this.leavingOverview = false;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-03-17 22:22:25 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_doneShowingOverview() {
|
2014-07-14 17:06:08 +00:00
|
|
|
this._animatingWindowsFade = false;
|
|
|
|
this._recalculateWindowPositions(WindowPositionFlags.INITIAL);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-07-14 17:06:08 +00:00
|
|
|
|
2013-01-14 17:38:02 +00:00
|
|
|
// Tests if @actor belongs to this workspaces and monitor
|
2017-10-31 00:03:21 +00:00
|
|
|
_isMyWindow(actor) {
|
2013-01-14 17:38:02 +00:00
|
|
|
let win = actor.meta_window;
|
|
|
|
return (this.metaWorkspace == null || win.located_on_workspace(this.metaWorkspace)) &&
|
2013-01-14 17:38:02 +00:00
|
|
|
(win.get_monitor() == this.monitorIndex);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2009-08-11 11:46:10 +00:00
|
|
|
// Tests if @win should be shown in the Overview
|
2017-10-31 00:03:21 +00:00
|
|
|
_isOverviewWindow(win) {
|
2014-01-30 17:04:18 +00:00
|
|
|
return !win.get_meta_window().skip_taskbar;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2009-01-23 19:21:20 +00:00
|
|
|
// Create a clone of a (non-desktop) window and add it to the window list
|
2017-10-31 00:03:21 +00:00
|
|
|
_addWindowClone(win, positioned) {
|
2020-06-08 07:23:08 +00:00
|
|
|
let clone = new WindowPreview(win, this);
|
2013-03-10 18:42:47 +00:00
|
|
|
clone.positioned = positioned;
|
2009-11-12 00:26:52 +00:00
|
|
|
|
2009-01-29 21:21:50 +00:00
|
|
|
clone.connect('selected',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onCloneSelected.bind(this));
|
2017-10-31 00:38:18 +00:00
|
|
|
clone.connect('drag-begin', () => {
|
|
|
|
Main.overview.beginWindowDrag(clone.metaWindow);
|
|
|
|
});
|
|
|
|
clone.connect('drag-cancelled', () => {
|
|
|
|
Main.overview.cancelledWindowDrag(clone.metaWindow);
|
|
|
|
});
|
|
|
|
clone.connect('drag-end', () => {
|
|
|
|
Main.overview.endWindowDrag(clone.metaWindow);
|
|
|
|
});
|
|
|
|
clone.connect('size-changed', () => {
|
|
|
|
this._recalculateWindowPositions(WindowPositionFlags.NONE);
|
|
|
|
});
|
2020-06-02 11:56:03 +00:00
|
|
|
clone.connect('show-chrome', () => {
|
2017-10-09 22:04:56 +00:00
|
|
|
let focus = global.stage.key_focus;
|
2019-07-16 09:24:13 +00:00
|
|
|
if (focus == null || this.contains(focus))
|
2018-11-14 18:26:33 +00:00
|
|
|
clone.grab_key_focus();
|
2018-11-19 11:28:28 +00:00
|
|
|
|
2020-06-02 11:56:03 +00:00
|
|
|
this._windows.forEach(c => {
|
|
|
|
if (c !== clone)
|
|
|
|
c.hideOverlay(true);
|
2018-11-19 11:28:28 +00:00
|
|
|
});
|
2017-10-09 22:04:56 +00:00
|
|
|
});
|
2020-06-02 11:56:03 +00:00
|
|
|
clone.connect('destroy', () => {
|
|
|
|
this._removeWindowClone(clone.metaWindow);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.add_child(clone);
|
2009-11-20 00:39:00 +00:00
|
|
|
|
2013-02-20 18:33:29 +00:00
|
|
|
if (this._windows.length == 0)
|
|
|
|
clone.setStackAbove(null);
|
|
|
|
else
|
2018-11-14 18:26:33 +00:00
|
|
|
clone.setStackAbove(this._windows[this._windows.length - 1]);
|
2013-02-20 18:33:29 +00:00
|
|
|
|
2009-01-23 19:21:20 +00:00
|
|
|
this._windows.push(clone);
|
|
|
|
|
2020-06-02 11:56:03 +00:00
|
|
|
return clone;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2018-07-09 09:50:25 +00:00
|
|
|
_removeWindowClone(metaWin) {
|
|
|
|
// find the position of the window in our list
|
2018-11-19 11:28:28 +00:00
|
|
|
let index = this._lookupIndex(metaWin);
|
2018-07-09 09:50:25 +00:00
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return this._windows.splice(index, 1).pop();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-07-09 09:50:25 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_isBetterLayout(oldLayout, newLayout) {
|
2012-08-08 17:27:46 +00:00
|
|
|
if (oldLayout.scale === undefined)
|
|
|
|
return true;
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2012-08-08 17:27:46 +00:00
|
|
|
let spacePower = (newLayout.space - oldLayout.space) * LAYOUT_SPACE_WEIGHT;
|
|
|
|
let scalePower = (newLayout.scale - oldLayout.scale) * LAYOUT_SCALE_WEIGHT;
|
2009-03-31 21:40:18 +00:00
|
|
|
|
2012-08-08 17:27:46 +00:00
|
|
|
if (newLayout.scale > oldLayout.scale && newLayout.space > oldLayout.space) {
|
|
|
|
// Win win -- better scale and better space
|
|
|
|
return true;
|
|
|
|
} else if (newLayout.scale > oldLayout.scale && newLayout.space <= oldLayout.space) {
|
2019-05-15 19:32:29 +00:00
|
|
|
// Keep new layout only if scale gain outweighs aspect space loss
|
2012-08-08 17:27:46 +00:00
|
|
|
return scalePower > spacePower;
|
|
|
|
} else if (newLayout.scale <= oldLayout.scale && newLayout.space > oldLayout.space) {
|
2019-05-15 19:32:29 +00:00
|
|
|
// Keep new layout only if aspect space gain outweighs scale loss
|
2012-08-08 17:27:46 +00:00
|
|
|
return spacePower > scalePower;
|
|
|
|
} else {
|
|
|
|
// Lose -- worse scale and space
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getBestLayout(windows, area, rowSpacing, columnSpacing) {
|
2012-08-08 17:27:46 +00:00
|
|
|
// We look for the largest scale that allows us to fit the
|
|
|
|
// largest row/tallest column on the workspace.
|
|
|
|
|
|
|
|
let lastLayout = {};
|
|
|
|
|
2013-02-26 00:31:03 +00:00
|
|
|
let strategy = new UnalignedLayoutStrategy(this._monitor, rowSpacing, columnSpacing);
|
|
|
|
|
2012-08-08 17:27:46 +00:00
|
|
|
for (let numRows = 1; ; numRows++) {
|
|
|
|
let numColumns = Math.ceil(windows.length / numRows);
|
2009-03-31 21:40:18 +00:00
|
|
|
|
2012-08-08 17:27:46 +00: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)
|
|
|
|
if (numColumns == lastLayout.numColumns)
|
|
|
|
break;
|
|
|
|
|
2019-08-19 19:06:04 +00:00
|
|
|
let layout = { area, strategy, numRows, numColumns };
|
2012-08-08 17:27:46 +00:00
|
|
|
strategy.computeLayout(windows, layout);
|
|
|
|
strategy.computeScaleAndSpace(layout);
|
|
|
|
|
|
|
|
if (!this._isBetterLayout(lastLayout, layout))
|
|
|
|
break;
|
|
|
|
|
|
|
|
lastLayout = layout;
|
|
|
|
}
|
2008-12-22 21:51:34 +00:00
|
|
|
|
2012-08-08 17:27:46 +00:00
|
|
|
return lastLayout;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-01-21 20:35:20 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getSpacingAndPadding() {
|
2019-07-16 09:24:13 +00:00
|
|
|
let node = this.get_theme_node();
|
2012-08-08 17:27:46 +00:00
|
|
|
|
|
|
|
// Window grid spacing
|
|
|
|
let columnSpacing = node.get_length('-horizontal-spacing');
|
|
|
|
let rowSpacing = node.get_length('-vertical-spacing');
|
2012-12-13 18:28:25 +00:00
|
|
|
let padding = {
|
|
|
|
left: node.get_padding(St.Side.LEFT),
|
|
|
|
top: node.get_padding(St.Side.TOP),
|
|
|
|
bottom: node.get_padding(St.Side.BOTTOM),
|
|
|
|
right: node.get_padding(St.Side.RIGHT),
|
|
|
|
};
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2013-02-26 00:42:19 +00:00
|
|
|
// All of the overlays have the same chrome sizes,
|
|
|
|
// so just pick the first one.
|
2020-06-02 11:56:03 +00:00
|
|
|
let clone = this._windows[0];
|
|
|
|
let [topBorder, bottomBorder] = clone.chromeHeights();
|
|
|
|
let [leftBorder, rightBorder] = clone.chromeWidths();
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2017-06-01 14:32:45 +00:00
|
|
|
rowSpacing += (topBorder + bottomBorder) / 2;
|
2012-12-13 18:28:25 +00:00
|
|
|
columnSpacing += (rightBorder + leftBorder) / 2;
|
2017-06-01 14:32:45 +00:00
|
|
|
padding.top += topBorder;
|
|
|
|
padding.bottom += bottomBorder;
|
2012-12-13 18:28:25 +00:00
|
|
|
padding.left += leftBorder;
|
|
|
|
padding.right += rightBorder;
|
|
|
|
|
2013-02-26 03:38:30 +00:00
|
|
|
return [rowSpacing, columnSpacing, padding];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-08-08 17:27:46 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_computeLayout(windows) {
|
2013-02-26 03:38:30 +00:00
|
|
|
let [rowSpacing, columnSpacing, padding] = this._getSpacingAndPadding();
|
|
|
|
let area = padArea(this._fullGeometry, padding);
|
2013-02-26 03:41:40 +00:00
|
|
|
return this._getBestLayout(windows, area, rowSpacing, columnSpacing);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-09-18 19:08:56 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onCloneSelected(clone, time) {
|
2019-08-19 19:14:33 +00:00
|
|
|
let wsIndex;
|
2011-03-03 21:33:27 +00:00
|
|
|
if (this.metaWorkspace)
|
|
|
|
wsIndex = this.metaWorkspace.index();
|
|
|
|
Main.activateWindow(clone.metaWindow, time, wsIndex);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2008-12-22 22:06:47 +00:00
|
|
|
|
2009-02-10 16:15:59 +00:00
|
|
|
// Draggable target interface
|
2019-01-31 14:08:10 +00:00
|
|
|
handleDragOver(source, _actor, _x, _y, _time) {
|
2011-02-14 22:13:25 +00:00
|
|
|
if (source.realWindow && !this._isMyWindow(source.realWindow))
|
2010-09-10 02:00:28 +00:00
|
|
|
return DND.DragMotionResult.MOVE_DROP;
|
2019-05-02 15:04:03 +00:00
|
|
|
if (source.app && source.app.can_open_new_window())
|
2019-08-02 10:58:34 +00:00
|
|
|
return DND.DragMotionResult.COPY_DROP;
|
|
|
|
if (!source.app && source.shellWorkspaceLaunch)
|
2010-09-10 02:00:28 +00:00
|
|
|
return DND.DragMotionResult.COPY_DROP;
|
|
|
|
|
|
|
|
return DND.DragMotionResult.CONTINUE;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-09-10 02:00:28 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
acceptDrop(source, actor, x, y, time) {
|
2019-08-02 10:58:34 +00:00
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
let workspaceIndex = this.metaWorkspace
|
|
|
|
? this.metaWorkspace.index()
|
|
|
|
: workspaceManager.get_active_workspace_index();
|
|
|
|
|
2011-01-31 01:25:00 +00:00
|
|
|
if (source.realWindow) {
|
2009-02-10 16:15:59 +00:00
|
|
|
let win = source.realWindow;
|
|
|
|
if (this._isMyWindow(win))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Set a hint on the Mutter.Window so its initial position
|
|
|
|
// in the new workspace will be correct
|
2009-08-11 11:46:10 +00:00
|
|
|
win._overviewHint = {
|
2009-02-10 16:15:59 +00:00
|
|
|
x: actor.x,
|
|
|
|
y: actor.y,
|
2019-09-01 09:49:58 +00:00
|
|
|
width: actor.width,
|
|
|
|
heigth: actor.height,
|
2009-02-10 16:15:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let metaWindow = win.get_meta_window();
|
2011-03-03 21:33:27 +00: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
|
|
|
|
if (metaWindow.get_monitor() != this.monitorIndex)
|
2011-03-17 17:48:09 +00:00
|
|
|
metaWindow.move_to_monitor(this.monitorIndex);
|
2011-03-03 21:33:27 +00:00
|
|
|
|
2019-08-02 10:58:34 +00:00
|
|
|
metaWindow.change_workspace_by_index(workspaceIndex, false);
|
|
|
|
return true;
|
2019-05-02 15:04:03 +00:00
|
|
|
} else if (source.app && source.app.can_open_new_window()) {
|
2019-09-15 09:45:47 +00:00
|
|
|
if (source.animateLaunchAtPos)
|
|
|
|
source.animateLaunchAtPos(actor.x, actor.y);
|
|
|
|
|
2019-08-02 10:58:34 +00:00
|
|
|
source.app.open_new_window(workspaceIndex);
|
2009-02-10 16:15:59 +00:00
|
|
|
return true;
|
2019-08-02 10:58:34 +00: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 21:09:58 +00:00
|
|
|
timestamp: time });
|
2009-02-10 16:15:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2008-12-22 21:51:34 +00:00
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
});
|