ec14fb7a2a
- Add keep-wallpaper-aspect-ratio-wallpaper-on-screen-resolution-change.diff: * Chooses a new preferred background image when the screen resolution is changed to keep the correct aspect ratio (boo#990257). Also check for division by zero. Note that for this patch to work correctly, it needs a kpackage with https://build.opensuse.org/request/show/433784 applied. OBS-URL: https://build.opensuse.org/request/show/433788 OBS-URL: https://build.opensuse.org/package/show/KDE:Frameworks5:LTS/plasma5-workspace?expand=0&rev=28
39 lines
1.7 KiB
Diff
39 lines
1.7 KiB
Diff
diff --git a/wallpapers/image/image.cpp b/wallpapers/image/image.cpp
|
|
index 0aa72bb..0a65b7d 100644
|
|
--- a/wallpapers/image/image.cpp
|
|
+++ b/wallpapers/image/image.cpp
|
|
@@ -192,7 +192,7 @@ void Image::findPreferedImageInPackage(KPackage::Package &package)
|
|
// 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();
|
|
+ float targetAspectRatio = ( m_targetSize.height() > 0 ) ? m_targetSize.width() / (float)m_targetSize.height() : 0;
|
|
|
|
QString bestImage;
|
|
QString bestImageWithSameAspectRatio;
|
|
@@ -201,7 +201,7 @@ void Image::findPreferedImageInPackage(KPackage::Package &package)
|
|
if (candidate == QSize()) {
|
|
continue;
|
|
}
|
|
- float candidateAspectRatio = candidate.width()/(float)candidate.height();
|
|
+ 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;
|
|
@@ -235,9 +235,15 @@ QSize Image::targetSize() const
|
|
|
|
void Image::setTargetSize(const QSize &size)
|
|
{
|
|
+ bool sizeChanged = m_targetSize != size;
|
|
m_targetSize = size;
|
|
|
|
if (m_mode == SingleImage) {
|
|
+ if (sizeChanged) {
|
|
+ // If screen size was changed, we may want to select a new preferred image
|
|
+ // which has correct aspect ratio for the new screen size.
|
|
+ m_wallpaperPackage.removeDefinition("preferred");
|
|
+ }
|
|
setSingleImage();
|
|
}
|
|
}
|