- Added fix-wallpaper-not-having-correct-aspect-ratio.diff . The previous algorithm to choose a wallpaper preferred the ones with the closest area giving preference to downscaling over upscaling. This patch changes that to use that algorithm first only in wallpapers with the same aspect ratio as the screen and then using the old algorithm as fallback if no wallpaper has the same aspect ratio (boo#990257) OBS-URL: https://build.opensuse.org/request/show/429455 OBS-URL: https://build.opensuse.org/package/show/KDE:Frameworks5:LTS/plasma5-workspace?expand=0&rev=14
56 lines
2.4 KiB
Diff
56 lines
2.4 KiB
Diff
Index: plasma-workspace-5.7.95/wallpapers/image/image.cpp
|
|
===================================================================
|
|
--- plasma-workspace-5.7.95.orig/wallpapers/image/image.cpp
|
|
+++ plasma-workspace-5.7.95/wallpapers/image/image.cpp
|
|
@@ -182,30 +182,43 @@ void Image::findPreferedImageInPackage(K
|
|
return;
|
|
}
|
|
|
|
- //qDebug() << "wanted" << size;
|
|
+ //qDebug() << "wanted" << m_targetSize;
|
|
+ //qDebug() << "options" << images;
|
|
|
|
- // choose the nearest resolution
|
|
+ // choose the nearest resolution, always preferring images with the same aspect ratio
|
|
float best = FLT_MAX;
|
|
+ float bestWithSameAspectRatio = FLT_MAX;
|
|
+ float targetAspectRatio = m_targetSize.width()/(float)m_targetSize.height();
|
|
|
|
QString bestImage;
|
|
+ QString bestImageWithSameAspectRatio;
|
|
foreach (const QString &entry, images) {
|
|
QSize candidate = resSize(QFileInfo(entry).baseName());
|
|
if (candidate == QSize()) {
|
|
continue;
|
|
}
|
|
+ float candidateAspectRatio = candidate.width()/(float)candidate.height();
|
|
|
|
double dist = distance(candidate, m_targetSize);
|
|
- //qDebug() << "candidate" << candidate << "distance" << dist;
|
|
- if (bestImage.isEmpty() || dist < best) {
|
|
- bestImage = entry;
|
|
- best = dist;
|
|
- //qDebug() << "best" << bestImage;
|
|
+ //qDebug() << "candidate" << candidate << "distance" << dist << "aspect ratio" << candidateAspectRatio;
|
|
+
|
|
+ if ( candidateAspectRatio == targetAspectRatio && (bestImageWithSameAspectRatio.isEmpty() || dist < bestWithSameAspectRatio) ) {
|
|
+ bestImageWithSameAspectRatio = entry;
|
|
+ bestWithSameAspectRatio = dist;
|
|
+ //qDebug() << "bestWithSameAspectRatio" << bestImageWithSameAspectRatio;
|
|
if (dist == 0) {
|
|
break;
|
|
}
|
|
+ } else if (bestImage.isEmpty() || dist < best) {
|
|
+ bestImage = entry;
|
|
+ best = dist;
|
|
+ //qDebug() << "best" << bestImage;
|
|
}
|
|
}
|
|
|
|
+ if (!bestImageWithSameAspectRatio.isEmpty()) // Always prefer an image with the same aspect ratio as the target (if available)
|
|
+ bestImage=bestImageWithSameAspectRatio;
|
|
+
|
|
//qDebug() << "best image" << bestImage;
|
|
package.removeDefinition("preferred");
|
|
package.addFileDefinition("preferred", "images/" + bestImage, i18n("Recommended wallpaper file"));
|