diff --git a/ScreenPlayWallpaper/main.cpp b/ScreenPlayWallpaper/main.cpp index f4128b23..8652170e 100644 --- a/ScreenPlayWallpaper/main.cpp +++ b/ScreenPlayWallpaper/main.cpp @@ -32,9 +32,10 @@ int main(int argc, char* argv[]) // For testing purposes when starting the ScreenPlayWallpaper directly. if (argumentList.length() == 1) { #if defined(Q_OS_WIN) - WinWindow window1({ 0 }, "test", "appID=test", "1", "fill", "videoWallpaper", true, true); + // WinWindow window1({ 0 }, "test", "appID=test", "1", "fill", "videoWallpaper", true, true); + WinWindow window1({ 0 }, "C:/Program Files (x86)/Steam/steamapps/workshop/content/672870/_tmp_171806", "appID=test", "1", "fill", "videoWallpaper", true, true); #elif defined(Q_OS_LINUX) - LinuxWindow window({ 0 }, "/home/graphicscore/Desktop/wallpapers/MechaGirl", "appid", "1", "fill", false); + LinuxWindow window({ 0 }, "test", "appid", "1", "fill", false); #elif defined(Q_OS_OSX) MacWindow window({ 0 }, "test", "appid", "1", "fill"); #endif diff --git a/ScreenPlayWallpaper/src/basewindow.cpp b/ScreenPlayWallpaper/src/basewindow.cpp index f6a4a9b8..399bbbbd 100644 --- a/ScreenPlayWallpaper/src/basewindow.cpp +++ b/ScreenPlayWallpaper/src/basewindow.cpp @@ -37,7 +37,7 @@ BaseWindow::BaseWindow( } setAppID(appID); - + setContentBasePath(projectFilePath); setOSVersion(QSysInfo::productVersion()); if (projectFilePath == "test") { @@ -209,13 +209,22 @@ QString BaseWindow::getApplicationPath() } /*! - \brief This public slot is for QML usage. + \brief This public slot is for QML usage. We limit the change event updates + to every 50ms, because the filesystem can be very trigger happy + with multiple change events per second. */ void BaseWindow::setupLiveReloading() { - auto reloadQMLLambda = [this]() { emit reloadQML(type()); }; - QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, reloadQMLLambda); - QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, reloadQMLLambda); - const QFileInfo file { m_fullContentPath }; - m_fileSystemWatcher.addPaths({ file.path(), m_fullContentPath }); + auto reloadQMLLambda = [this]() { + m_liveReloadLimiter.stop(); + emit reloadQML(type()); + }; + auto timeoutLambda = [this]() { + m_liveReloadLimiter.start(50); + }; + + QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, timeoutLambda); + QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, timeoutLambda); + QObject::connect(&m_liveReloadLimiter, &QTimer::timeout, this, reloadQMLLambda); + m_fileSystemWatcher.addPaths({ m_contentBasePath }); } diff --git a/ScreenPlayWallpaper/src/basewindow.h b/ScreenPlayWallpaper/src/basewindow.h index 79c0fa89..9e32bca0 100644 --- a/ScreenPlayWallpaper/src/basewindow.h +++ b/ScreenPlayWallpaper/src/basewindow.h @@ -72,6 +72,7 @@ public: Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged) Q_PROPERTY(QString basePath READ basePath WRITE setBasePath NOTIFY basePathChanged) Q_PROPERTY(QString fullContentPath READ fullContentPath WRITE setFullContentPath NOTIFY fullContentPathChanged) + Q_PROPERTY(QString contentBasePath READ contentBasePath WRITE setContentBasePath NOTIFY contentBasePathChanged) Q_PROPERTY(QString fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) Q_PROPERTY(bool loops READ loops WRITE setLoops NOTIFY loopsChanged) @@ -113,6 +114,7 @@ public: QString basePath() const { return m_basePath; } bool debugMode() const { return m_debugMode; } ScreenPlaySDK* sdk() const { return m_sdk.get(); } + const QString& contentBasePath() const { return m_contentBasePath; } signals: void qmlExit(); @@ -142,6 +144,8 @@ signals: void debugModeChanged(bool debugMode); void sdkChanged(ScreenPlaySDK* sdk); + void contentBasePathChanged(const QString&); + public slots: virtual void destroyThis() { } virtual void setVisible(bool show) { Q_UNUSED(show) } @@ -340,6 +344,14 @@ public slots: emit sdkChanged(sdk); } + void setContentBasePath(const QString& contentBasePath) + { + if (m_contentBasePath == contentBasePath) + return; + m_contentBasePath = contentBasePath; + emit contentBasePathChanged(m_contentBasePath); + } + private: void setupLiveReloading(); @@ -370,4 +382,6 @@ private: QString m_basePath; bool m_debugMode = false; std::unique_ptr m_sdk; + QString m_contentBasePath; + QTimer m_liveReloadLimiter; }; diff --git a/ScreenPlayWallpaper/src/winwindow.cpp b/ScreenPlayWallpaper/src/winwindow.cpp index d528f3d9..71b4d417 100644 --- a/ScreenPlayWallpaper/src/winwindow.cpp +++ b/ScreenPlayWallpaper/src/winwindow.cpp @@ -123,7 +123,6 @@ void WinWindow::setupWindowMouseHook() qInfo() << "Faild to install mouse hook!"; return; } - qInfo() << "Setup mousehook"; } } @@ -146,6 +145,9 @@ WinWindow::WinWindow( { auto* guiAppInst = dynamic_cast(QApplication::instance()); + connect(this, &BaseWindow::reloadQML, this, [this]() { + clearComponentCache(); + }); connect(guiAppInst, &QApplication::screenAdded, this, &WinWindow::configureWindowGeometry); connect(guiAppInst, &QApplication::screenRemoved, this, &WinWindow::configureWindowGeometry); connect(guiAppInst, &QApplication::primaryScreenChanged, this, &WinWindow::configureWindowGeometry); @@ -187,7 +189,7 @@ WinWindow::WinWindow( } } if (hasWindowScaling) { - qInfo() << "scaling"; + qInfo() << "Monitor with scaling detected!"; configureWindowGeometry(); } @@ -202,7 +204,8 @@ WinWindow::WinWindow( setupWindowMouseHook(); }); - sdk()->start(); + if (!debugMode) + sdk()->start(); } void WinWindow::setVisible(bool show)