From 85d2837466f549a772fdbebe28a6cdc789b88b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Mon, 1 Jun 2020 14:36:08 +0200 Subject: [PATCH] workspace: Allow allocating smaller sizes for window clones Change the preferred size functions of the layout manager of window clones to allow allocating smaller sizes, too. Also scale down the allocation sizes of the ClutterClones our allocate implementation so the ClutterClones will scale their texture accordingly. This will enable us to position the window clones using their allocation size instead of their scale, which is necessary when introducing a new ClutterLayoutManager that positions the window clones. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1294 --- js/ui/workspace.js | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/js/ui/workspace.js b/js/ui/workspace.js index 0830e29fb..960514911 100644 --- a/js/ui/workspace.js +++ b/js/ui/workspace.js @@ -51,35 +51,22 @@ class WindowCloneLayout extends Clutter.LayoutManager { this.layout_changed(); } - _makeBoxForWindow(window) { - // We need to adjust the position of the actor because of the - // consequences of invisible borders -- in reality, the texture - // has an extra set of "padding" around it that we need to trim - // down. - - // The bounding box is based on the (visible) frame rect, while - // the buffer rect contains everything, including the invisible - // border padding. - let bufferRect = window.get_buffer_rect(); - - let box = new Clutter.ActorBox(); - - box.set_origin(bufferRect.x - this._boundingBox.x, - bufferRect.y - this._boundingBox.y); - box.set_size(bufferRect.width, bufferRect.height); - - return box; - } - vfunc_get_preferred_height(_container, _forWidth) { - return [this._boundingBox.height, this._boundingBox.height]; + return [0, this._boundingBox.height]; } vfunc_get_preferred_width(_container, _forHeight) { - return [this._boundingBox.width, this._boundingBox.width]; + return [0, this._boundingBox.width]; } - vfunc_allocate(container, _box) { + 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. + const scaleX = box.get_width() / this._boundingBox.width; + const scaleY = box.get_height() / this._boundingBox.height; + + const childBox = new Clutter.ActorBox(); + container.get_children().forEach(child => { let realWindow; if (child == container._windowClone) @@ -87,7 +74,20 @@ class WindowCloneLayout extends Clutter.LayoutManager { else realWindow = child.source; - child.allocate(this._makeBoxForWindow(realWindow.meta_window)); + const bufferRect = realWindow.meta_window.get_buffer_rect(); + childBox.set_origin( + bufferRect.x - this._boundingBox.x, + bufferRect.y - this._boundingBox.y); + + 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); }); } });