From b34255b96f5bcf30405ca5d5d132b5e5667576f3 Mon Sep 17 00:00:00 2001 From: Alex Spataru Date: Tue, 21 Dec 2021 17:06:08 -0500 Subject: [PATCH] Allow enabling/disabling window shadows --- assets/qml/FramelessWindow/CustomWindow.qml | 3 ++- assets/qml/Panes/SetupPanes/Settings.qml | 19 +++++++++++++++++++ src/Misc/ThemeManager.cpp | 18 ++++++++++++++++++ src/Misc/ThemeManager.h | 9 +++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/assets/qml/FramelessWindow/CustomWindow.qml b/assets/qml/FramelessWindow/CustomWindow.qml index 6d9b2bdd..219cfb83 100644 --- a/assets/qml/FramelessWindow/CustomWindow.qml +++ b/assets/qml/FramelessWindow/CustomWindow.qml @@ -97,7 +97,8 @@ QtWindow.Window { // // Size of the shadow object // - property int shadowMargin: Cpp_IsMac ? 0 : (root.radius > 0 ? 20 : 0) + property int shadowMargin: (Cpp_IsMac | !Cpp_ThemeManager.shadowsEnabled) ? + 0 : (root.radius > 0 ? 20 : 0) // // Titlebar left/right margins for custom controls diff --git a/assets/qml/Panes/SetupPanes/Settings.qml b/assets/qml/Panes/SetupPanes/Settings.qml index 6caaa0b8..a225c8fc 100644 --- a/assets/qml/Panes/SetupPanes/Settings.qml +++ b/assets/qml/Panes/SetupPanes/Settings.qml @@ -35,6 +35,7 @@ Control { property alias tcpPlugins: _tcpPlugins.checked property alias language: _langCombo.currentIndex property alias startSequence: _startSequence.text + property alias windowShadows: _windowShadows.checked property alias separatorSequence: _separatorSequence.text property alias multithreadedFrameProcessing: _multithreadedFrameProcessing.checked @@ -166,6 +167,24 @@ Control { Cpp_JSON_Generator.processFramesInSeparateThread = checked } } + + // + // Window shadows + // + Label { + visible: !Cpp_IsMac + text: qsTr("Window shadows") + ": " + } Switch { + id: _windowShadows + visible: !Cpp_IsMac + Layout.leftMargin: -app.spacing + Layout.alignment: Qt.AlignLeft + checked: Cpp_ThemeManager.shadowsEnabled + onCheckedChanged: { + if (checked != Cpp_ThemeManager.shadowsEnabled) + Cpp_ThemeManager.shadowsEnabled = checked + } + } } // diff --git a/src/Misc/ThemeManager.cpp b/src/Misc/ThemeManager.cpp index 192be58e..19433fe7 100644 --- a/src/Misc/ThemeManager.cpp +++ b/src/Misc/ThemeManager.cpp @@ -41,6 +41,7 @@ Misc::ThemeManager::ThemeManager() { populateThemes(); loadTheme(m_settings.value("themeId", 0).toInt()); + setShadowsEnabled(m_settings.value("shadowsEnabled", true).toBool()); } /** @@ -60,6 +61,16 @@ int Misc::ThemeManager::themeId() const return m_themeId; } +/** + * Returns @c true if the application should draw window shadows. This feature makes the + * frameless windows look good - except if the DE does not support composting (e.g. CDE + * or Haiku OS). + */ +bool Misc::ThemeManager::shadowsEnabled() const +{ + return m_enableShadows; +} + /** * Updates the theme ID to be used & saves the changes to the * application settings. @@ -93,6 +104,13 @@ void Misc::ThemeManager::setTheme(const int id) Utilities::rebootApplication(); } +void Misc::ThemeManager::setShadowsEnabled(const bool enabled) +{ + m_enableShadows = enabled; + m_settings.setValue("shadowsEnabled", enabled); + Q_EMIT shadowsEnabledChanged(); +} + /** * Parses the JSON theme definition file for the given theme ID. * The colors are then "extracted" from the JSON file & loaded into the diff --git a/src/Misc/ThemeManager.h b/src/Misc/ThemeManager.h index 80dcdb65..7258c42a 100644 --- a/src/Misc/ThemeManager.h +++ b/src/Misc/ThemeManager.h @@ -193,10 +193,15 @@ class ThemeManager : public QObject Q_PROPERTY(StringList availableThemes READ availableThemes NOTIFY availableThemesChanged) + Q_PROPERTY(bool shadowsEnabled + READ shadowsEnabled + WRITE setshadowsEnabled + NOTIFY shadowsEnabledChanged) // clang-format on Q_SIGNALS: void themeChanged(); + void shadowsEnabledChanged(); void availableThemesChanged(); private: @@ -210,6 +215,7 @@ public: static ThemeManager &instance(); int themeId() const; + bool shadowsEnabled() const; bool titlebarSeparator() const; QColor base() const; @@ -264,6 +270,7 @@ public: public Q_SLOTS: void setTheme(const int id); + void setShadowsEnabled(const bool enabled); private Q_SLOTS: void populateThemes(); @@ -271,6 +278,8 @@ private Q_SLOTS: private: int m_themeId; + bool m_enableShadows; + QSettings m_settings; bool m_titlebarSeparator; StringList m_availableThemes;