-
Notifications
You must be signed in to change notification settings - Fork 43
feat: make QDeepinTheme follow DConfig settings #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
deepin-wm
wants to merge
5
commits into
linuxdeepin:master
Choose a base branch
from
deepin-wm:fix/qdeepintheme-follow-dconfig
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef01bc0
feat: make QDeepinTheme follow DConfig settings
b2dd8a0
fix(deepintheme): address PR #1005 review comments
f4a888d
fix(deepintheme): fix review issues from code review
f2bf9ba
fix(deepintheme): use postEvent instead of handleThemeChanged
f0deb06
fix(deepintheme): fix CI build failure
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| // Copyright (C) 2026 UnionTech Software Technology Co., Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | ||
|
|
||
| #include "deepintheme.h" | ||
|
|
||
| #include "seat/helper.h" | ||
| #include "seatuserconfig.hpp" | ||
| #include "treelanduserconfig.hpp" | ||
|
|
||
| #include <DGuiApplicationHelper> | ||
|
|
||
| #include <QCoreApplication> | ||
| #include <QGuiApplication> | ||
| #include <QSizeF> | ||
| #include <QStyleHints> | ||
|
|
||
| DCORE_USE_NAMESPACE; | ||
| DGUI_USE_NAMESPACE; | ||
|
|
||
| QDeepinTheme::QDeepinTheme() = default; | ||
|
|
||
| QDeepinTheme::~QDeepinTheme() | ||
| { | ||
| disconnectConfig(); | ||
| disconnectSeatConfig(); | ||
| } | ||
|
|
||
| const QPalette *QDeepinTheme::palette(QPlatformTheme::Palette type) const | ||
| { | ||
| if (type != QPlatformTheme::SystemPalette) { | ||
| return QGenericUnixTheme::palette(type); | ||
| } | ||
| static QPalette palette; | ||
| palette = DGuiApplicationHelper::instance()->applicationPalette(); | ||
| return &palette; | ||
| } | ||
|
|
||
| QVariant QDeepinTheme::themeHint(ThemeHint hint) const | ||
| { | ||
| if (!m_config) | ||
| return QGenericUnixTheme::themeHint(hint); | ||
|
|
||
| switch (hint) { | ||
| case CursorFlashTime: | ||
| return m_config->cursorBlink() ? m_config->cursorBlinkTime() : 0; | ||
| case MouseDoubleClickInterval: | ||
| return m_config->doubleClickTime(); | ||
| case MouseDoubleClickDistance: | ||
| return m_config->doubleClickDistance(); | ||
| case StartDragDistance: | ||
| return m_config->dndDragThreshold(); | ||
| case MouseCursorTheme: | ||
| return m_config->cursorThemeName(); | ||
| case MouseCursorSize: | ||
| return QSizeF(m_config->cursorSize(), m_config->cursorSize()); | ||
| case KeyboardAutoRepeatRate: | ||
| return m_seatConfig ? m_seatConfig->keyboardRate() : QGenericUnixTheme::themeHint(hint); | ||
| case KeyboardInputInterval: | ||
| return m_seatConfig ? m_seatConfig->keyboardDelay() : QGenericUnixTheme::themeHint(hint); | ||
| default: | ||
| break; | ||
| } | ||
| return QGenericUnixTheme::themeHint(hint); | ||
| } | ||
|
|
||
| const QFont *QDeepinTheme::font(Font type) const | ||
| { | ||
| if (!m_config) | ||
| return QGenericUnixTheme::font(type); | ||
|
|
||
| switch (type) { | ||
| case SystemFont: { | ||
| static QFont f; | ||
| f.setFamily(m_config->font()); | ||
| f.setPointSize(m_config->fontSize() / 10.0); | ||
| return &f; | ||
| } | ||
| case FixedFont: { | ||
| static QFont f; | ||
| f.setFamily(m_config->monoFont()); | ||
| f.setPointSize(m_config->fontSize() / 10.0); | ||
| return &f; | ||
| } | ||
| default: | ||
| break; | ||
| } | ||
| return QGenericUnixTheme::font(type); | ||
| } | ||
|
|
||
| void QDeepinTheme::bindConfig(TreelandUserConfig *config) | ||
| { | ||
| if (m_config == config) | ||
| return; | ||
|
|
||
| disconnectConfig(); | ||
| m_config = config; | ||
| if (!m_config) | ||
| return; | ||
|
|
||
| auto addConnection = [this](const QMetaObject::Connection &conn) { | ||
| m_connections.push_back(conn); | ||
| }; | ||
|
|
||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::cursorBlinkChanged, m_config, [this]() { applyCursorSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::cursorBlinkTimeChanged, m_config, [this]() { applyCursorSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::doubleClickTimeChanged, m_config, [this]() { applyStyleHintSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::doubleClickDistanceChanged, m_config, [this]() { applyThemeSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::dndDragThresholdChanged, m_config, [this]() { applyStyleHintSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::fontChanged, m_config, [this]() { applyFontSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::monoFontChanged, m_config, [this]() { applyFontSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::fontSizeChanged, m_config, [this]() { applyFontSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::iconThemeNameChanged, m_config, [this]() { applyThemeSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::themeNameChanged, m_config, [this]() { applyThemeSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::preferDarkChanged, m_config, [this]() { applyStyleHintSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::cursorThemeNameChanged, m_config, [this]() { applyThemeSettings(); })); | ||
| addConnection(QObject::connect(m_config, &TreelandUserConfig::cursorSizeChanged, m_config, [this]() { applyThemeSettings(); })); | ||
|
|
||
| applyAllSettings(); | ||
| } | ||
|
|
||
| void QDeepinTheme::applyAllSettings() | ||
| { | ||
| applyCursorSettings(); | ||
| applyStyleHintSettings(); | ||
| applyFontSettings(); | ||
| applyThemeSettings(); | ||
| applyKeyboardSettings(); | ||
| } | ||
|
|
||
| void QDeepinTheme::applyCursorSettings() | ||
| { | ||
| if (!m_config) | ||
| return; | ||
|
|
||
| int flashTime = m_config->cursorBlink() ? m_config->cursorBlinkTime() : 0; | ||
| QGuiApplication::styleHints()->setCursorFlashTime(flashTime); | ||
| } | ||
|
|
||
| void QDeepinTheme::applyFontSettings() | ||
| { | ||
| if (!m_config) | ||
| return; | ||
|
|
||
| QFont systemFont; | ||
| systemFont.setFamily(m_config->font()); | ||
| systemFont.setPointSize(m_config->fontSize() / 10.0); | ||
| QGuiApplication::setFont(systemFont); | ||
| } | ||
|
|
||
| void QDeepinTheme::applyThemeSettings() | ||
| { | ||
| if (!m_config) | ||
| return; | ||
|
|
||
| QCoreApplication::postEvent(qGuiApp, new QEvent(QEvent::ThemeChange)); | ||
| } | ||
|
|
||
| void QDeepinTheme::applyStyleHintSettings() | ||
| { | ||
| if (!m_config) | ||
| return; | ||
|
|
||
| auto *hints = QGuiApplication::styleHints(); | ||
| hints->setMouseDoubleClickInterval(m_config->doubleClickTime()); | ||
| hints->setStartDragDistance(m_config->dndDragThreshold()); | ||
|
|
||
| if (m_config->preferDark()) { | ||
| hints->setColorScheme(Qt::ColorScheme::Dark); | ||
| } else { | ||
| hints->setColorScheme(Qt::ColorScheme::Light); | ||
| } | ||
| } | ||
|
|
||
| void QDeepinTheme::disconnectConfig() | ||
| { | ||
| for (const auto &conn : std::as_const(m_connections)) { | ||
| QObject::disconnect(conn); | ||
| } | ||
| m_connections.clear(); | ||
| m_config = nullptr; | ||
| } | ||
|
|
||
| void QDeepinTheme::bindSeatConfig(SeatUserDConfig *config) | ||
| { | ||
| if (m_seatConfig == config) | ||
| return; | ||
|
|
||
| disconnectSeatConfig(); | ||
| m_seatConfig = config; | ||
| if (!m_seatConfig) | ||
| return; | ||
|
|
||
| auto addConnection = [this](const QMetaObject::Connection &conn) { | ||
| m_seatConnections.push_back(conn); | ||
| }; | ||
|
|
||
| addConnection(QObject::connect(m_seatConfig, &SeatUserDConfig::keyboardRateChanged, | ||
| m_seatConfig, [this]() { applyKeyboardSettings(); })); | ||
| addConnection(QObject::connect(m_seatConfig, &SeatUserDConfig::keyboardDelayChanged, | ||
| m_seatConfig, [this]() { applyKeyboardSettings(); })); | ||
|
|
||
| applyKeyboardSettings(); | ||
| } | ||
|
|
||
| void QDeepinTheme::applyKeyboardSettings() | ||
| { | ||
| if (!m_seatConfig) | ||
| return; | ||
|
|
||
| auto *hints = QGuiApplication::styleHints(); | ||
| hints->setKeyboardAutoRepeatRate(m_seatConfig->keyboardRate()); | ||
| hints->setKeyboardInputInterval(m_seatConfig->keyboardDelay()); | ||
| } | ||
|
|
||
| void QDeepinTheme::disconnectSeatConfig() | ||
| { | ||
| for (const auto &conn : std::as_const(m_seatConnections)) { | ||
| QObject::disconnect(conn); | ||
| } | ||
| m_seatConnections.clear(); | ||
| m_seatConfig = nullptr; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (C) 2026 UnionTech Software Technology Co., Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <QFont> | ||
| #include <QPalette> | ||
| #include <QPointer> | ||
|
|
||
| #if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0) | ||
| # include <private/qgenericunixtheme_p.h> | ||
| #else | ||
| # include <private/qgenericunixthemes_p.h> | ||
| #endif | ||
|
|
||
| #include <vector> | ||
|
|
||
| class SeatUserDConfig; | ||
| class TreelandUserConfig; | ||
|
|
||
| class QDeepinTheme : public QGenericUnixTheme | ||
| { | ||
| public: | ||
| QDeepinTheme(); | ||
| ~QDeepinTheme() override; | ||
|
|
||
| const QPalette *palette(QPlatformTheme::Palette type) const override; | ||
| QVariant themeHint(ThemeHint hint) const override; | ||
| const QFont *font(Font type) const override; | ||
|
|
||
| void bindConfig(TreelandUserConfig *config); | ||
| void bindSeatConfig(SeatUserDConfig *config); | ||
|
|
||
| private: | ||
| void applyAllSettings(); | ||
| void applyCursorSettings(); | ||
| void applyFontSettings(); | ||
| void applyThemeSettings(); | ||
| void applyStyleHintSettings(); | ||
| void applyKeyboardSettings(); | ||
|
|
||
| void disconnectConfig(); | ||
| void disconnectSeatConfig(); | ||
|
|
||
| QPointer<TreelandUserConfig> m_config; | ||
| QPointer<SeatUserDConfig> m_seatConfig; | ||
| std::vector<QMetaObject::Connection> m_connections; | ||
| std::vector<QMetaObject::Connection> m_seatConnections; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.