diff --git a/src/controller.cpp b/src/controller.cpp index 788c9c98a..fcd7a3e9b 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -8,9 +8,6 @@ #include #include -#ifdef HAVE_WINDOWSYSTEM -#include -#endif #include #include @@ -392,32 +389,6 @@ QString Controller::formatDuration(quint64 msecs, KFormat::DurationFormatOptions return KFormat().formatDuration(msecs, options); } -void Controller::setBlur(QQuickItem *item, bool blur) -{ -#ifdef HAVE_WINDOWSYSTEM - auto setWindows = [item, blur]() { - auto reg = QRect(QPoint(0, 0), item->window()->size()); - KWindowEffects::enableBackgroundContrast(item->window(), blur, 1, 1, 1, reg); - KWindowEffects::enableBlurBehind(item->window(), blur, reg); - }; - - disconnect(item->window(), &QQuickWindow::heightChanged, this, nullptr); - disconnect(item->window(), &QQuickWindow::widthChanged, this, nullptr); - connect(item->window(), &QQuickWindow::heightChanged, this, setWindows); - connect(item->window(), &QQuickWindow::widthChanged, this, setWindows); - setWindows(); -#endif -} - -bool Controller::hasWindowSystem() const -{ -#ifdef HAVE_WINDOWSYSTEM - return true; -#else - return false; -#endif -} - void Controller::forceRefreshTextDocument(QQuickTextDocument *textDocument, QQuickItem *item) { // HACK: Workaround bug QTBUG 93281 diff --git a/src/controller.h b/src/controller.h index 3fadc8ddc..7789f5b8f 100644 --- a/src/controller.h +++ b/src/controller.h @@ -64,11 +64,6 @@ class Controller : public QObject */ Q_PROPERTY(bool supportSystemTray READ supportSystemTray CONSTANT) - /** - * @brief Whether KWindowSystem specific features are available. - */ - Q_PROPERTY(bool hasWindowSystem READ hasWindowSystem CONSTANT) - /** * @brief Whether NeoChat is currently able to connect to the server. */ @@ -128,11 +123,6 @@ public: [[nodiscard]] bool supportSystemTray() const; - /** - * @brief Set the background blur status of the given item. - */ - Q_INVOKABLE void setBlur(QQuickItem *item, bool blur); - bool isOnline() const; /** @@ -180,8 +170,6 @@ private: bool m_isOnline = true; QMap m_notificationCounts; - bool hasWindowSystem() const; - QPointer m_pushRuleModel; Quotient::AccountRegistry m_accountRegistry; diff --git a/src/qml/AppearanceSettingsPage.qml b/src/qml/AppearanceSettingsPage.qml index 88332abaa..3f29d3beb 100644 --- a/src/qml/AppearanceSettingsPage.qml +++ b/src/qml/AppearanceSettingsPage.qml @@ -235,7 +235,7 @@ FormCard.FormCardPage { FormCard.FormCheckDelegate { id: hasWindowSystemDelegate - visible: Controller.hasWindowSystem + visible: WindowController.hasWindowSystem text: i18n("Use transparent chat page") enabled: !Config.compactLayout && !Config.isBlurImmutable checked: Config.blur @@ -249,7 +249,7 @@ FormCard.FormCardPage { FormCard.AbstractFormDelegate { id: transparencyDelegate - visible: Controller.hasWindowSystem && Config.blur + visible: WindowController.hasWindowSystem && Config.blur enabled: !Config.isTransparancyImmutable background: Item {} contentItem: ColumnLayout { diff --git a/src/qml/main.qml b/src/qml/main.qml index 139038529..77a22479c 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -190,7 +190,7 @@ Kirigami.ApplicationWindow { } Component.onCompleted: { - Controller.setBlur(pageStack, Config.blur && !Config.compactLayout); + WindowController.setBlur(pageStack, Config.blur && !Config.compactLayout); if (Config.minimizeToSystemTrayOnStartup && !Kirigami.Settings.isMobile && Controller.supportSystemTray && Config.systemTray) { restoreWindowGeometryConnections.enabled = true; // To restore window size and position } else { @@ -201,10 +201,10 @@ Kirigami.ApplicationWindow { Connections { target: Config function onBlurChanged() { - Controller.setBlur(pageStack, Config.blur && !Config.compactLayout); + WindowController.setBlur(pageStack, Config.blur && !Config.compactLayout); } function onCompactLayoutChanged() { - Controller.setBlur(pageStack, Config.blur && !Config.compactLayout); + WindowController.setBlur(pageStack, Config.blur && !Config.compactLayout); } } diff --git a/src/windowcontroller.cpp b/src/windowcontroller.cpp index 15259e5a6..c3fcb47f9 100644 --- a/src/windowcontroller.cpp +++ b/src/windowcontroller.cpp @@ -76,4 +76,30 @@ void WindowController::showAndRaiseWindow(const QString &startupId) #endif } +bool WindowController::hasWindowSystem() const +{ +#ifdef HAVE_WINDOWSYSTEM + return true; +#else + return false; +#endif +} + +void WindowController::setBlur(QQuickItem *item, bool blur) +{ +#ifdef HAVE_WINDOWSYSTEM + auto setWindows = [item, blur]() { + auto reg = QRect(QPoint(0, 0), item->window()->size()); + KWindowEffects::enableBackgroundContrast(item->window(), blur, 1, 1, 1, reg); + KWindowEffects::enableBlurBehind(item->window(), blur, reg); + }; + + disconnect(item->window(), &QQuickWindow::heightChanged, this, nullptr); + disconnect(item->window(), &QQuickWindow::widthChanged, this, nullptr); + connect(item->window(), &QQuickWindow::heightChanged, this, setWindows); + connect(item->window(), &QQuickWindow::widthChanged, this, setWindows); + setWindows(); +#endif +} + #include "moc_windowcontroller.cpp" diff --git a/src/windowcontroller.h b/src/windowcontroller.h index a416bfbd0..cdcb1c7c5 100644 --- a/src/windowcontroller.h +++ b/src/windowcontroller.h @@ -4,8 +4,12 @@ #pragma once #include -#include - +#include +#include +#include +#ifdef HAVE_WINDOWSYSTEM +#include +#endif /** * @class WindowController * @@ -14,9 +18,21 @@ class WindowController : public QObject { Q_OBJECT + QML_ELEMENT + QML_SINGLETON + + /** + * @brief Whether KWindowSystem specific features are available. + */ + Q_PROPERTY(bool hasWindowSystem READ hasWindowSystem CONSTANT) public: static WindowController &instance(); + static WindowController *create(QQmlEngine *engine, QJSEngine *) + { + engine->setObjectOwnership(&instance(), QQmlEngine::CppOwnership); + return &instance(); + } /** * @brief Set the window that the will be managed. @@ -43,6 +59,13 @@ public: */ void showAndRaiseWindow(const QString &startupId); + bool hasWindowSystem() const; + + /** + * @brief Set the background blur status of the given item. + */ + Q_INVOKABLE void setBlur(QQuickItem *item, bool blur); + Q_SIGNALS: /** * @brief Triggered if the managed window is changed.