Skip to content

feat: make QDeepinTheme follow DConfig settings#1005

Open
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/qdeepintheme-follow-dconfig
Open

feat: make QDeepinTheme follow DConfig settings#1005
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/qdeepintheme-follow-dconfig

Conversation

@deepin-wm

@deepin-wm deepin-wm commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

增强 QDeepinTheme,让 treeland 自身的光标闪动间隔、双击间隔、系统字体、等宽字体跟随 DConfig 设置。

  1. Override themeHint() to return CursorFlashTime and MouseDoubleClickInterval from TreelandUserConfig
  2. Override font() to return SystemFont and FixedFont based on DConfig font/monoFont/fontSize settings
  3. Add notifyThemeChanged() to trigger Qt theme refresh via QWindowSystemInterface::handleThemeChanged()
  4. Add connectConfigSignals() to bind DConfig change signals to theme refresh, with disconnect on user switch to prevent duplicate connections
  5. Connect Helper::configChanged to reconnect signals when user configuration is rebuilt

WM-25

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @deepin-wm, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-wm deepin-wm force-pushed the fix/qdeepintheme-follow-dconfig branch 5 times, most recently from 8aa9c67 to 6e93e07 Compare June 18, 2026 06:34
Comment thread src/main.cpp Outdated
WAYLIB_SERVER_USE_NAMESPACE
DCORE_USE_NAMESPACE;

class QDeepinTheme : public QGenericUnixTheme

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请把它拆到一个单独文件实现,现在的逻辑太长了,不应该再放main.cpp里了

Comment thread src/main.cpp Outdated
if (!config)
return;

config->disconnect();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个断开的不对,1是只应该断开QDeepinTheme的connect,不能把别人的给断开了,2是这里的config对象是新的,应该断开的是旧的config。

Comment thread src/main.cpp Outdated
return;

// Notify all top-level windows about the theme change
for (auto *window : QGuiApplication::topLevelWindows()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for循环要确保用 std::as_const 让list为const的

Comment thread src/main.cpp Outdated
// Force Qt to re-query style hints and fonts
auto *app = QGuiApplication::instance();
QEvent fontEvent(QEvent::ApplicationFontChange);
QCoreApplication::sendEvent(app, &fontEvent);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

font仅这样做不会有变化,应该要 setFont 直接设置guiapplication的font,而且应该仅在font相关的配置有变化时才这样做,不相关的配置变化时不要做。

Comment thread src/main.cpp Outdated
// Notify all top-level windows about the theme change
for (auto *window : QGuiApplication::topLevelWindows()) {
QEvent event(QEvent::ThemeChange);
QCoreApplication::sendEvent(static_cast<QObject*>(window), &event);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样做意义不大,应该调用 QGuiApplicationPrivate::handleThemeChanged ,而且应该只在theme icon等相关变化时才调用。

Comment thread src/main.cpp Outdated
return &palette;
}

QVariant themeHint(ThemeHint hint) const override

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不应该只支持这么点,不还有 KeyboardAutoRepeatRate MouseCursorTheme等内容的吗,要把能支持的都支持上去。

Comment thread src/main.cpp Outdated
return QGenericUnixTheme::font(type);
}

static void notifyThemeChanged()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于有些属性没有通知手段的,且 qstylehints里有设置入口的,可以用qstylehints的setXXXX方法设置,这样它是有信号的,或者干脆优先使用qstylehints的setXXXX方法。

@deepin-wm deepin-wm force-pushed the fix/qdeepintheme-follow-dconfig branch 7 times, most recently from f9c3c96 to 8aa6adc Compare June 18, 2026 08:52
Comment thread src/deepintheme.cpp
if (type != QPlatformTheme::SystemPalette) {
return QGenericUnixTheme::palette(type);
}
static QPalette palette;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥要做成静态的?这里可以直接return guihelper的呀

Comment thread src/deepintheme.cpp Outdated
return QGenericUnixTheme::palette(type);
}
static QPalette palette;
palette = Dtk::Gui::DGuiApplicationHelper::instance()->applicationPalette();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要写完整的namespace,可以跟DCORE_USE_NAMESPACE一样用 DGUI_USE_NAMESPACE

Comment thread src/deepintheme.h Outdated
@@ -0,0 +1,44 @@
// Copyright (C) 2024 JiDe Zhang <zhangjide@deepin.org>.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在是2026年了,而且不应该是个人的,应该是 UnionTech 公司

@deepin-wm deepin-wm force-pushed the fix/qdeepintheme-follow-dconfig branch 3 times, most recently from 49a5a03 to cba3420 Compare June 18, 2026 09:48
Implement QDeepinTheme that reads DConfig settings and applies them
to the Qt platform theme, so QPA follows treeland user preferences.

- Split QDeepinTheme to separate deepintheme.h/.cpp files
- Track connections via QMetaObject::Connection for proper cleanup
- Disconnect only own connections from old config on rebind
- Use QStyleHints setters for properties that have them:
  setCursorFlashTime, setMouseDoubleClickInterval,
  setStartDragDistance, setColorScheme
- Set font via QGuiApplication::setFont(), only on font changes
- Use QGuiApplicationPrivate::handleThemeChanged() for theme/icon changes
- Support: cursorBlink/cursorBlinkTime, doubleClickTime,
  doubleClickDistance, dndDragThreshold, font/monoFont/fontSize,
  iconThemeName, themeName, preferDark, cursorThemeName
@deepin-wm deepin-wm force-pushed the fix/qdeepintheme-follow-dconfig branch from cba3420 to ef01bc0 Compare June 18, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants