launcher: allow wallpaper switch when exactly 2 wallpapers (#343)

This commit is contained in:
Laurens Duin 2025-08-05 06:31:40 +02:00 committed by GitHub
parent e26e1947bf
commit e4d4c457f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,22 +16,22 @@ PathView {
return 0; return 0;
const itemWidth = Config.launcher.sizes.wallpaperWidth * 0.8; const itemWidth = Config.launcher.sizes.wallpaperWidth * 0.8;
const max = Config.launcher.maxWallpapers; const max = Config.launcher.maxWallpapers;
if (max * itemWidth > screenWidth) { const maxItemsOnScreen = Math.floor(screenWidth / itemWidth);
const items = Math.floor(screenWidth / itemWidth);
return items > 1 && items % 2 === 0 ? items - 1 : items; const visible = Math.min(maxItemsOnScreen, max, scriptModel.values.length)
} if (visible === 2)
return max; return 1
else if (visible > 1 && visible %2 === 0)
return visible - 1
return visible;
} }
model: ScriptModel { model: ScriptModel {
id: scriptModel
readonly property string search: root.search.text.split(" ").slice(1).join(" ") readonly property string search: root.search.text.split(" ").slice(1).join(" ")
values: { values: Wallpapers.query(search)
const list = Wallpapers.query(search);
if (list.length > 1 && list.length % 2 === 0)
list.length -= 1; // Always show odd number
return list;
}
onValuesChanged: root.currentIndex = search ? 0 : values.findIndex(w => w.path === Wallpapers.actualCurrent) onValuesChanged: root.currentIndex = search ? 0 : values.findIndex(w => w.path === Wallpapers.actualCurrent)
} }