Commit b73b970a authored by Ismael Asensio's avatar Ismael Asensio
Browse files

switchers/thumbnailgrid: Fix layout when window count changes

Assign the column calculation declaratively, so the number of
columns is automatically updated on window count changes

BUG: 441241
FIXED-IN: 5.25.3
parent 801763bb
Pipeline #196823 passed with stage
in 1 minute and 42 seconds
......@@ -46,7 +46,17 @@ KWin.Switcher {
property real screenFactor: tabBox.screenGeometry.width / tabBox.screenGeometry.height
property int maxGridColumnsByWidth: Math.floor(maxWidth / thumbnailGridView.cellWidth)
property int gridColumns: maxGridColumnsByWidth
property int gridColumns: { // Simple greedy algorithm
// respect screenGeometry
const c = Math.min(thumbnailGridView.count, maxGridColumnsByWidth);
const residue = thumbnailGridView.count % c;
if (residue == 0) {
return c;
}
// start greedy recursion
return columnCountRecursion(c, c, c - residue);
}
property int gridRows: Math.ceil(thumbnailGridView.count / gridColumns)
property int optimalWidth: thumbnailGridView.cellWidth * gridColumns
property int optimalHeight: thumbnailGridView.cellHeight * gridRows
......@@ -57,21 +67,6 @@ KWin.Switcher {
clip: true
// Simple greedy algorithm
function calculateColumnCount() {
// respect screenGeometry
const c = Math.min(thumbnailGridView.count, maxGridColumnsByWidth);
const residue = thumbnailGridView.count % c;
if (residue == 0) {
gridColumns = c;
return;
}
// start greedy recursion
gridColumns = columnCountRecursion(c, c, c - residue);
}
// Step for greedy algorithm
function columnCountRecursion(prevC, prevBestC, prevDiff) {
const c = prevC - 1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment