- Add use-nearest-aspect-ratio-available-wallpaper.diff to improve the selection of wallpapers keeping the same (or as similar as possible) aspect ratio (boo#990257). Include the latest changes submitted upstream to work better with QUAD HD screen resolutions. OBS-URL: https://build.opensuse.org/request/show/438297 OBS-URL: https://build.opensuse.org/package/show/KDE:Frameworks5/plasma5-workspace?expand=0&rev=271
73 lines
3.5 KiB
Diff
73 lines
3.5 KiB
Diff
Index: plasma-workspace-5.8.2/wallpapers/image/image.cpp
|
|
===================================================================
|
|
--- plasma-workspace-5.8.2.orig/wallpapers/image/image.cpp
|
|
+++ plasma-workspace-5.8.2/wallpapers/image/image.cpp
|
|
@@ -156,13 +156,14 @@ void Image::setRenderingMode(RenderingMo
|
|
float distance(const QSize& size, const QSize& desired)
|
|
{
|
|
// compute difference of areas
|
|
- float delta = size.width() * size.height() -
|
|
- desired.width() * desired.height();
|
|
- // scale down to about 1.0
|
|
- delta /= ((desired.width() * desired.height())+(size.width() * size.height()))/2;
|
|
+ float desiredAspectRatio = ( desired.height() > 0 ) ? desired.width() / (float)desired.height() : 0;
|
|
+ float candidateAspectRatio = (size.height() > 0 ) ? size.width() / (float)size.height() : FLT_MAX;
|
|
+
|
|
+ float delta = size.width() - desired.width();
|
|
+ delta = (delta >= 0.0 ? delta : -delta*2 ); // Penalize for scaling up
|
|
+
|
|
+ return qAbs(candidateAspectRatio - desiredAspectRatio)*25000 + delta;
|
|
|
|
- // Difference of areas, slight preference to scale down
|
|
- return delta >= 0.0 ? delta : -delta + 2.0;
|
|
}
|
|
|
|
QSize resSize(const QString &str)
|
|
@@ -187,42 +188,28 @@ void Image::findPreferedImageInPackage(K
|
|
return;
|
|
}
|
|
|
|
- //qDebug() << "wanted" << m_targetSize << "options" << images;
|
|
+ //float targetAspectRatio = (m_targetSize.height() > 0 ) ? m_targetSize.width() / (float)m_targetSize.height() : 0;
|
|
+ //qDebug() << "wanted" << m_targetSize << "options" << images << "aspect ratio" << targetAspectRatio;
|
|
|
|
- // choose the nearest resolution, always preferring images with the same aspect ratio
|
|
float best = FLT_MAX;
|
|
- float bestWithSameAspectRatio = FLT_MAX;
|
|
- float targetAspectRatio = ( m_targetSize.height() > 0 ) ? m_targetSize.width() / (float)m_targetSize.height() : 0;
|
|
-
|
|
QString bestImage;
|
|
- QString bestImageWithSameAspectRatio;
|
|
foreach (const QString &entry, images) {
|
|
QSize candidate = resSize(QFileInfo(entry).baseName());
|
|
if (candidate == QSize()) {
|
|
continue;
|
|
}
|
|
- float candidateAspectRatio = (candidate.height() > 0 ) ? candidate.width() / (float)candidate.height() : FLT_MAX;
|
|
+ //float candidateAspectRatio = (candidate.height() > 0 ) ? candidate.width() / (float)candidate.height() : FLT_MAX;
|
|
|
|
double dist = distance(candidate, m_targetSize);
|
|
//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) {
|
|
+ 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"));
|