1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00

Fix windows wallpaper fade in calculation again

This commit is contained in:
Elias Steurer 2022-12-03 17:01:50 +01:00
parent 4da1f5cd04
commit e2beadb671
4 changed files with 68 additions and 18 deletions

View File

@ -7,7 +7,6 @@ import ScreenPlay.Enums.VideoCodec
Rectangle { Rectangle {
id: root id: root
onStateChanged: print(state)
property bool canFadeByWallpaperFillMode: true property bool canFadeByWallpaperFillMode: true
@ -173,6 +172,43 @@ Rectangle {
switch (Wallpaper.windowsDesktopProperties.wallpaperStyle) { switch (Wallpaper.windowsDesktopProperties.wallpaperStyle) {
case 10: case 10:
imgCover.fillMode = Image.PreserveAspectCrop imgCover.fillMode = Image.PreserveAspectCrop
// We only support fade in for one screen
if (Wallpaper.activeScreensList.length !== 1)
return
if (Wallpaper.width === 0)
return
if (Wallpaper.width > Wallpaper.windowsDesktopProperties.defaultWallpaperSize.width)
return
// Windows does some weird top margin if the Wallpaper
// is bigger than the monitor. So instead of centering
// it vertically it moves the wallpaper down by 1/3 of
// the remaining height.
// 1. Scale down the wallpaper based on the height.
// The default Windows 11 wallpaper C:\Windows\Web\Wallpaper\Windows\img19.jpg
// has a resoltion of 3841x2400 scaled down to 3440x2150,3 with a given monitor
// resolution of 3440x1440 resulting in a 2150,3 - 1440 = 710,3
// 710,3 / (1/3) = 236,767
const monitorWidth = Wallpaper.width
const monitorHeight = Wallpaper.height
const windowsWallpaperWidth = Wallpaper.windowsDesktopProperties.defaultWallpaperSize.width
const windowsWallpapeHeight = Wallpaper.windowsDesktopProperties.defaultWallpaperSize.height
// 1. Get scale factor:
// -> 3440 / 3840 = 0.8956
const scaleFactor = monitorWidth / windowsWallpaperWidth
// 2. Scale down the default Windows wallpaper height (width stays the same for correct aspect ratio):
// -> 2400 * 0.8956 = 2149.4
const scaledDownDefaultWallpaperHeight = windowsWallpapeHeight * scaleFactor
// 3. Calc offste
// -> 2150,3 - 1440 = 710,3
const offset = scaledDownDefaultWallpaperHeight - monitorHeight
// 4. Calc the one third offset (topMargin)
// -> 710,3 * (1/3) = 236,767
const topMargin = Math.floor(offset * 0.3333333)
imgCover.anchors.topMargin = -topMargin
break break
case 6: case 6:
imgCover.fillMode = Image.PreserveAspectFit imgCover.fillMode = Image.PreserveAspectFit
@ -199,18 +235,6 @@ Rectangle {
anchors { anchors {
top: parent.top top: parent.top
topMargin: {
// FHD 16:9
if (root.width === 1920 && root.height === 1080)
return 0
// FHD 21:9
if (root.width === 2560 && root.height === 1080)
return -66
// WQHD 21:9
if (root.width === 3440 && root.height === 1440)
return -93
return 0
}
left: parent.left left: parent.left
right: parent.right right: parent.right
} }

View File

@ -1,5 +1,8 @@
#include "windowsdesktopproperties.h" #include "windowsdesktopproperties.h"
#include <QFileInfo>
#include <QImage>
/*! /*!
\class WindowsDesktopProperties \class WindowsDesktopProperties
\inmodule ScreenPlayWallpaper \inmodule ScreenPlayWallpaper
@ -15,6 +18,12 @@ WindowsDesktopProperties::WindowsDesktopProperties(QObject* parent)
setWallpaperPath(settings.value("WallPaper").toString()); setWallpaperPath(settings.value("WallPaper").toString());
setIsTiled(settings.value("TileWallpaper").toBool()); setIsTiled(settings.value("TileWallpaper").toBool());
QFileInfo defaultBackgroundImageInfo(m_wallpaperPath);
if(defaultBackgroundImageInfo.exists()){
QImage backgroundImage(defaultBackgroundImageInfo.absoluteFilePath());
setDefaultWallpaperSize(backgroundImage.size());
}
QPoint pos; QPoint pos;
pos.setX(settings.value("WallpaperOriginX").toInt()); pos.setX(settings.value("WallpaperOriginX").toInt());
pos.setY(settings.value("WallpaperOriginY").toInt()); pos.setY(settings.value("WallpaperOriginY").toInt());

View File

@ -41,6 +41,7 @@
#include <QPoint> #include <QPoint>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QSize>
#include <qqml.h> #include <qqml.h>
#include <qt_windows.h> #include <qt_windows.h>
@ -51,6 +52,8 @@ public:
explicit WindowsDesktopProperties(QObject* parent = nullptr); explicit WindowsDesktopProperties(QObject* parent = nullptr);
Q_PROPERTY(int windowsVersion READ windowsVersion WRITE setWindowsVersion NOTIFY windowsVersionChanged) Q_PROPERTY(int windowsVersion READ windowsVersion WRITE setWindowsVersion NOTIFY windowsVersionChanged)
Q_PROPERTY(QSize defaultWallpaperSize READ defaultWallpaperSize WRITE setDefaultWallpaperSize NOTIFY defaultWallpaperSizeChanged)
Q_PROPERTY(QString wallpaperPath READ wallpaperPath WRITE setWallpaperPath NOTIFY wallpaperPathChanged) Q_PROPERTY(QString wallpaperPath READ wallpaperPath WRITE setWallpaperPath NOTIFY wallpaperPathChanged)
Q_PROPERTY(QPoint position READ position WRITE setPosition NOTIFY positionChanged) Q_PROPERTY(QPoint position READ position WRITE setPosition NOTIFY positionChanged)
Q_PROPERTY(bool isTiled READ isTiled WRITE setIsTiled NOTIFY isTiledChanged) Q_PROPERTY(bool isTiled READ isTiled WRITE setIsTiled NOTIFY isTiledChanged)
@ -72,6 +75,7 @@ public:
int wallpaperStyle() const { return m_wallpaperStyle; } int wallpaperStyle() const { return m_wallpaperStyle; }
QColor color() const { return m_color; } QColor color() const { return m_color; }
int windowsVersion() const { return m_windowsVersion; } int windowsVersion() const { return m_windowsVersion; }
QSize defaultWallpaperSize() const { return m_defaultWallpaperSize; }
signals: signals:
void wallpaperPathChanged(QString wallpaperPath); void wallpaperPathChanged(QString wallpaperPath);
@ -81,7 +85,17 @@ signals:
void colorChanged(QColor color); void colorChanged(QColor color);
void windowsVersionChanged(int windowsVersion); void windowsVersionChanged(int windowsVersion);
void defaultWallpaperSizeChanged();
public slots: public slots:
void setDefaultWallpaperSize(const QSize& newDefaultWallpaperSize)
{
if (m_defaultWallpaperSize == newDefaultWallpaperSize)
return;
m_defaultWallpaperSize = newDefaultWallpaperSize;
emit defaultWallpaperSizeChanged();
}
void setWallpaperPath(QString wallpaperPath) void setWallpaperPath(QString wallpaperPath)
{ {
if (m_wallpaperPath == wallpaperPath) if (m_wallpaperPath == wallpaperPath)
@ -139,4 +153,5 @@ private:
int m_wallpaperStyle; int m_wallpaperStyle;
QColor m_color; QColor m_color;
int m_windowsVersion; int m_windowsVersion;
QSize m_defaultWallpaperSize;
}; };

View File

@ -264,7 +264,9 @@ void WinWindow::setupWallpaperForOneScreen(int activeScreen)
const int x = monitors.rcMonitors[activeScreen].left + m_zeroPoint.x() + borderOffset; const int x = monitors.rcMonitors[activeScreen].left + m_zeroPoint.x() + borderOffset;
const int y = monitors.rcMonitors[activeScreen].top + m_zeroPoint.y() + borderOffset; const int y = monitors.rcMonitors[activeScreen].top + m_zeroPoint.y() + borderOffset;
qInfo() << QString("Setup window activeScreen: %1 scaling: %2 x: %3 y: %4 width: %5 height: %6").arg(activeScreen).arg(scaling).arg(x).arg(y).arg(width).arg(height); qInfo() << QString("Setup window activeScreen: %1 scaling: %2 x: %3 y: %4 width: %5 height: %6").arg(activeScreen).arg(scaling).arg(x).arg(y).arg(width).arg(height);
// Also set it in BaseWindow. This is needed for Windows fade in.
setWidth(width - boderWidth);
setHeight(height - boderWidth);
{ {
// Must be called twice for some reason when window has scaling... // Must be called twice for some reason when window has scaling...
if (!SetWindowPos(m_windowHandle, nullptr, x, y, width, height, SWP_HIDEWINDOW)) { if (!SetWindowPos(m_windowHandle, nullptr, x, y, width, height, SWP_HIDEWINDOW)) {
@ -387,7 +389,6 @@ float WinWindow::getScaling(const int monitorIndex)
return 1; return 1;
case 107: case 107:
return 1.5; return 1.5;
case 109: case 109:
return 1; return 1;
case 161: case 161:
@ -417,6 +418,7 @@ bool WinWindow::hasWindowScaling()
*/ */
void WinWindow::configureWindowGeometry() void WinWindow::configureWindowGeometry()
{ {
qInfo() << "configureWindowGeometry";
setVisible(false); setVisible(false);
if (!searchWorkerWindowToParentTo()) { if (!searchWorkerWindowToParentTo()) {
@ -448,12 +450,12 @@ void WinWindow::configureWindowGeometry()
setupWallpaperForMultipleScreens(activeScreensList()); setupWallpaperForMultipleScreens(activeScreensList());
} }
setWidth(m_window.width());
setHeight(m_window.height());
// Instead of setting "renderType: Text.NativeRendering" every time we can set it here once // Instead of setting "renderType: Text.NativeRendering" every time we can set it here once
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering); m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
m_window.setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView); m_window.setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
m_window.setWidth(width());
m_window.setHeight(height());
qInfo() << "Setup " << width() << height();
m_window.setSource(QUrl("qrc:/qml/ScreenPlayWallpaper/qml/Wallpaper.qml")); m_window.setSource(QUrl("qrc:/qml/ScreenPlayWallpaper/qml/Wallpaper.qml"));
m_window.hide(); m_window.hide();
} }