overviewControls: Subclass layout manager directly

All the ControlsManagerLayout uses from BoxLayout is the spacing
property, both size requests and allocation are completely custom.

That makes subclassing really questionable, so stop doing that
and just hook up to the `spacing` style property manually.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3104>
This commit is contained in:
Florian Müllner 2024-01-10 12:02:10 +01:00 committed by Marge Bot
parent 64b7249405
commit 812270fee3

View File

@ -34,10 +34,10 @@ export const ControlsState = {
}; };
const ControlsManagerLayout = GObject.registerClass( const ControlsManagerLayout = GObject.registerClass(
class ControlsManagerLayout extends Clutter.BoxLayout { class ControlsManagerLayout extends Clutter.LayoutManager {
_init(searchEntry, appDisplay, workspacesDisplay, workspacesThumbnails, _init(searchEntry, appDisplay, workspacesDisplay, workspacesThumbnails,
searchController, dash, stateAdjustment) { searchController, dash, stateAdjustment) {
super._init({orientation: Clutter.Orientation.VERTICAL}); super._init();
this._appDisplay = appDisplay; this._appDisplay = appDisplay;
this._workspacesDisplay = workspacesDisplay; this._workspacesDisplay = workspacesDisplay;
@ -47,6 +47,8 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
this._searchController = searchController; this._searchController = searchController;
this._dash = dash; this._dash = dash;
this._spacing = 0;
this._cachedWorkspaceBoxes = new Map(); this._cachedWorkspaceBoxes = new Map();
this._postAllocationCallbacks = []; this._postAllocationCallbacks = [];
@ -78,7 +80,6 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
const workspaceBox = box.copy(); const workspaceBox = box.copy();
const [width, height] = workspaceBox.get_size(); const [width, height] = workspaceBox.get_size();
const {y1: startY} = this._workAreaBox; const {y1: startY} = this._workAreaBox;
const {spacing} = this;
const {expandFraction} = this._workspacesThumbnails; const {expandFraction} = this._workspacesThumbnails;
switch (state) { switch (state) {
@ -88,16 +89,16 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
break; break;
case ControlsState.WINDOW_PICKER: case ControlsState.WINDOW_PICKER:
workspaceBox.set_origin(0, workspaceBox.set_origin(0,
startY + searchHeight + spacing + startY + searchHeight + this._spacing +
thumbnailsHeight + spacing * expandFraction); thumbnailsHeight + this._spacing * expandFraction);
workspaceBox.set_size(width, workspaceBox.set_size(width,
height - height -
dashHeight - spacing - dashHeight - this._spacing -
searchHeight - spacing - searchHeight - this._spacing -
thumbnailsHeight - spacing * expandFraction); thumbnailsHeight - this._spacing * expandFraction);
break; break;
case ControlsState.APP_GRID: case ControlsState.APP_GRID:
workspaceBox.set_origin(0, startY + searchHeight + spacing); workspaceBox.set_origin(0, startY + searchHeight + this._spacing);
workspaceBox.set_size( workspaceBox.set_size(
width, width,
Math.round(height * SMALL_WORKSPACE_RATIO)); Math.round(height * SMALL_WORKSPACE_RATIO));
@ -111,7 +112,6 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
const [width, height] = box.get_size(); const [width, height] = box.get_size();
const {y1: startY} = this._workAreaBox; const {y1: startY} = this._workAreaBox;
const appDisplayBox = new Clutter.ActorBox(); const appDisplayBox = new Clutter.ActorBox();
const {spacing} = this;
switch (state) { switch (state) {
case ControlsState.HIDDEN: case ControlsState.HIDDEN:
@ -120,14 +120,14 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
break; break;
case ControlsState.APP_GRID: case ControlsState.APP_GRID:
appDisplayBox.set_origin(0, appDisplayBox.set_origin(0,
startY + searchHeight + spacing + appGridBox.get_height()); startY + searchHeight + this._spacing + appGridBox.get_height());
break; break;
} }
appDisplayBox.set_size(width, appDisplayBox.set_size(width,
height - height -
searchHeight - spacing - searchHeight - this._spacing -
appGridBox.get_height() - spacing - appGridBox.get_height() - this._spacing -
dashHeight); dashHeight);
return appDisplayBox; return appDisplayBox;
@ -142,9 +142,17 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
} }
vfunc_set_container(container) { vfunc_set_container(container) {
this._container?.disconnectObject(this);
this._container = container; this._container = container;
if (container) this._container?.connectObject('style-changed',
this.hookup_style(container); () => {
const node = this._container.get_theme_node();
const spacing = node.get_length('spacing');
if (this._spacing !== spacing) {
this._spacing = spacing;
this.layout_changed();
}
}, this);
} }
vfunc_get_preferred_width(_container, _forHeight) { vfunc_get_preferred_width(_container, _forHeight) {
@ -160,8 +168,6 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
vfunc_allocate(container, box) { vfunc_allocate(container, box) {
const childBox = new Clutter.ActorBox(); const childBox = new Clutter.ActorBox();
const {spacing} = this;
const startY = this._workAreaBox.y1; const startY = this._workAreaBox.y1;
box.y1 += startY; box.y1 += startY;
const [width, height] = box.get_size(); const [width, height] = box.get_size();
@ -173,7 +179,7 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
childBox.set_size(width, searchHeight); childBox.set_size(width, searchHeight);
this._searchEntry.allocate(childBox); this._searchEntry.allocate(childBox);
availableHeight -= searchHeight + spacing; availableHeight -= searchHeight + this._spacing;
// Dash // Dash
const maxDashHeight = Math.round(box.get_height() * DASH_MAX_HEIGHT_RATIO); const maxDashHeight = Math.round(box.get_height() * DASH_MAX_HEIGHT_RATIO);
@ -185,7 +191,7 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
childBox.set_size(width, dashHeight); childBox.set_size(width, dashHeight);
this._dash.allocate(childBox); this._dash.allocate(childBox);
availableHeight -= dashHeight + spacing; availableHeight -= dashHeight + this._spacing;
// Workspace Thumbnails // Workspace Thumbnails
let thumbnailsHeight = 0; let thumbnailsHeight = 0;
@ -196,7 +202,7 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
thumbnailsHeight = Math.min( thumbnailsHeight = Math.min(
thumbnailsHeight * expandFraction, thumbnailsHeight * expandFraction,
height * this._workspacesThumbnails.maxThumbnailScale); height * this._workspacesThumbnails.maxThumbnailScale);
childBox.set_origin(0, startY + searchHeight + spacing); childBox.set_origin(0, startY + searchHeight + this._spacing);
childBox.set_size(width, thumbnailsHeight); childBox.set_size(width, thumbnailsHeight);
this._workspacesThumbnails.allocate(childBox); this._workspacesThumbnails.allocate(childBox);
} }
@ -245,7 +251,7 @@ class ControlsManagerLayout extends Clutter.BoxLayout {
} }
// Search // Search
childBox.set_origin(0, startY + searchHeight + spacing); childBox.set_origin(0, startY + searchHeight + this._spacing);
childBox.set_size(width, availableHeight); childBox.set_size(width, availableHeight);
this._searchController.allocate(childBox); this._searchController.allocate(childBox);