diff --git a/include/kernel/dplatformtheme.h b/include/kernel/dplatformtheme.h index 9aa7c20..8e42376 100644 --- a/include/kernel/dplatformtheme.h +++ b/include/kernel/dplatformtheme.h @@ -242,9 +242,6 @@ public Q_SLOTS: private: friend class DPlatformThemePrivate; - -private: - D_PRIVATE_SLOT(void _q_onThemePropertyChanged(const QByteArray &name, const QVariant &value)) }; DGUI_END_NAMESPACE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f436622..71086b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,10 +4,6 @@ else() find_package(Qt5 REQUIRED COMPONENTS WaylandClient XkbCommonSupport) endif() -option(DTK_DISABLE_TREELAND "Disable TreeLand Protocols" OFF) -find_package(TreelandProtocols) -set(TreelandProtocols_FOUND ${TreelandProtocols_FOUND}) - add_library(${LIB_NAME} SHARED) include(dbus/dbus.cmake) @@ -15,42 +11,7 @@ include(filedrag/dfiledrag.cmake) include(kernel/kernel.cmake) include(private/private.cmake) include(util/util.cmake) - -try_compile(DEEPIN_WAYLAND_TEST_COMPILE_RESULT ${CMAKE_CURRENT_BINARY_DIR}/wayland_test - ${CMAKE_CURRENT_LIST_DIR}/wayland/config.tests/wayland_test wayland_test CMAKE_FLAGS -DQT_VERSION_MAJOR=${QT_VERSION_MAJOR}) - -if(NOT DEEPIN_WAYLAND_TEST_COMPILE_RESULT) - message("wayland_test failed, disable treeland support") - set(DTK_DISABLE_TREELAND ON) -endif() - -if(NOT DTK_DISABLE_TREELAND AND TreelandProtocols_FOUND) - message("Support Treeland!") - if("${QT_VERSION_MAJOR}" STREQUAL "6") - qt6_generate_wayland_protocol_client_sources(${LIB_NAME} FILES - ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml - ) - else() - # ECM setup - include(FeatureSummary) - find_package(ECM REQUIRED NO_MODULE) - set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ECM_MODULE_PATH}") - find_package(QtWaylandScanner) - ecm_add_qtwayland_client_protocol(CLIENT_LIB_SRCS - PROTOCOL ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml - BASENAME treeland-personalization-manager-v1 - ) - target_sources(${LIB_NAME} PRIVATE - ${CLIENT_LIB_SRCS} - ) - endif() - include(wayland/wayland.cmake) - target_sources(${LIB_NAME} PRIVATE - ${wayland_SRC} - ) -else() - target_compile_definitions(${LIB_NAME} PRIVATE DTK_DISABLE_TREELAND) -endif() +include(plugins/plugins.cmake) target_sources(${LIB_NAME} PRIVATE ${dbus_SRC} diff --git a/src/kernel/dplatformtheme.cpp b/src/kernel/dplatformtheme.cpp index 5aee3ef..e92a0ce 100644 --- a/src/kernel/dplatformtheme.cpp +++ b/src/kernel/dplatformtheme.cpp @@ -5,10 +5,19 @@ #include "dplatformtheme.h" #include "private/dplatformtheme_p.h" +#ifndef DTK_DISABLE_XCB +#include "plugins/platform/xcb/dxcbplatforminterface.h" +#endif +#ifndef DTK_DISABLE_TREELAND +#include "plugins/platform/treeland/dtreelandplatforminterface.h" +#endif +#include "plugins/dplatforminterface.h" + #include #include #include #include +#include #include @@ -22,76 +31,6 @@ DPlatformThemePrivate::DPlatformThemePrivate(Dtk::Gui::DPlatformTheme *qq) } -void DPlatformThemePrivate::_q_onThemePropertyChanged(const QByteArray &name, const QVariant &value) -{ - D_Q(DPlatformTheme); - - // 转发属性变化的信号,此信号来源可能为parent theme或“非调色板”的属性变化。 - // 使用队列的形式转发,避免多次发出同样的信号 - q->staticMetaObject.invokeMethod(q, "propertyChanged", Qt::QueuedConnection, - Q_ARG(const QByteArray&, name), Q_ARG(const QVariant&, value)); - - if (QByteArrayLiteral("Gtk/FontName") == name) { - Q_EMIT q->gtkFontNameChanged(value.toByteArray()); - return; - } - - if (name.startsWith("Qt/DPI/")) { - const QString &screen_name = QString::fromLocal8Bit(name.mid(7)); - - if (!screen_name.isEmpty()) { - bool ok = false; - int dpi = value.toInt(&ok); - - Q_EMIT q->dotsPerInchChanged(screen_name, ok ? dpi : -1); - } - - return; - } - - if (QByteArrayLiteral("Xft/DPI") == name) { - bool ok = false; - int dpi = value.toInt(&ok); - Q_EMIT q->dotsPerInchChanged(QString(), ok ? dpi : -1); - } - - const QByteArrayList &list = name.split('/'); - - if (list.count() != 2) - return; - - QByteArray pn = list.last(); - - if (pn.isEmpty()) - return; - - // 转换首字母为小写 - pn[0] = QChar(pn.at(0)).toLower().toLatin1(); - - // 直接使用静态的meta object,防止通过metaObject函数调用到dynamic metaobject - const QMetaObject *mo = &DPlatformTheme::staticMetaObject; - int index = mo->indexOfProperty(pn.constData()); - - if (index < 0) - return; - - const QMetaProperty &p = mo->property(index); - bool is_parent_signal = q->sender() != theme; - - // 当自己的属性有效时应该忽略父主题的属性变化信号,优先以自身的属性值为准。 - if (is_parent_signal && p.read(q).isValid()) { - return; - } - - if (p.hasNotifySignal()) { - // invoke会做Q_ASSERT(mobj->cast(object))判断, DPlatformTheme的dynamic metaObject为 - // qt5platform-plugin插件的DNativeSettings. 导致崩溃. - // invokeOnGadget与invoke代码逻辑一致, 只是少了异步支持. - if (!p.notifySignal().invokeOnGadget(q, QGenericArgument(value.typeName(), value.constData()))) - qWarning() << "_q_onThemePropertyChanged() error when notify signal" << p.notifySignal().name(); - } -} - void DPlatformThemePrivate::onQtColorChanged(QPalette::ColorRole role, const QColor &color) { if (!palette) { @@ -142,6 +81,22 @@ DPlatformTheme::DPlatformTheme(quint32 window, QObject *parent) { D_D(DPlatformTheme); + #ifndef DTK_DISABLE_XCB + if (DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsXWindowPlatform)) { + d->platformInterface = new DXCBPlatformInterface(0, parent); + } + #endif + + #ifndef DTK_DISABLE_TREELAND + if (DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsTreelandPlatform)) { + d->platformInterface = new DTreelandPlatformInterface(parent); + } + #endif + + if (!d->platformInterface) { + d->platformInterface = new DPlatformInterface(parent); + } + d->theme = new DNativeSettings(window, QByteArray(), this); #if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) connect(this, &DPlatformTheme::windowChanged, std::bind(&DPlatformThemePrivate::onQtColorChanged, d, QPalette::Window, std::placeholders::_1)); @@ -172,8 +127,55 @@ DPlatformTheme::DPlatformTheme(quint32 window, QObject *parent) connect(this, &DPlatformTheme::darkLivelyChanged, std::bind(&DPlatformThemePrivate::onDtkColorChanged, d, DPalette::DarkLively, std::placeholders::_1)); connect(this, &DPlatformTheme::frameBorderChanged, std::bind(&DPlatformThemePrivate::onDtkColorChanged, d, DPalette::FrameBorder, std::placeholders::_1)); #endif - connect(d->theme, SIGNAL(propertyChanged(const QByteArray &, const QVariant &)), - this, SLOT(_q_onThemePropertyChanged(const QByteArray &, const QVariant &))); + connect(d->platformInterface, &DPlatformInterface::cursorBlinkTimeChanged, this, &DPlatformTheme::cursorBlinkTimeChanged); + connect(d->platformInterface, &DPlatformInterface::cursorBlinkTimeoutChanged, this, &DPlatformTheme::cursorBlinkTimeoutChanged); + connect(d->platformInterface, &DPlatformInterface::cursorBlinkChanged, this, &DPlatformTheme::cursorBlinkChanged); + connect(d->platformInterface, &DPlatformInterface::doubleClickDistanceChanged, this, &DPlatformTheme::doubleClickDistanceChanged); + connect(d->platformInterface, &DPlatformInterface::doubleClickTimeChanged, this, &DPlatformTheme::doubleClickTimeChanged); + connect(d->platformInterface, &DPlatformInterface::dndDragThresholdChanged, this, &DPlatformTheme::dndDragThresholdChanged); + connect(d->platformInterface, &DPlatformInterface::themeNameChanged, this, &DPlatformTheme::themeNameChanged); + connect(d->platformInterface, &DPlatformInterface::iconThemeNameChanged, this, &DPlatformTheme::iconThemeNameChanged); + connect(d->platformInterface, &DPlatformInterface::soundThemeNameChanged, this, &DPlatformTheme::soundThemeNameChanged); + connect(d->platformInterface, &DPlatformInterface::fontNameChanged, this, &DPlatformTheme::fontNameChanged); + connect(d->platformInterface, &DPlatformInterface::monoFontNameChanged, this, &DPlatformTheme::monoFontNameChanged); + connect(d->platformInterface, &DPlatformInterface::fontPointSizeChanged, this, &DPlatformTheme::fontPointSizeChanged); + connect(d->platformInterface, &DPlatformInterface::gtkFontNameChanged, this, &DPlatformTheme::gtkFontNameChanged); + connect(d->platformInterface, &DPlatformInterface::activeColorChanged, this, &DPlatformTheme::activeColorChanged); + connect(d->platformInterface, &DPlatformInterface::darkActiveColorChanged, this, &DPlatformTheme::darkActiveColorChanged); + connect(d->platformInterface, &DPlatformInterface::paletteChanged, this, &DPlatformTheme::paletteChanged); +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) + connect(d->platformInterface, &DPlatformInterface::windowChanged, this, &DPlatformTheme::windowChanged); + connect(d->platformInterface, &DPlatformInterface::windowTextChanged, this, &DPlatformTheme::windowTextChanged); + connect(d->platformInterface, &DPlatformInterface::baseChanged, this, &DPlatformTheme::baseChanged); + connect(d->platformInterface, &DPlatformInterface::alternateBaseChanged, this, &DPlatformTheme::alternateBaseChanged); + connect(d->platformInterface, &DPlatformInterface::toolTipBaseChanged, this, &DPlatformTheme::toolTipBaseChanged); + connect(d->platformInterface, &DPlatformInterface::toolTipTextChanged, this, &DPlatformTheme::toolTipTextChanged); + connect(d->platformInterface, &DPlatformInterface::textChanged, this, &DPlatformTheme::textChanged); + connect(d->platformInterface, &DPlatformInterface::buttonChanged, this, &DPlatformTheme::buttonChanged); + connect(d->platformInterface, &DPlatformInterface::buttonTextChanged, this, &DPlatformTheme::buttonTextChanged); + connect(d->platformInterface, &DPlatformInterface::brightTextChanged, this, &DPlatformTheme::brightTextChanged); + connect(d->platformInterface, &DPlatformInterface::lightChanged, this, &DPlatformTheme::lightChanged); + connect(d->platformInterface, &DPlatformInterface::midlightChanged, this, &DPlatformTheme::midlightChanged); + connect(d->platformInterface, &DPlatformInterface::darkChanged, this, &DPlatformTheme::darkChanged); + connect(d->platformInterface, &DPlatformInterface::midChanged, this, &DPlatformTheme::midChanged); + connect(d->platformInterface, &DPlatformInterface::shadowChanged, this, &DPlatformTheme::shadowChanged); + connect(d->platformInterface, &DPlatformInterface::highlightChanged, this, &DPlatformTheme::highlightChanged); + connect(d->platformInterface, &DPlatformInterface::highlightedTextChanged, this, &DPlatformTheme::highlightedTextChanged); + connect(d->platformInterface, &DPlatformInterface::linkChanged, this, &DPlatformTheme::linkChanged); + connect(d->platformInterface, &DPlatformInterface::linkVisitedChanged, this, &DPlatformTheme::linkVisitedChanged); + connect(d->platformInterface, &DPlatformInterface::itemBackgroundChanged, this, &DPlatformTheme::itemBackgroundChanged); + connect(d->platformInterface, &DPlatformInterface::textTitleChanged, this, &DPlatformTheme::textTitleChanged); + connect(d->platformInterface, &DPlatformInterface::textTipsChanged, this, &DPlatformTheme::textTipsChanged); + connect(d->platformInterface, &DPlatformInterface::textWarningChanged, this, &DPlatformTheme::textWarningChanged); + connect(d->platformInterface, &DPlatformInterface::textLivelyChanged, this, &DPlatformTheme::textLivelyChanged); + connect(d->platformInterface, &DPlatformInterface::lightLivelyChanged, this, &DPlatformTheme::lightLivelyChanged); + connect(d->platformInterface, &DPlatformInterface::darkLivelyChanged, this, &DPlatformTheme::darkLivelyChanged); + connect(d->platformInterface, &DPlatformInterface::frameBorderChanged, this, &DPlatformTheme::frameBorderChanged); +#endif + connect(d->platformInterface, &DPlatformInterface::dotsPerInchChanged, this, &DPlatformTheme::dotsPerInchChanged); + connect(d->platformInterface, &DPlatformInterface::windowRadiusChanged, this, &DPlatformTheme::windowRadiusChanged); + connect(d->platformInterface, &DPlatformInterface::sizeModeChanged, this, &DPlatformTheme::sizeModeChanged); + connect(d->platformInterface, &DPlatformInterface::scrollBarPolicyChanged, this, &DPlatformTheme::scrollBarPolicyChanged); } DPlatformTheme::DPlatformTheme(quint32 window, DPlatformTheme *parent) @@ -331,141 +333,106 @@ void DPlatformTheme::setPalette(const DPalette &palette) #endif } -#define FETCH_PROPERTY(Name, Function) \ - D_DC(DPlatformTheme); \ - QVariant value = d->theme->getSetting(QByteArrayLiteral(Name)); \ - if (d->fallbackProperty && !value.isValid() && d->parent) \ - return d->parent->Function(); \ - -#define FETCH_PROPERTY_WITH_ARGS(Name, Function, Args) \ - D_DC(DPlatformTheme); \ - QVariant value = d->theme->getSetting(Name); \ - if (d->fallbackProperty && !value.isValid() && d->parent) \ - return d->parent->Function(Args); \ - int DPlatformTheme::cursorBlinkTime() const { - FETCH_PROPERTY("Net/CursorBlinkTime", cursorBlinkTime) - - return value.toInt(); + D_DC(DPlatformTheme); + return d->platformInterface->cursorBlinkTime(); } int DPlatformTheme::cursorBlinkTimeout() const { - FETCH_PROPERTY("Net/CursorBlinkTimeout", cursorBlinkTimeout) - - return value.toInt(); + D_DC(DPlatformTheme); + return d->platformInterface->cursorBlinkTimeout(); } bool DPlatformTheme::cursorBlink() const { - FETCH_PROPERTY("Net/CursorBlink", cursorBlink) - - return value.toInt(); + D_DC(DPlatformTheme); + return d->platformInterface->cursorBlink(); } int DPlatformTheme::doubleClickDistance() const { - FETCH_PROPERTY("Net/DoubleClickDistance", doubleClickDistance) - - return value.toInt(); + D_DC(DPlatformTheme); + return d->platformInterface->doubleClickDistance(); } int DPlatformTheme::doubleClickTime() const { - FETCH_PROPERTY("Net/DoubleClickTime", doubleClickTime) - - return value.toInt(); + D_DC(DPlatformTheme); + return d->platformInterface->doubleClickTime(); } int DPlatformTheme::dndDragThreshold() const { - FETCH_PROPERTY("Net/DndDragThreshold", dndDragThreshold) - - return value.toInt(); + D_DC(DPlatformTheme); + return d->platformInterface->dndDragThreshold(); } int DPlatformTheme::windowRadius() const { - return windowRadius(-1); + D_DC(DPlatformTheme); + return d->platformInterface->windowRadius(); } int DPlatformTheme::windowRadius(int defaultValue) const { - Q_D(const DPlatformTheme); - - QVariant value = d->theme->getSetting(QByteArrayLiteral("DTK/WindowRadius")); - bool ok = false; - - if (d->fallbackProperty && !value.isValid() && d->parent) - return d->parent->windowRadius(defaultValue); - - int radius = value.toInt(&ok); - - return ok ? radius : defaultValue; + D_DC(DPlatformTheme); + return d->platformInterface->windowRadius(defaultValue); } QByteArray DPlatformTheme::themeName() const { - FETCH_PROPERTY("Net/ThemeName", themeName) - - return value.toByteArray(); + D_DC(DPlatformTheme); + return d->platformInterface->themeName(); } QByteArray DPlatformTheme::iconThemeName() const { - FETCH_PROPERTY("Net/IconThemeName", iconThemeName) - - return value.toByteArray(); + D_DC(DPlatformTheme); + return d->platformInterface->iconThemeName(); } QByteArray DPlatformTheme::soundThemeName() const { - FETCH_PROPERTY("Net/SoundThemeName", soundThemeName) - - return value.toByteArray(); + D_DC(DPlatformTheme); + return d->platformInterface->soundThemeName(); } QByteArray DPlatformTheme::fontName() const { - FETCH_PROPERTY("Qt/FontName", fontName) - - return value.toByteArray(); + D_DC(DPlatformTheme); + return d->platformInterface->fontName(); } QByteArray DPlatformTheme::monoFontName() const { - FETCH_PROPERTY("Qt/MonoFontName", monoFontName) - - return value.toByteArray(); + D_DC(DPlatformTheme); + return d->platformInterface->monoFontName(); } qreal DPlatformTheme::fontPointSize() const { - FETCH_PROPERTY("Qt/FontPointSize", fontPointSize) - - return value.toDouble(); + D_DC(DPlatformTheme); + return d->platformInterface->fontPointSize(); } QByteArray DPlatformTheme::gtkFontName() const { - FETCH_PROPERTY("Gtk/FontName", gtkFontName) - - return value.toByteArray(); + D_DC(DPlatformTheme); + return d->platformInterface->gtkFontName(); } QColor DPlatformTheme::activeColor() const { - FETCH_PROPERTY("Qt/ActiveColor", activeColor) - - return qvariant_cast(value); + D_DC(DPlatformTheme); + return d->platformInterface->activeColor(); } QColor DPlatformTheme::darkActiveColor() const { - FETCH_PROPERTY("Qt/DarkActiveColor", darkActiveColor) - - return qvariant_cast(value); + D_DC(DPlatformTheme); + return d->platformInterface->darkActiveColor(); } bool DPlatformTheme::isValidPalette() const @@ -477,155 +444,171 @@ bool DPlatformTheme::isValidPalette() const #if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) QColor DPlatformTheme::window() const { - return GET_COLOR(window); + D_DC(DPlatformTheme); + return d->platformInterface->window(); } QColor DPlatformTheme::windowText() const { - return GET_COLOR(windowText); + D_DC(DPlatformTheme); + return d->platformInterface->windowText(); } QColor DPlatformTheme::base() const { - return GET_COLOR(base); + D_DC(DPlatformTheme); + return d->platformInterface->base(); } QColor DPlatformTheme::alternateBase() const { - return GET_COLOR(alternateBase); + D_DC(DPlatformTheme); + return d->platformInterface->alternateBase(); } QColor DPlatformTheme::toolTipBase() const { - return GET_COLOR(toolTipBase); + D_DC(DPlatformTheme); + return d->platformInterface->toolTipBase(); } QColor DPlatformTheme::toolTipText() const { - return GET_COLOR(toolTipText); + D_DC(DPlatformTheme); + return d->platformInterface->toolTipText(); } QColor DPlatformTheme::text() const { - return GET_COLOR(text); + D_DC(DPlatformTheme); + return d->platformInterface->text(); } QColor DPlatformTheme::button() const { - return GET_COLOR(button); + D_DC(DPlatformTheme); + return d->platformInterface->button(); } QColor DPlatformTheme::buttonText() const { - return GET_COLOR(buttonText); + D_DC(DPlatformTheme); + return d->platformInterface->buttonText(); } QColor DPlatformTheme::brightText() const { - return GET_COLOR(brightText); + D_DC(DPlatformTheme); + return d->platformInterface->brightText(); } QColor DPlatformTheme::light() const { - return GET_COLOR(light); + D_DC(DPlatformTheme); + return d->platformInterface->light(); } QColor DPlatformTheme::midlight() const { - return GET_COLOR(midlight); + D_DC(DPlatformTheme); + return d->platformInterface->midlight(); } QColor DPlatformTheme::dark() const { - return GET_COLOR(dark); + D_DC(DPlatformTheme); + return d->platformInterface->dark(); } QColor DPlatformTheme::mid() const { - return GET_COLOR(mid); + D_DC(DPlatformTheme); + return d->platformInterface->mid(); } QColor DPlatformTheme::shadow() const { - return GET_COLOR(shadow); + D_DC(DPlatformTheme); + return d->platformInterface->shadow(); } QColor DPlatformTheme::highlight() const { - return GET_COLOR(highlight); + D_DC(DPlatformTheme); + return d->platformInterface->highlight(); } QColor DPlatformTheme::highlightedText() const { - return GET_COLOR(highlightedText); + D_DC(DPlatformTheme); + return d->platformInterface->highlightedText(); } QColor DPlatformTheme::link() const { - return GET_COLOR(link); + D_DC(DPlatformTheme); + return d->platformInterface->link(); } QColor DPlatformTheme::linkVisited() const { - return GET_COLOR(linkVisited); + D_DC(DPlatformTheme); + return d->platformInterface->linkVisited(); } QColor DPlatformTheme::itemBackground() const { - return GET_COLOR(itemBackground); + D_DC(DPlatformTheme); + return d->platformInterface->itemBackground(); } QColor DPlatformTheme::textTitle() const { - return GET_COLOR(textTitle); + D_DC(DPlatformTheme); + return d->platformInterface->textTitle(); } QColor DPlatformTheme::textTips() const { - return GET_COLOR(textTips); + D_DC(DPlatformTheme); + return d->platformInterface->textTips(); } QColor DPlatformTheme::textWarning() const { - return GET_COLOR(textWarning); + D_DC(DPlatformTheme); + return d->platformInterface->textWarning(); } QColor DPlatformTheme::textLively() const { - return GET_COLOR(textLively); + D_DC(DPlatformTheme); + return d->platformInterface->textLively(); } QColor DPlatformTheme::lightLively() const { - return GET_COLOR(lightLively); + D_DC(DPlatformTheme); + return d->platformInterface->lightLively(); } QColor DPlatformTheme::darkLively() const { - return GET_COLOR(darkLively); + D_DC(DPlatformTheme); + return d->platformInterface->darkLively(); } QColor DPlatformTheme::frameBorder() const { - return GET_COLOR(frameBorder); + D_DC(DPlatformTheme); + return d->platformInterface->frameBorder(); } #endif int DPlatformTheme::dotsPerInch(const QString &screenName) const { - bool ok = false; - - if (!screenName.isEmpty()) { - FETCH_PROPERTY_WITH_ARGS("Qt/DPI/" + screenName.toLocal8Bit(), dotsPerInch, screenName); - int dpi = value.toInt(&ok); - - if (ok) - return dpi; - } - - FETCH_PROPERTY_WITH_ARGS("Xft/DPI", dotsPerInch, screenName); - int dpi = value.toInt(&ok); - return ok ? dpi : -1; + D_DC(DPlatformTheme); + return d->platformInterface->dotsPerInch(screenName); } /*! @@ -635,8 +618,7 @@ int DPlatformTheme::dotsPerInch(const QString &screenName) const int DPlatformTheme::sizeMode() const { D_DC(DPlatformTheme); - QVariant value = d->theme->getSetting(QByteArrayLiteral("DTK/SizeMode")); - return value.toInt(); + return d->platformInterface->sizeMode(); } /*! @@ -648,270 +630,275 @@ int DPlatformTheme::sizeMode() const */ int DPlatformTheme::scrollBarPolicy() const { - FETCH_PROPERTY("Qt/ScrollBarPolicy", scrollBarPolicy) - - return qvariant_cast(value); + D_DC(DPlatformTheme); + return d->platformInterface->scrollBarPolicy(); } void DPlatformTheme::setCursorBlinkTime(int cursorBlinkTime) { - D_D(DPlatformTheme); - - d->theme->setSetting("Net/CursorBlinkTime", cursorBlinkTime); + D_DC(DPlatformTheme); + return d->platformInterface->setCursorBlinkTime(cursorBlinkTime); } void DPlatformTheme::setCursorBlinkTimeout(int cursorBlinkTimeout) { - D_D(DPlatformTheme); - - d->theme->setSetting("Net/CursorBlinkTimeout", cursorBlinkTimeout); + D_DC(DPlatformTheme); + return d->platformInterface->setCursorBlinkTimeout(cursorBlinkTimeout); } void DPlatformTheme::setCursorBlink(bool cursorBlink) { - D_D(DPlatformTheme); - - d->theme->setSetting("Net/CursorBlink", cursorBlink); + D_DC(DPlatformTheme); + return d->platformInterface->setCursorBlink(cursorBlink); } void DPlatformTheme::setDoubleClickDistance(int doubleClickDistance) { - D_D(DPlatformTheme); - - d->theme->setSetting("Net/DoubleClickDistance", doubleClickDistance); + D_DC(DPlatformTheme); + return d->platformInterface->setDoubleClickDistance(doubleClickDistance); } void DPlatformTheme::setDoubleClickTime(int doubleClickTime) { - D_D(DPlatformTheme); - - d->theme->setSetting("Net/DoubleClickTime", doubleClickTime); + D_DC(DPlatformTheme); + return d->platformInterface->setDoubleClickTime(doubleClickTime); } void DPlatformTheme::setDndDragThreshold(int dndDragThreshold) { - D_D(DPlatformTheme); - - d->theme->setSetting("Net/DndDragThreshold", dndDragThreshold); + D_DC(DPlatformTheme); + return d->platformInterface->setDndDragThreshold(dndDragThreshold); } void DPlatformTheme::setThemeName(const QByteArray &themeName) { - D_D(DPlatformTheme); - - d->theme->setSetting("Net/ThemeName", themeName); + D_DC(DPlatformTheme); + return d->platformInterface->setThemeName(themeName); } void DPlatformTheme::setIconThemeName(const QByteArray &iconThemeName) { - D_D(DPlatformTheme); - - d->theme->setSetting("Net/IconThemeName", iconThemeName); + D_DC(DPlatformTheme); + return d->platformInterface->setIconThemeName(iconThemeName); } void DPlatformTheme::setSoundThemeName(const QByteArray &soundThemeName) { - D_D(DPlatformTheme); - - d->theme->setSetting("Net/SoundThemeName", soundThemeName); + D_DC(DPlatformTheme); + return d->platformInterface->setSoundThemeName(soundThemeName); } void DPlatformTheme::setFontName(const QByteArray &fontName) { - D_D(DPlatformTheme); - - d->theme->setSetting("Qt/FontName", fontName); + D_DC(DPlatformTheme); + return d->platformInterface->setFontName(fontName); } void DPlatformTheme::setMonoFontName(const QByteArray &monoFontName) { - D_D(DPlatformTheme); - - d->theme->setSetting("Qt/MonoFontName", monoFontName); + D_DC(DPlatformTheme); + return d->platformInterface->setMonoFontName(monoFontName); } void DPlatformTheme::setFontPointSize(qreal fontPointSize) { - D_D(DPlatformTheme); - - d->theme->setSetting("Qt/FontPointSize", fontPointSize); + D_DC(DPlatformTheme); + return d->platformInterface->setFontPointSize(fontPointSize); } void DPlatformTheme::setGtkFontName(const QByteArray &fontName) { - D_D(DPlatformTheme); - - d->theme->setSetting("Gtk/FontName", fontName); + D_DC(DPlatformTheme); + return d->platformInterface->setGtkFontName(fontName); } void DPlatformTheme::setActiveColor(const QColor activeColor) { - D_D(DPlatformTheme); - - d->theme->setSetting("Qt/ActiveColor", activeColor); + D_DC(DPlatformTheme); + return d->platformInterface->setActiveColor(activeColor); } void DPlatformTheme::setDarkActiveColor(const QColor &activeColor) { - D_D(DPlatformTheme); - - d->theme->setSetting("Qt/DarkActiveColor", activeColor); + D_DC(DPlatformTheme); + return d->platformInterface->setDarkActiveColor(activeColor); } #define SET_COLOR(Role) setSetting(QByteArrayLiteral(#Role), Role) #if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) void DPlatformTheme::setWindow(const QColor &window) { - SET_COLOR(window); + D_DC(DPlatformTheme); + return d->platformInterface->setWindow(window); } void DPlatformTheme::setWindowText(const QColor &windowText) { - SET_COLOR(windowText); + D_DC(DPlatformTheme); + return d->platformInterface->setWindowText(windowText); } void DPlatformTheme::setBase(const QColor &base) { - SET_COLOR(base); + D_DC(DPlatformTheme); + return d->platformInterface->setBase(base); } void DPlatformTheme::setAlternateBase(const QColor &alternateBase) { - SET_COLOR(alternateBase); + D_DC(DPlatformTheme); + return d->platformInterface->setAlternateBase(alternateBase); } void DPlatformTheme::setToolTipBase(const QColor &toolTipBase) { - SET_COLOR(toolTipBase); + D_DC(DPlatformTheme); + return d->platformInterface->setToolTipBase(toolTipBase); } void DPlatformTheme::setToolTipText(const QColor &toolTipText) { - SET_COLOR(toolTipText); + D_DC(DPlatformTheme); + return d->platformInterface->setToolTipText(toolTipText); } void DPlatformTheme::setText(const QColor &text) { - SET_COLOR(text); + D_DC(DPlatformTheme); + return d->platformInterface->setText(text); } void DPlatformTheme::setButton(const QColor &button) { - SET_COLOR(button); + D_DC(DPlatformTheme); + return d->platformInterface->setButton(button); } void DPlatformTheme::setButtonText(const QColor &buttonText) { - SET_COLOR(buttonText); + D_DC(DPlatformTheme); + return d->platformInterface->setButtonText(buttonText); } void DPlatformTheme::setBrightText(const QColor &brightText) { - SET_COLOR(brightText); + D_DC(DPlatformTheme); + return d->platformInterface->setBrightText(brightText); } void DPlatformTheme::setLight(const QColor &light) { - SET_COLOR(light); + D_DC(DPlatformTheme); + return d->platformInterface->setLight(light); } void DPlatformTheme::setMidlight(const QColor &midlight) { - SET_COLOR(midlight); + D_DC(DPlatformTheme); + return d->platformInterface->setMidlight(midlight); } void DPlatformTheme::setDark(const QColor &dark) { - SET_COLOR(dark); + D_DC(DPlatformTheme); + return d->platformInterface->setDark(dark); } void DPlatformTheme::setMid(const QColor &mid) { - SET_COLOR(mid); + D_DC(DPlatformTheme); + return d->platformInterface->setMid(mid); } void DPlatformTheme::setShadow(const QColor &shadow) { - SET_COLOR(shadow); + D_DC(DPlatformTheme); + return d->platformInterface->setShadow(shadow); } void DPlatformTheme::setHighlight(const QColor &highlight) { - SET_COLOR(highlight); + D_DC(DPlatformTheme); + return d->platformInterface->setHighlight(highlight); } void DPlatformTheme::setHighlightedText(const QColor &highlightText) { - SET_COLOR(highlightText); + D_DC(DPlatformTheme); + return d->platformInterface->setHighlightedText(highlightText); } void DPlatformTheme::setLink(const QColor &link) { - SET_COLOR(link); + D_DC(DPlatformTheme); + return d->platformInterface->setLink(link); } void DPlatformTheme::setLinkVisited(const QColor &linkVisited) { - SET_COLOR(linkVisited); + D_DC(DPlatformTheme); + return d->platformInterface->setLinkVisited(linkVisited); } void DPlatformTheme::setItemBackground(const QColor &itemBackground) { - SET_COLOR(itemBackground); + D_DC(DPlatformTheme); + return d->platformInterface->setItemBackground(itemBackground); } void DPlatformTheme::setTextTitle(const QColor &textTitle) { - SET_COLOR(textTitle); + D_DC(DPlatformTheme); + return d->platformInterface->setTextTitle(textTitle); } void DPlatformTheme::setTextTips(const QColor &textTips) { - SET_COLOR(textTips); + D_DC(DPlatformTheme); + return d->platformInterface->setTextTips(textTips); } void DPlatformTheme::setTextWarning(const QColor &textWarning) { - SET_COLOR(textWarning); + D_DC(DPlatformTheme); + return d->platformInterface->setTextWarning(textWarning); } void DPlatformTheme::setTextLively(const QColor &textLively) { - SET_COLOR(textLively); + D_DC(DPlatformTheme); + return d->platformInterface->setTextLively(textLively); } void DPlatformTheme::setLightLively(const QColor &lightLively) { - SET_COLOR(lightLively); + D_DC(DPlatformTheme); + return d->platformInterface->setLightLively(lightLively); } void DPlatformTheme::setDarkLively(const QColor &darkLively) { - SET_COLOR(darkLively); + D_DC(DPlatformTheme); + return d->platformInterface->setDarkLively(darkLively); } void DPlatformTheme::setFrameBorder(const QColor &frameBorder) { - SET_COLOR(frameBorder); + D_DC(DPlatformTheme); + return d->platformInterface->setFrameBorder(frameBorder); } #endif void DPlatformTheme::setDotsPerInch(const QString &screenName, int dpi) { - D_D(DPlatformTheme); - - if (screenName.isEmpty()) { - d->theme->setSetting("Xft/DPI", dpi); - } else { - d->theme->setSetting("Qt/DPI/" + screenName.toLocal8Bit(), dpi); - } + D_DC(DPlatformTheme); + return d->platformInterface->setDotsPerInch(screenName, dpi); } void DPlatformTheme::setWindowRadius(int windowRadius) { - D_D(DPlatformTheme); - - d->theme->setSetting("DTK/WindowRadius", windowRadius); + D_DC(DPlatformTheme); + return d->platformInterface->setWindowRadius(windowRadius); } DGUI_END_NAMESPACE diff --git a/src/plugins/dplatforminterface.cpp b/src/plugins/dplatforminterface.cpp new file mode 100644 index 0000000..61d81e9 --- /dev/null +++ b/src/plugins/dplatforminterface.cpp @@ -0,0 +1,498 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dplatforminterface.h" +#include "private/dplatforminterface_p.h" + +DGUI_BEGIN_NAMESPACE +DPlatformInterfacePrivate::DPlatformInterfacePrivate(DPlatformInterface *qq) + : DObjectPrivate(qq) + +{ + +} + +DPlatformInterfacePrivate::~DPlatformInterfacePrivate() +{ + +} + +DPlatformInterface::DPlatformInterface(QObject *parent) + : DPlatformInterface(*new DPlatformInterfacePrivate(this), parent) +{ + +} + +DPlatformInterface::~DPlatformInterface() +{ + +} + +DPlatformInterface::DPlatformInterface(DPlatformInterfacePrivate &dd, QObject *parent) + : QObject(parent) + , DObject(dd) +{ + +} + +int DPlatformInterface::cursorBlinkTime() const +{ + return {}; +} + +int DPlatformInterface::cursorBlinkTimeout() const +{ + return {}; +} + +bool DPlatformInterface::cursorBlink() const +{ + return {}; +} + +int DPlatformInterface::doubleClickDistance() const +{ + return {}; +} + +int DPlatformInterface::doubleClickTime() const +{ + return {}; +} + +int DPlatformInterface::dndDragThreshold() const +{ + return {}; +} + +int DPlatformInterface::windowRadius() const +{ + return {}; +} + +int DPlatformInterface::windowRadius(int) const +{ + return {}; +} + +QByteArray DPlatformInterface::themeName() const +{ + return {}; +} + +QByteArray DPlatformInterface::iconThemeName() const +{ + return {}; +} + +QByteArray DPlatformInterface::soundThemeName() const +{ + return {}; +} + +QByteArray DPlatformInterface::fontName() const +{ + return {}; +} + +QByteArray DPlatformInterface::monoFontName() const +{ + return {}; +} + +qreal DPlatformInterface::fontPointSize() const +{ + return {}; +} + +QByteArray DPlatformInterface::gtkFontName() const +{ + return {}; +} + +QColor DPlatformInterface::activeColor() const +{ + return {}; +} + +QColor DPlatformInterface::darkActiveColor() const +{ + return {}; +} + +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) +QColor DPlatformInterface::window() const +{ + return {}; +} + +QColor DPlatformInterface::windowText() const +{ + return {}; +} + +QColor DPlatformInterface::base() const +{ + return {}; +} + +QColor DPlatformInterface::alternateBase() const +{ + return {}; +} + +QColor DPlatformInterface::toolTipBase() const +{ + return {}; +} + +QColor DPlatformInterface::toolTipText() const +{ + return {}; +} + +QColor DPlatformInterface::text() const +{ + return {}; +} + +QColor DPlatformInterface::button() const +{ + return {}; +} + +QColor DPlatformInterface::buttonText() const +{ + return {}; +} + +QColor DPlatformInterface::brightText() const +{ + return {}; +} + +QColor DPlatformInterface::light() const +{ + return {}; +} + +QColor DPlatformInterface::midlight() const +{ + return {}; +} + +QColor DPlatformInterface::dark() const +{ + return {}; +} + +QColor DPlatformInterface::mid() const +{ + return {}; +} + +QColor DPlatformInterface::shadow() const +{ + return {}; +} + +QColor DPlatformInterface::highlight() const +{ + return {}; +} + +QColor DPlatformInterface::highlightedText() const +{ + return {}; +} + +QColor DPlatformInterface::link() const +{ + return {}; +} + +QColor DPlatformInterface::linkVisited() const +{ + return {}; +} + +QColor DPlatformInterface::itemBackground() const +{ + return {}; +} + +QColor DPlatformInterface::textTitle() const +{ + return {}; +} + +QColor DPlatformInterface::textTips() const +{ + return {}; +} + +QColor DPlatformInterface::textWarning() const +{ + return {}; +} + +QColor DPlatformInterface::textLively() const +{ + return {}; +} + +QColor DPlatformInterface::lightLively() const +{ + return {}; +} + +QColor DPlatformInterface::darkLively() const +{ + return {}; +} + +QColor DPlatformInterface::frameBorder() const +{ + return {}; +} +#endif + +int DPlatformInterface::dotsPerInch(const QString &) const +{ + return {}; +} + +int DPlatformInterface::sizeMode() const +{ + return {}; +} + +int DPlatformInterface::scrollBarPolicy() const +{ + return {}; +} + +void DPlatformInterface::setCursorBlinkTime(int) +{ + +} + +void DPlatformInterface::setCursorBlinkTimeout(int) +{ + +} + +void DPlatformInterface::setCursorBlink(bool) +{ + +} + +void DPlatformInterface::setDoubleClickDistance(int) +{ + +} + +void DPlatformInterface::setDoubleClickTime(int) +{ + +} + +void DPlatformInterface::setDndDragThreshold(int) +{ + +} + +void DPlatformInterface::setThemeName(const QByteArray &) +{ + +} + +void DPlatformInterface::setIconThemeName(const QByteArray &) +{ + +} + +void DPlatformInterface::setSoundThemeName(const QByteArray &) +{ + +} + +void DPlatformInterface::setFontName(const QByteArray &) +{ + +} + +void DPlatformInterface::setMonoFontName(const QByteArray &) +{ + +} + +void DPlatformInterface::setFontPointSize(qreal) +{ + +} + +void DPlatformInterface::setGtkFontName(const QByteArray &) +{ + +} + +void DPlatformInterface::setActiveColor(const QColor) +{ + +} + +void DPlatformInterface::setDarkActiveColor(const QColor &) +{ + +} + +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) +void DPlatformInterface::setWindow(const QColor &) +{ + +} + +void DPlatformInterface::setWindowText(const QColor &) +{ + +} + +void DPlatformInterface::setBase(const QColor &) +{ + +} + +void DPlatformInterface::setAlternateBase(const QColor &) +{ + +} + +void DPlatformInterface::setToolTipBase(const QColor &) +{ + +} + +void DPlatformInterface::setToolTipText(const QColor &) +{ + +} + +void DPlatformInterface::setText(const QColor &) +{ + +} + +void DPlatformInterface::setButton(const QColor &) +{ + +} + +void DPlatformInterface::setButtonText(const QColor &) +{ + +} + +void DPlatformInterface::setBrightText(const QColor &) +{ + +} + +void DPlatformInterface::setLight(const QColor &) +{ + +} + +void DPlatformInterface::setMidlight(const QColor &) +{ + +} + +void DPlatformInterface::setDark(const QColor &) +{ + +} + +void DPlatformInterface::setMid(const QColor &) +{ + +} + +void DPlatformInterface::setShadow(const QColor &) +{ + +} + +void DPlatformInterface::setHighlight(const QColor &) +{ + +} + +void DPlatformInterface::setHighlightedText(const QColor &) +{ + +} + +void DPlatformInterface::setLink(const QColor &) +{ + +} + +void DPlatformInterface::setLinkVisited(const QColor &) +{ + +} + +void DPlatformInterface::setItemBackground(const QColor &) +{ + +} + +void DPlatformInterface::setTextTitle(const QColor &) +{ + +} + +void DPlatformInterface::setTextTips(const QColor &) +{ + +} + +void DPlatformInterface::setTextWarning(const QColor &) +{ + +} + +void DPlatformInterface::setTextLively(const QColor &) +{ + +} + +void DPlatformInterface::setLightLively(const QColor &) +{ + +} + +void DPlatformInterface::setDarkLively(const QColor &) +{ + +} + +void DPlatformInterface::setFrameBorder(const QColor &) +{ + +} +#endif + +void DPlatformInterface::setDotsPerInch(const QString &, int) +{ + +} + +void DPlatformInterface::setWindowRadius(int) +{ + +} + +DGUI_END_NAMESPACE diff --git a/src/plugins/dplatforminterface.h b/src/plugins/dplatforminterface.h new file mode 100644 index 0000000..c54519a --- /dev/null +++ b/src/plugins/dplatforminterface.h @@ -0,0 +1,241 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DPLATFORMINTERFACE_H +#define DPLATFORMINTERFACE_H + +#include +#include +#include + +#include +#include + +#include "dtkgui_global.h" + +DGUI_BEGIN_NAMESPACE + +class DPlatformInterfacePrivate; +class DPlatformInterface : public QObject, public DCORE_NAMESPACE::DObject +{ + Q_OBJECT + D_DECLARE_PRIVATE(DPlatformInterface) + + Q_PROPERTY(int cursorBlinkTime READ cursorBlinkTime WRITE setCursorBlinkTime NOTIFY cursorBlinkTimeChanged) + Q_PROPERTY(int cursorBlinkTimeout READ cursorBlinkTimeout WRITE setCursorBlinkTimeout NOTIFY cursorBlinkTimeoutChanged) + Q_PROPERTY(bool cursorBlink READ cursorBlink WRITE setCursorBlink NOTIFY cursorBlinkChanged) + Q_PROPERTY(int doubleClickDistance READ doubleClickDistance WRITE setDoubleClickDistance NOTIFY doubleClickDistanceChanged) + Q_PROPERTY(int doubleClickTime READ doubleClickTime WRITE setDoubleClickTime NOTIFY doubleClickTimeChanged) + Q_PROPERTY(int dndDragThreshold READ dndDragThreshold WRITE setDndDragThreshold NOTIFY dndDragThresholdChanged) + Q_PROPERTY(int windowRadius READ windowRadius WRITE setWindowRadius NOTIFY windowRadiusChanged) + Q_PROPERTY(QByteArray themeName READ themeName WRITE setThemeName NOTIFY themeNameChanged) + Q_PROPERTY(QByteArray iconThemeName READ iconThemeName WRITE setIconThemeName NOTIFY iconThemeNameChanged) + Q_PROPERTY(QByteArray soundThemeName READ soundThemeName WRITE setSoundThemeName NOTIFY soundThemeNameChanged) + // Font + Q_PROPERTY(QByteArray fontName READ fontName WRITE setFontName NOTIFY fontNameChanged) + Q_PROPERTY(QByteArray monoFontName READ monoFontName WRITE setMonoFontName NOTIFY monoFontNameChanged) + Q_PROPERTY(qreal fontPointSize READ fontPointSize WRITE setFontPointSize NOTIFY fontPointSizeChanged) + Q_PROPERTY(QByteArray gtkFontName READ gtkFontName WRITE setGtkFontName NOTIFY gtkFontNameChanged) + + Q_PROPERTY(QColor activeColor READ activeColor WRITE setActiveColor NOTIFY activeColorChanged) + Q_PROPERTY(QColor darkActiveColor READ darkActiveColor WRITE setDarkActiveColor NOTIFY darkActiveColorChanged) +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) + // QPalette + Q_PROPERTY(QColor window READ window WRITE setWindow NOTIFY windowChanged) + Q_PROPERTY(QColor windowText READ windowText WRITE setWindowText NOTIFY windowTextChanged) + Q_PROPERTY(QColor base READ base WRITE setBase NOTIFY baseChanged) + Q_PROPERTY(QColor alternateBase READ alternateBase WRITE setAlternateBase NOTIFY alternateBaseChanged) + Q_PROPERTY(QColor toolTipBase READ toolTipBase WRITE setToolTipBase NOTIFY toolTipBaseChanged) + Q_PROPERTY(QColor toolTipText READ toolTipText WRITE setToolTipText NOTIFY toolTipTextChanged) + Q_PROPERTY(QColor text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QColor button READ button WRITE setButton NOTIFY buttonChanged) + Q_PROPERTY(QColor buttonText READ buttonText WRITE setButtonText NOTIFY buttonTextChanged) + Q_PROPERTY(QColor brightText READ brightText WRITE setBrightText NOTIFY brightTextChanged) + Q_PROPERTY(QColor light READ light WRITE setLight NOTIFY lightChanged) + Q_PROPERTY(QColor midlight READ midlight WRITE setMidlight NOTIFY midlightChanged) + Q_PROPERTY(QColor dark READ dark WRITE setDark NOTIFY darkChanged) + Q_PROPERTY(QColor mid READ mid WRITE setMid NOTIFY midChanged) + Q_PROPERTY(QColor shadow READ shadow WRITE setShadow NOTIFY shadowChanged) + Q_PROPERTY(QColor highlight READ highlight WRITE setHighlight NOTIFY highlightChanged) + Q_PROPERTY(QColor highlightedText READ highlightedText WRITE setHighlightedText NOTIFY highlightedTextChanged) + Q_PROPERTY(QColor link READ link WRITE setLink NOTIFY linkChanged) + Q_PROPERTY(QColor linkVisited READ linkVisited WRITE setLinkVisited NOTIFY linkVisitedChanged) + // DPalette + Q_PROPERTY(QColor itemBackground READ itemBackground WRITE setItemBackground NOTIFY itemBackgroundChanged) + Q_PROPERTY(QColor textTitle READ textTitle WRITE setTextTitle NOTIFY textTitleChanged) + Q_PROPERTY(QColor textTips READ textTips WRITE setTextTips NOTIFY textTipsChanged) + Q_PROPERTY(QColor textWarning READ textWarning WRITE setTextWarning NOTIFY textWarningChanged) + Q_PROPERTY(QColor textLively READ textLively WRITE setTextLively NOTIFY textLivelyChanged) + Q_PROPERTY(QColor lightLively READ lightLively WRITE setLightLively NOTIFY lightLivelyChanged) + Q_PROPERTY(QColor darkLively READ darkLively WRITE setDarkLively NOTIFY darkLivelyChanged) + Q_PROPERTY(QColor frameBorder READ frameBorder WRITE setFrameBorder NOTIFY frameBorderChanged) +#endif + // DSizeMode + Q_PROPERTY(int sizeMode READ sizeMode NOTIFY sizeModeChanged) + Q_PROPERTY(int scrollBarPolicy READ scrollBarPolicy NOTIFY scrollBarPolicyChanged) + +public: + explicit DPlatformInterface(QObject *parent); + virtual ~DPlatformInterface(); + + virtual int cursorBlinkTime() const; + virtual int cursorBlinkTimeout() const; + virtual bool cursorBlink() const; + virtual int doubleClickDistance() const; + virtual int doubleClickTime() const; + virtual int dndDragThreshold() const; + virtual int windowRadius() const; + virtual int windowRadius(int defaultValue) const; + virtual QByteArray themeName() const; + virtual QByteArray iconThemeName() const; + virtual QByteArray soundThemeName() const; + + virtual QByteArray fontName() const; + virtual QByteArray monoFontName() const; + virtual qreal fontPointSize() const; + virtual QByteArray gtkFontName() const; + + virtual QColor activeColor() const; + virtual QColor darkActiveColor() const; + +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) + virtual QColor window() const; + virtual QColor windowText() const; + virtual QColor base() const; + virtual QColor alternateBase() const; + virtual QColor toolTipBase() const; + virtual QColor toolTipText() const; + virtual QColor text() const; + virtual QColor button() const; + virtual QColor buttonText() const; + virtual QColor brightText() const; + virtual QColor light() const; + virtual QColor midlight() const; + virtual QColor dark() const; + virtual QColor mid() const; + virtual QColor shadow() const; + virtual QColor highlight() const; + virtual QColor highlightedText() const; + virtual QColor link() const; + virtual QColor linkVisited() const; + virtual QColor itemBackground() const; + virtual QColor textTitle() const; + virtual QColor textTips() const; + virtual QColor textWarning() const; + virtual QColor textLively() const; + virtual QColor lightLively() const; + virtual QColor darkLively() const; + virtual QColor frameBorder() const; +#endif + + virtual int sizeMode() const; + virtual int scrollBarPolicy() const; + +public Q_SLOTS: + virtual void setCursorBlinkTime(int cursorBlinkTime); + virtual void setCursorBlinkTimeout(int cursorBlinkTimeout); + virtual void setCursorBlink(bool cursorBlink); + virtual void setDoubleClickDistance(int doubleClickDistance); + virtual void setDoubleClickTime(int doubleClickTime); + virtual void setDndDragThreshold(int dndDragThreshold); + virtual void setThemeName(const QByteArray &themeName); + virtual void setIconThemeName(const QByteArray &iconThemeName); + virtual void setSoundThemeName(const QByteArray &soundThemeName); + virtual void setFontName(const QByteArray &fontName); + virtual void setMonoFontName(const QByteArray &monoFontName); + virtual void setFontPointSize(qreal fontPointSize); + virtual void setGtkFontName(const QByteArray &fontName); + virtual void setActiveColor(const QColor activeColor); + virtual void setDarkActiveColor(const QColor &activeColor); +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) + virtual void setWindow(const QColor &window); + virtual void setWindowText(const QColor &windowText); + virtual void setBase(const QColor &base); + virtual void setAlternateBase(const QColor &alternateBase); + virtual void setToolTipBase(const QColor &toolTipBase); + virtual void setToolTipText(const QColor &toolTipText); + virtual void setText(const QColor &text); + virtual void setButton(const QColor &button); + virtual void setButtonText(const QColor &buttonText); + virtual void setBrightText(const QColor &brightText); + virtual void setLight(const QColor &light); + virtual void setMidlight(const QColor &midlight); + virtual void setDark(const QColor &dark); + virtual void setMid(const QColor &mid); + virtual void setShadow(const QColor &shadow); + virtual void setHighlight(const QColor &highlight); + virtual void setHighlightedText(const QColor &highlightedText); + virtual void setLink(const QColor &link); + virtual void setLinkVisited(const QColor &linkVisited); + virtual void setItemBackground(const QColor &itemBackground); + virtual void setTextTitle(const QColor &textTitle); + virtual void setTextTips(const QColor &textTips); + virtual void setTextWarning(const QColor &textWarning); + virtual void setTextLively(const QColor &textLively); + virtual void setLightLively(const QColor &lightLively); + virtual void setDarkLively(const QColor &darkLively); + virtual void setFrameBorder(const QColor &frameBorder); +#endif + + virtual int dotsPerInch(const QString &screenName = QString()) const; + virtual void setDotsPerInch(const QString &screenName, int dpi); + virtual void setWindowRadius(int windowRadius); + +Q_SIGNALS: + void cursorBlinkTimeChanged(int cursorBlinkTime); + void cursorBlinkTimeoutChanged(int cursorBlinkTimeout); + void cursorBlinkChanged(bool cursorBlink); + void doubleClickDistanceChanged(int doubleClickDistance); + void doubleClickTimeChanged(int doubleClickTime); + void dndDragThresholdChanged(int dndDragThreshold); + void themeNameChanged(QByteArray themeName); + void iconThemeNameChanged(QByteArray iconThemeName); + void soundThemeNameChanged(QByteArray soundThemeName); + void fontNameChanged(QByteArray fontName); + void monoFontNameChanged(QByteArray monoFontName); + void fontPointSizeChanged(qreal fontPointSize); + void gtkFontNameChanged(QByteArray fontName); + void activeColorChanged(QColor activeColor); + void darkActiveColorChanged(QColor activeColor); + void paletteChanged(DPalette palette); +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) + void windowChanged(QColor window); + void windowTextChanged(QColor windowText); + void baseChanged(QColor base); + void alternateBaseChanged(QColor alternateBase); + void toolTipBaseChanged(QColor toolTipBase); + void toolTipTextChanged(QColor toolTipText); + void textChanged(QColor text); + void buttonChanged(QColor button); + void buttonTextChanged(QColor buttonText); + void brightTextChanged(QColor brightText); + void lightChanged(QColor light); + void midlightChanged(QColor midlight); + void darkChanged(QColor dark); + void midChanged(QColor mid); + void shadowChanged(QColor shadow); + void highlightChanged(QColor highlight); + void highlightedTextChanged(QColor highlightedText); + void linkChanged(QColor link); + void linkVisitedChanged(QColor linkVisited); + void itemBackgroundChanged(QColor itemBackground); + void textTitleChanged(QColor textTitle); + void textTipsChanged(QColor textTips); + void textWarningChanged(QColor textWarning); + void textLivelyChanged(QColor textLively); + void lightLivelyChanged(QColor lightLively); + void darkLivelyChanged(QColor darkLively); + void frameBorderChanged(QColor frameBorder); +#endif + void dotsPerInchChanged(const QString &screen, int dpi); + void windowRadiusChanged(int r); + void sizeModeChanged(int sizeMode); + void scrollBarPolicyChanged(int scrollBarPolicy); + +protected: + DPlatformInterface(DPlatformInterfacePrivate &dd, QObject *parent); +}; + +DGUI_END_NAMESPACE +#endif diff --git a/src/plugins/platform/treeland/dtreelandplatforminterface.cpp b/src/plugins/platform/treeland/dtreelandplatforminterface.cpp new file mode 100644 index 0000000..55eda18 --- /dev/null +++ b/src/plugins/platform/treeland/dtreelandplatforminterface.cpp @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dtreelandplatforminterface.h" +#include "dtreelandplatforminterface_p.h" + +#include "plugins/dplatforminterface.h" + +DGUI_BEGIN_NAMESPACE +DTreelandPlatformInterfacePrivate::DTreelandPlatformInterfacePrivate(DTreelandPlatformInterface *qq) + : DPlatformInterfacePrivate(qq) +{ +} + +DGUI_END_NAMESPACE diff --git a/src/plugins/platform/treeland/dtreelandplatforminterface.h b/src/plugins/platform/treeland/dtreelandplatforminterface.h new file mode 100644 index 0000000..8774b1d --- /dev/null +++ b/src/plugins/platform/treeland/dtreelandplatforminterface.h @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DTREELANDPLATFORMINTERFACE_H +#define DTREELANDPLATFORMINTERFACE_H + +#include "plugins/dplatforminterface.h" + +DGUI_BEGIN_NAMESPACE + +class DTreelandPlatformInterfacePrivate; +class DTreelandPlatformInterface : public DPlatformInterface +{ + Q_OBJECT + D_DECLARE_PRIVATE(DTreelandPlatformInterface) +public: + explicit DTreelandPlatformInterface(QObject *parent); +}; + +DGUI_END_NAMESPACE +#endif diff --git a/src/plugins/platform/treeland/dtreelandplatforminterface_p.h b/src/plugins/platform/treeland/dtreelandplatforminterface_p.h new file mode 100644 index 0000000..6625f22 --- /dev/null +++ b/src/plugins/platform/treeland/dtreelandplatforminterface_p.h @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DTREELANDPLATFORMINTERFACE_P_H +#define DTREELANDPLATFORMINTERFACE_P_H + +#include "dtreelandplatforminterface.h" +#include "private/dplatforminterface_p.h" + +DGUI_BEGIN_NAMESPACE + +class DTreelandPlatformInterfacePrivate : public DPlatformInterfacePrivate +{ +public: + D_DECLARE_PUBLIC(DTreelandPlatformInterface) + DTreelandPlatformInterfacePrivate(DTreelandPlatformInterface *qq); + +private: +}; + +DGUI_END_NAMESPACE + +#endif // DNATIVESETTINGS_P_H diff --git a/src/plugins/platform/treeland/treeland.cmake b/src/plugins/platform/treeland/treeland.cmake new file mode 100644 index 0000000..db55e90 --- /dev/null +++ b/src/plugins/platform/treeland/treeland.cmake @@ -0,0 +1,10 @@ +file(GLOB TREELAND_HEADER + ${CMAKE_CURRENT_LIST_DIR}/*.h +) +file(GLOB TREELAND_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/*.cpp +) +set(treeland_SRC + ${TREELAND_HEADER} + ${TREELAND_SOURCE} +) diff --git a/src/plugins/platform/xcb/dxcbplatforminterface.cpp b/src/plugins/platform/xcb/dxcbplatforminterface.cpp new file mode 100644 index 0000000..bb11a04 --- /dev/null +++ b/src/plugins/platform/xcb/dxcbplatforminterface.cpp @@ -0,0 +1,706 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dxcbplatforminterface.h" +#include "dxcbplatforminterface_p.h" + +#include +#include +#include +#include +#include + +#include "dplatformtheme.h" +#include "dguiapplicationhelper.h" +#include + +DGUI_BEGIN_NAMESPACE + +#define DEFINE_CONST_CHAR(Name) const char _##Name[] = "_d_" #Name + +#define FETCH_PROPERTY(Name, Function) \ + D_DC(DXCBPlatformInterface); \ + QVariant value = d->theme->getSetting(QByteArrayLiteral(Name)); \ + if (d->fallbackProperty && !value.isValid() && d->parent) \ + return d->parent->Function(); \ + +#define FETCH_PROPERTY_WITH_ARGS(Name, Function, Args) \ + D_DC(DXCBPlatformInterface); \ + QVariant value = d->theme->getSetting(Name); \ + if (d->fallbackProperty && !value.isValid() && d->parent) \ + return d->parent->Function(Args); \ + + +DXCBPlatformInterfacePrivate::DXCBPlatformInterfacePrivate(DXCBPlatformInterface *qq) + : DPlatformInterfacePrivate(qq) +{ +} + +void DXCBPlatformInterfacePrivate::_q_onThemePropertyChanged(const QByteArray &name, const QVariant &value) +{ + D_Q(DXCBPlatformInterface); + + // 转发属性变化的信号,此信号来源可能为parent theme或“非调色板”的属性变化。 + // 使用队列的形式转发,避免多次发出同样的信号 + // q->staticMetaObject.invokeMethod(q, "propertyChanged", Qt::QueuedConnection, + // Q_ARG(const QByteArray&, name), Q_ARG(const QVariant&, value)); + + if (QByteArrayLiteral("Gtk/FontName") == name) { + Q_EMIT q->gtkFontNameChanged(value.toByteArray()); + return; + } + + if (name.startsWith("Qt/DPI/")) { + const QString &screen_name = QString::fromLocal8Bit(name.mid(7)); + + if (!screen_name.isEmpty()) { + bool ok = false; + int dpi = value.toInt(&ok); + + Q_EMIT q->dotsPerInchChanged(screen_name, ok ? dpi : -1); + } + + return; + } + + if (QByteArrayLiteral("Xft/DPI") == name) { + bool ok = false; + int dpi = value.toInt(&ok); + Q_EMIT q->dotsPerInchChanged(QString(), ok ? dpi : -1); + } + + const QByteArrayList &list = name.split('/'); + + if (list.count() != 2) + return; + + QByteArray pn = list.last(); + + if (pn.isEmpty()) + return; + + + // 转换首字母为小写 + pn[0] = QChar(pn.at(0)).toLower().toLatin1(); + + // 直接使用静态的meta object,防止通过metaObject函数调用到dynamic metaobject + const QMetaObject *mo = &DXCBPlatformInterface::staticMetaObject; + + int index = mo->indexOfProperty(pn.constData()); + + + if (index < 0) + return; + + const QMetaProperty &p = mo->property(index); + bool is_parent_signal = q->sender() != theme; + + // 当自己的属性有效时应该忽略父主题的属性变化信号,优先以自身的属性值为准。 + if (is_parent_signal && p.read(q).isValid()) { + return; + } + + if (p.hasNotifySignal()) { + // invoke会做Q_ASSERT(mobj->cast(object))判断, DPlatformTheme的dynamic metaObject为 + // qt5platform-plugin插件的DNativeSettings. 导致崩溃. + // invokeOnGadget与invoke代码逻辑一致, 只是少了异步支持. + // return; + + if (!p.notifySignal().invokeOnGadget(q, QGenericArgument(value.typeName(), value.constData()))) + qWarning() << "_q_onThemePropertyChanged() error when notify signal" << p.notifySignal().name(); + } +} + + +DXCBPlatformInterface::DXCBPlatformInterface(quint32 window, QObject *parent) + : DPlatformInterface(*new DXCBPlatformInterfacePrivate(this), parent) +{ + D_D(DXCBPlatformInterface); + + d->theme = new DNativeSettings(window, QByteArray(), this); + + connect(d->theme, SIGNAL(propertyChanged(const QByteArray &, const QVariant &)), + this, SLOT(_q_onThemePropertyChanged(const QByteArray &, const QVariant &))); +} + +int DXCBPlatformInterface::cursorBlinkTime() const +{ + FETCH_PROPERTY("Net/CursorBlinkTime", cursorBlinkTime) + + return value.toInt(); +} + +int DXCBPlatformInterface::cursorBlinkTimeout() const +{ + FETCH_PROPERTY("Net/CursorBlinkTimeout", cursorBlinkTimeout) + + return value.toInt(); +} + +bool DXCBPlatformInterface::cursorBlink() const +{ + FETCH_PROPERTY("Net/CursorBlink", cursorBlink) + + return value.toInt(); +} + +int DXCBPlatformInterface::doubleClickDistance() const +{ + FETCH_PROPERTY("Net/DoubleClickDistance", doubleClickDistance) + + return value.toInt(); +} + +int DXCBPlatformInterface::doubleClickTime() const +{ + FETCH_PROPERTY("Net/DoubleClickTime", doubleClickTime) + + return value.toInt(); +} + +int DXCBPlatformInterface::dndDragThreshold() const +{ + FETCH_PROPERTY("Net/DndDragThreshold", dndDragThreshold) + + return value.toInt(); +} + +int DXCBPlatformInterface::windowRadius() const +{ + return windowRadius(-1); +} + +int DXCBPlatformInterface::windowRadius(int defaultValue) const +{ + Q_D(const DXCBPlatformInterface); + + QVariant value = d->theme->getSetting(QByteArrayLiteral("DTK/WindowRadius")); + bool ok = false; + + if (d->fallbackProperty && !value.isValid() && d->parent) + return d->parent->windowRadius(defaultValue); + + int radius = value.toInt(&ok); + + return ok ? radius : defaultValue; +} + +QByteArray DXCBPlatformInterface::themeName() const +{ + FETCH_PROPERTY("Net/ThemeName", themeName) + + return value.toByteArray(); +} + +QByteArray DXCBPlatformInterface::iconThemeName() const +{ + FETCH_PROPERTY("Net/IconThemeName", iconThemeName) + + return value.toByteArray(); +} + +QByteArray DXCBPlatformInterface::soundThemeName() const +{ + FETCH_PROPERTY("Net/SoundThemeName", soundThemeName) + + return value.toByteArray(); +} + +QByteArray DXCBPlatformInterface::fontName() const +{ + FETCH_PROPERTY("Qt/FontName", fontName) + + return value.toByteArray(); +} + +QByteArray DXCBPlatformInterface::monoFontName() const +{ + FETCH_PROPERTY("Qt/MonoFontName", monoFontName) + + return value.toByteArray(); +} + +qreal DXCBPlatformInterface::fontPointSize() const +{ + FETCH_PROPERTY("Qt/FontPointSize", fontPointSize) + + return value.toDouble(); +} + +QByteArray DXCBPlatformInterface::gtkFontName() const +{ + FETCH_PROPERTY("Gtk/FontName", gtkFontName) + + return value.toByteArray(); +} + +QColor DXCBPlatformInterface::activeColor() const +{ + FETCH_PROPERTY("Qt/ActiveColor", activeColor) + + return qvariant_cast(value); +} + +QColor DXCBPlatformInterface::darkActiveColor() const +{ + FETCH_PROPERTY("Qt/DarkActiveColor", darkActiveColor) + + return qvariant_cast(value); +} + +static QColor getSetting(const QByteArray &key) +{ + qWarning() << "Not implemented, key:" << key; + return {}; +} + +#define GET_COLOR(Role) qvariant_cast(getSetting(QByteArrayLiteral(#Role))) +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) +QColor DXCBPlatformInterface::window() const +{ + return GET_COLOR(window); +} + +QColor DXCBPlatformInterface::windowText() const +{ + return GET_COLOR(windowText); +} + +QColor DXCBPlatformInterface::base() const +{ + return GET_COLOR(base); +} + +QColor DXCBPlatformInterface::alternateBase() const +{ + return GET_COLOR(alternateBase); +} + +QColor DXCBPlatformInterface::toolTipBase() const +{ + return GET_COLOR(toolTipBase); +} + +QColor DXCBPlatformInterface::toolTipText() const +{ + return GET_COLOR(toolTipText); +} + +QColor DXCBPlatformInterface::text() const +{ + return GET_COLOR(text); +} + +QColor DXCBPlatformInterface::button() const +{ + return GET_COLOR(button); +} + +QColor DXCBPlatformInterface::buttonText() const +{ + return GET_COLOR(buttonText); +} + +QColor DXCBPlatformInterface::brightText() const +{ + return GET_COLOR(brightText); +} + +QColor DXCBPlatformInterface::light() const +{ + return GET_COLOR(light); +} + +QColor DXCBPlatformInterface::midlight() const +{ + return GET_COLOR(midlight); +} + +QColor DXCBPlatformInterface::dark() const +{ + return GET_COLOR(dark); +} + +QColor DXCBPlatformInterface::mid() const +{ + return GET_COLOR(mid); +} + +QColor DXCBPlatformInterface::shadow() const +{ + return GET_COLOR(shadow); +} + +QColor DXCBPlatformInterface::highlight() const +{ + return GET_COLOR(highlight); +} + +QColor DXCBPlatformInterface::highlightedText() const +{ + return GET_COLOR(highlightedText); +} + +QColor DXCBPlatformInterface::link() const +{ + return GET_COLOR(link); +} + +QColor DXCBPlatformInterface::linkVisited() const +{ + return GET_COLOR(linkVisited); +} + +QColor DXCBPlatformInterface::itemBackground() const +{ + return GET_COLOR(itemBackground); +} + +QColor DXCBPlatformInterface::textTitle() const +{ + return GET_COLOR(textTitle); +} + +QColor DXCBPlatformInterface::textTips() const +{ + return GET_COLOR(textTips); +} + +QColor DXCBPlatformInterface::textWarning() const +{ + return GET_COLOR(textWarning); +} + +QColor DXCBPlatformInterface::textLively() const +{ + return GET_COLOR(textLively); +} + +QColor DXCBPlatformInterface::lightLively() const +{ + return GET_COLOR(lightLively); +} + +QColor DXCBPlatformInterface::darkLively() const +{ + return GET_COLOR(darkLively); +} + +QColor DXCBPlatformInterface::frameBorder() const +{ + return GET_COLOR(frameBorder); +} +#endif + +int DXCBPlatformInterface::dotsPerInch(const QString &screenName) const +{ + bool ok = false; + + if (!screenName.isEmpty()) { + FETCH_PROPERTY_WITH_ARGS("Qt/DPI/" + screenName.toLocal8Bit(), dotsPerInch, screenName); + int dpi = value.toInt(&ok); + + if (ok) + return dpi; + } + + FETCH_PROPERTY_WITH_ARGS("Xft/DPI", dotsPerInch, screenName); + int dpi = value.toInt(&ok); + return ok ? dpi : -1; +} + +/*! + \property DXCBPlatformInterface::sizeMode + \brief This property holds the sizeMode of the system's SizeMode. + */ +int DXCBPlatformInterface::sizeMode() const +{ + D_DC(DXCBPlatformInterface); + QVariant value = d->theme->getSetting(QByteArrayLiteral("DTK/SizeMode")); + return value.toInt(); +} + +/*! + \property DXCBPlatformInterface::scrollBarPolicy + \brief This property holds the scrollBarPolicy of the system. same as Qt::ScrollBarPolicy + \retval 0 show as needed auto hide, default + \retval 1 always off + \retval 2 always on + */ +int DXCBPlatformInterface::scrollBarPolicy() const +{ + FETCH_PROPERTY("Qt/ScrollBarPolicy", scrollBarPolicy) + + return qvariant_cast(value); +} + +void DXCBPlatformInterface::setCursorBlinkTime(int cursorBlinkTime) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Net/CursorBlinkTime", cursorBlinkTime); +} + +void DXCBPlatformInterface::setCursorBlinkTimeout(int cursorBlinkTimeout) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Net/CursorBlinkTimeout", cursorBlinkTimeout); +} + +void DXCBPlatformInterface::setCursorBlink(bool cursorBlink) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Net/CursorBlink", cursorBlink); +} + +void DXCBPlatformInterface::setDoubleClickDistance(int doubleClickDistance) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Net/DoubleClickDistance", doubleClickDistance); +} + +void DXCBPlatformInterface::setDoubleClickTime(int doubleClickTime) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Net/DoubleClickTime", doubleClickTime); +} + +void DXCBPlatformInterface::setDndDragThreshold(int dndDragThreshold) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Net/DndDragThreshold", dndDragThreshold); +} + +void DXCBPlatformInterface::setThemeName(const QByteArray &themeName) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Net/ThemeName", themeName); +} + +void DXCBPlatformInterface::setIconThemeName(const QByteArray &iconThemeName) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Net/IconThemeName", iconThemeName); +} + +void DXCBPlatformInterface::setSoundThemeName(const QByteArray &soundThemeName) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Net/SoundThemeName", soundThemeName); +} + +void DXCBPlatformInterface::setFontName(const QByteArray &fontName) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Qt/FontName", fontName); +} + +void DXCBPlatformInterface::setMonoFontName(const QByteArray &monoFontName) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Qt/MonoFontName", monoFontName); +} + +void DXCBPlatformInterface::setFontPointSize(qreal fontPointSize) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Qt/FontPointSize", fontPointSize); +} + +void DXCBPlatformInterface::setGtkFontName(const QByteArray &fontName) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Gtk/FontName", fontName); +} + +void DXCBPlatformInterface::setActiveColor(const QColor activeColor) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Qt/ActiveColor", activeColor); +} + +void DXCBPlatformInterface::setDarkActiveColor(const QColor &activeColor) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("Qt/DarkActiveColor", activeColor); +} + +static void setSetting(const QByteArray &key, const QColor &color) +{ + qWarning() << "Not implemented, key: " << key << "value: " << color; +} + +#define SET_COLOR(Role) setSetting(QByteArrayLiteral(#Role), Role) +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) +void DXCBPlatformInterface::setWindow(const QColor &window) +{ + SET_COLOR(window); +} + +void DXCBPlatformInterface::setWindowText(const QColor &windowText) +{ + SET_COLOR(windowText); +} + +void DXCBPlatformInterface::setBase(const QColor &base) +{ + SET_COLOR(base); +} + +void DXCBPlatformInterface::setAlternateBase(const QColor &alternateBase) +{ + SET_COLOR(alternateBase); +} + +void DXCBPlatformInterface::setToolTipBase(const QColor &toolTipBase) +{ + SET_COLOR(toolTipBase); +} + +void DXCBPlatformInterface::setToolTipText(const QColor &toolTipText) +{ + SET_COLOR(toolTipText); +} + +void DXCBPlatformInterface::setText(const QColor &text) +{ + SET_COLOR(text); +} + +void DXCBPlatformInterface::setButton(const QColor &button) +{ + SET_COLOR(button); +} + +void DXCBPlatformInterface::setButtonText(const QColor &buttonText) +{ + SET_COLOR(buttonText); +} + +void DXCBPlatformInterface::setBrightText(const QColor &brightText) +{ + SET_COLOR(brightText); +} + +void DXCBPlatformInterface::setLight(const QColor &light) +{ + SET_COLOR(light); +} + +void DXCBPlatformInterface::setMidlight(const QColor &midlight) +{ + SET_COLOR(midlight); +} + +void DXCBPlatformInterface::setDark(const QColor &dark) +{ + SET_COLOR(dark); +} + +void DXCBPlatformInterface::setMid(const QColor &mid) +{ + SET_COLOR(mid); +} + +void DXCBPlatformInterface::setShadow(const QColor &shadow) +{ + SET_COLOR(shadow); +} + +void DXCBPlatformInterface::setHighlight(const QColor &highlight) +{ + SET_COLOR(highlight); +} + +void DXCBPlatformInterface::setHighlightedText(const QColor &highlightText) +{ + SET_COLOR(highlightText); +} + +void DXCBPlatformInterface::setLink(const QColor &link) +{ + SET_COLOR(link); +} + +void DXCBPlatformInterface::setLinkVisited(const QColor &linkVisited) +{ + SET_COLOR(linkVisited); +} + +void DXCBPlatformInterface::setItemBackground(const QColor &itemBackground) +{ + SET_COLOR(itemBackground); +} + +void DXCBPlatformInterface::setTextTitle(const QColor &textTitle) +{ + SET_COLOR(textTitle); +} + +void DXCBPlatformInterface::setTextTips(const QColor &textTips) +{ + SET_COLOR(textTips); +} + +void DXCBPlatformInterface::setTextWarning(const QColor &textWarning) +{ + SET_COLOR(textWarning); +} + +void DXCBPlatformInterface::setTextLively(const QColor &textLively) +{ + SET_COLOR(textLively); +} + +void DXCBPlatformInterface::setLightLively(const QColor &lightLively) +{ + SET_COLOR(lightLively); +} + +void DXCBPlatformInterface::setDarkLively(const QColor &darkLively) +{ + SET_COLOR(darkLively); +} + +void DXCBPlatformInterface::setFrameBorder(const QColor &frameBorder) +{ + SET_COLOR(frameBorder); +} +#endif + +void DXCBPlatformInterface::setDotsPerInch(const QString &screenName, int dpi) +{ + D_D(DXCBPlatformInterface); + + if (screenName.isEmpty()) { + d->theme->setSetting("Xft/DPI", dpi); + } else { + d->theme->setSetting("Qt/DPI/" + screenName.toLocal8Bit(), dpi); + } +} + +void DXCBPlatformInterface::setWindowRadius(int windowRadius) +{ + D_D(DXCBPlatformInterface); + + d->theme->setSetting("DTK/WindowRadius", windowRadius); +} + +DGUI_END_NAMESPACE + +#include "moc_dxcbplatforminterface.cpp" diff --git a/src/plugins/platform/xcb/dxcbplatforminterface.h b/src/plugins/platform/xcb/dxcbplatforminterface.h new file mode 100644 index 0000000..14e58b5 --- /dev/null +++ b/src/plugins/platform/xcb/dxcbplatforminterface.h @@ -0,0 +1,129 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DXCBPLATFORMINTERFACE_H +#define DXCBPLATFORMINTERFACE_H + +#include "plugins/dplatforminterface.h" + +DGUI_BEGIN_NAMESPACE + +class DXCBPlatformInterfacePrivate; +class DXCBPlatformInterface : public DPlatformInterface +{ + Q_OBJECT + D_DECLARE_PRIVATE(DXCBPlatformInterface) +public: + explicit DXCBPlatformInterface(quint32 window, QObject *parent); + + int cursorBlinkTime() const override; + int cursorBlinkTimeout() const override; + bool cursorBlink() const override; + int doubleClickDistance() const override; + int doubleClickTime() const override; + int dndDragThreshold() const override; + int windowRadius() const override; + int windowRadius(int defaultValue) const override; + QByteArray themeName() const override; + QByteArray iconThemeName() const override; + QByteArray soundThemeName() const override; + + QByteArray fontName() const override; + QByteArray monoFontName() const override; + qreal fontPointSize() const override; + QByteArray gtkFontName() const override; + + QColor activeColor() const override; + QColor darkActiveColor() const override; + +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) + QColor window() const override; + QColor windowText() const override; + QColor base() const override; + QColor alternateBase() const override; + QColor toolTipText() const override; + QColor toolTipBase() const override; + QColor text() const override; + QColor button() const override; + QColor buttonText() const override; + QColor brightText() const override; + QColor light() const override; + QColor midlight() const override; + QColor dark() const override; + QColor mid() const override; + QColor shadow() const override; + QColor highlight() const override; + QColor highlightedText() const override; + QColor link() const override; + QColor linkVisited() const override; + QColor itemBackground() const override; + QColor textTitle() const override; + QColor textTips() const override; + QColor textWarning() const override; + QColor textLively() const override; + QColor lightLively() const override; + QColor darkLively() const override; + QColor frameBorder() const override; +#endif + + int sizeMode() const override; + int scrollBarPolicy() const override; + +public Q_SLOTS: + void setCursorBlinkTime(int cursorBlinkTime) override; + void setCursorBlinkTimeout(int cursorBlinkTimeout) override; + void setCursorBlink(bool cursorBlink) override; + void setDoubleClickDistance(int doubleClickDistance) override; + void setDoubleClickTime(int doubleClickTime) override; + void setDndDragThreshold(int dndDragThreshold) override; + void setThemeName(const QByteArray &themeName) override; + void setIconThemeName(const QByteArray &iconThemeName) override; + void setSoundThemeName(const QByteArray &soundThemeName) override; + void setFontName(const QByteArray &fontName) override; + void setMonoFontName(const QByteArray &monoFontName) override; + void setFontPointSize(qreal fontPointSize) override; + void setGtkFontName(const QByteArray &fontName) override; + void setActiveColor(const QColor activeColor) override; + void setDarkActiveColor(const QColor &activeColor) override; +#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) + void setWindow(const QColor &window) override; + void setWindowText(const QColor &windowText) override; + void setBase(const QColor &base) override; + void setAlternateBase(const QColor &alternateBase) override; + void setToolTipBase(const QColor &toolTipBase) override; + void setToolTipText(const QColor &toolTipText) override; + void setText(const QColor &text) override; + void setButton(const QColor &button) override; + void setButtonText(const QColor &buttonText) override; + void setBrightText(const QColor &brightText) override; + void setLight(const QColor &light) override; + void setMidlight(const QColor &midlight) override; + void setDark(const QColor &dark) override; + void setMid(const QColor &mid) override; + void setShadow(const QColor &shadow) override; + void setHighlight(const QColor &highlight) override; + void setHighlightedText(const QColor &highlightedText) override; + void setLink(const QColor &link) override; + void setLinkVisited(const QColor &linkVisited) override; + void setItemBackground(const QColor &itemBackground) override; + void setTextTitle(const QColor &textTitle) override; + void setTextTips(const QColor &textTips) override; + void setTextWarning(const QColor &textWarning) override; + void setTextLively(const QColor &textLively) override; + void setLightLively(const QColor &lightLively) override; + void setDarkLively(const QColor &darkLively) override; + void setFrameBorder(const QColor &frameBorder) override; +#endif + + int dotsPerInch(const QString &screenName = QString()) const override; + void setDotsPerInch(const QString &screenName, int dpi) override; + void setWindowRadius(int windowRadius) override; + +private: + friend class DPlatformThemePrivate; + D_PRIVATE_SLOT(void _q_onThemePropertyChanged(const QByteArray &name, const QVariant &value)) +}; + +DGUI_END_NAMESPACE +#endif // DXCBPLATFORMINTERFACE_H diff --git a/src/plugins/platform/xcb/dxcbplatforminterface_p.h b/src/plugins/platform/xcb/dxcbplatforminterface_p.h new file mode 100644 index 0000000..2f341cf --- /dev/null +++ b/src/plugins/platform/xcb/dxcbplatforminterface_p.h @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DXCBPLATFORMINTERFACE_P_H +#define DXCBPLATFORMINTERFACE_P_H + +#include "dxcbplatforminterface.h" +#include "private/dplatforminterface_p.h" + +DGUI_BEGIN_NAMESPACE + +class DNativeSettings; +class DPlatformTheme; + +class DXCBPlatformInterfacePrivate : public DPlatformInterfacePrivate +{ +public: + D_DECLARE_PUBLIC(DXCBPlatformInterface) + DXCBPlatformInterfacePrivate(DXCBPlatformInterface *qq); + + void _q_onThemePropertyChanged(const QByteArray &name, const QVariant &value); + +public: + DPlatformTheme *parent = nullptr; + bool fallbackProperty = true; + DNativeSettings *theme; + QHash m_properties; +}; + +DGUI_END_NAMESPACE + +#endif // DNATIVESETTINGS_P_H diff --git a/src/plugins/platform/xcb/xcb.cmake b/src/plugins/platform/xcb/xcb.cmake new file mode 100644 index 0000000..2f8ff07 --- /dev/null +++ b/src/plugins/platform/xcb/xcb.cmake @@ -0,0 +1,10 @@ +file(GLOB XCB_HEADER + ${CMAKE_CURRENT_LIST_DIR}/*.h +) +file(GLOB XCB_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/*.cpp +) +set(xcb_SRC + ${XCB_HEADER} + ${XCB_SOURCE} +) diff --git a/src/plugins/plugins.cmake b/src/plugins/plugins.cmake new file mode 100644 index 0000000..67de257 --- /dev/null +++ b/src/plugins/plugins.cmake @@ -0,0 +1,74 @@ +option(DTK_DISABLE_XCB "Disable XCB Protocols" OFF) + +# force disable, because we don't support Treeland +option(DTK_DISABLE_TREELAND "Disable Treeland Protocols" ON) + +file(GLOB PLATFORM_INTERFACE_HEADER + ${CMAKE_CURRENT_LIST_DIR}/*.h +) +file(GLOB PLATFORM_INTERFACE_SOURCE + ${CMAKE_CURRENT_LIST_DIR}/*.cpp +) + +set(platform_interface_SRC + ${PLATFORM_INTERFACE_HEADER} + ${PLATFORM_INTERFACE_SOURCE} +) +target_sources(${LIB_NAME} PRIVATE + ${platform_interface_SRC} +) + +set(PRIVATE_HEADER_FILES plugins/dplatforminterface.h) +set(PRIVATE_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/dtk${PROJECT_VERSION_MAJOR}/DGui/Private") + +# XCB +if(NOT DTK_DISABLE_XCB) + message("Support XCB!") + include(plugins/platform/xcb/xcb.cmake) + target_sources(${LIB_NAME} PRIVATE + ${xcb_SRC} + ) + list(APPEND PRIVATE_HEADER_FILES "plugins/platform/xcb/dxcbplatforminterface.h") +else() + target_compile_definitions(${LIB_NAME} PRIVATE DTK_DISABLE_XCB) +endif() + +# Treeland +if(NOT DTK_DISABLE_TREELAND) + find_package(TreelandProtocols) + find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS WaylandClient) + set(TreelandProtocols_FOUND ${TreelandProtocols_FOUND}) +endif() + +if(NOT DTK_DISABLE_TREELAND AND TreelandProtocols_FOUND) + message("Support Treeland!") + if("${QT_VERSION_MAJOR}" STREQUAL "6") + qt6_generate_wayland_protocol_client_sources(${LIB_NAME} FILES + ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml + ) + else() + # ECM setup + include(FeatureSummary) + find_package(ECM REQUIRED NO_MODULE) + set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ECM_MODULE_PATH}") + find_package(QtWaylandScanner) + ecm_add_qtwayland_client_protocol(CLIENT_LIB_SRCS + PROTOCOL ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml + BASENAME treeland-personalization-manager-v1 + ) + target_sources(${LIB_NAME} PRIVATE + ${CLIENT_LIB_SRCS} + ) + endif() + + include(plugins/platform/treeland/treeland.cmake) + target_sources(${LIB_NAME} PRIVATE + ${treeland_SRC} + ) + list(APPEND PRIVATE_HEADER_FILES "plugins/platform/treeland/dtreelandplatforminterface.h") +else() + target_compile_definitions(${LIB_NAME} PRIVATE DTK_DISABLE_TREELAND) +endif() + +message(${PRIVATE_HEADER_FILES}) +install(FILES ${PRIVATE_HEADER_FILES} DESTINATION "${PRIVATE_INCLUDE_INSTALL_DIR}") diff --git a/src/private/dplatforminterface_p.h b/src/private/dplatforminterface_p.h new file mode 100644 index 0000000..3d518e3 --- /dev/null +++ b/src/private/dplatforminterface_p.h @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DPLATFORMINTERFACE_P_H +#define DPLATFORMINTERFACE_P_H + +#include +#include "plugins/dplatforminterface.h" + +DGUI_BEGIN_NAMESPACE + +class DPlatformInterface; +class DPlatformInterfacePrivate : public DCORE_NAMESPACE::DObjectPrivate +{ + D_DECLARE_PUBLIC(DPlatformInterface) +public: + DPlatformInterfacePrivate(DPlatformInterface *qq); + ~DPlatformInterfacePrivate(); +}; + +DGUI_END_NAMESPACE + +#endif // DNATIVESETTINGS_P_H diff --git a/src/private/dplatformtheme_p.h b/src/private/dplatformtheme_p.h index 0349cba..f2267b4 100644 --- a/src/private/dplatformtheme_p.h +++ b/src/private/dplatformtheme_p.h @@ -5,6 +5,7 @@ #ifndef DPLATFORMTHEME_P_H #define DPLATFORMTHEME_P_H +#include "plugins/dplatforminterface.h" #include "dplatformtheme.h" #include "dnativesettings_p.h" @@ -18,7 +19,6 @@ class DPlatformThemePrivate : public DNativeSettingsPrivate // 接收parent主题或非调色板DNativeSettings对象(theme对象)的属性变化通知 // 调色板相关的属性变化与此无关 - void _q_onThemePropertyChanged(const QByteArray &name, const QVariant &value); void onQtColorChanged(QPalette::ColorRole role, const QColor &color); void onDtkColorChanged(DPalette::ColorType type, const QColor &color); void notifyPaletteChanged(); @@ -34,6 +34,8 @@ class DPlatformThemePrivate : public DNativeSettingsPrivate DPalette *palette = nullptr; // 减少调色板changed信号的通知频率 QTimer *notifyPaletteChangeTimer = nullptr; + + DPlatformInterface *platformInterface = nullptr; }; DGUI_END_NAMESPACE diff --git a/src/wayland/config.tests/wayland_test/CMakeLists.txt b/src/wayland/config.tests/wayland_test/CMakeLists.txt deleted file mode 100644 index 4c12e76..0000000 --- a/src/wayland/config.tests/wayland_test/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. -# -# SPDX-License-Identifier: LGPL-3.0-or-later - -cmake_minimum_required(VERSION 3.16) - -project(wayland_test) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(AUTOMOC_COMPILER_PREDEFINES ON) - -find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Gui WaylandClient) -if(${QT_VERSION_MAJOR} STREQUAL "5") - find_package(Qt5 REQUIRED COMPONENTS XkbCommonSupport) -endif() - -find_package(PkgConfig REQUIRED) -pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client) - -find_package(TreelandProtocols) -set(TreelandProtocols_FOUND ${TreelandProtocols_FOUND}) - -add_executable(${PROJECT_NAME} main.cpp) - -if("${QT_VERSION_MAJOR}" STREQUAL "6") - qt6_generate_wayland_protocol_client_sources(${PROJECT_NAME} FILES - ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml - ) -else() - # ECM setup - include(FeatureSummary) - find_package(ECM REQUIRED NO_MODULE) - set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ECM_MODULE_PATH}") - find_package(QtWaylandScanner) - ecm_add_qtwayland_client_protocol(TABLET_SRCS - PROTOCOL ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml - BASENAME treeland-personalization-manager-v1 - ) - target_sources(${PROJECT_NAME} PRIVATE ${TABLET_SRCS}) - - target_link_libraries(${PROJECT_NAME} PRIVATE - Qt${QT_VERSION_MAJOR}::XkbCommonSupportPrivate - ) -endif() - -target_link_libraries(${PROJECT_NAME} PRIVATE - Qt${QT_VERSION_MAJOR}::Gui - Qt${QT_VERSION_MAJOR}::GuiPrivate - Qt${QT_VERSION_MAJOR}::CorePrivate - Qt${QT_VERSION_MAJOR}::WaylandClientPrivate - ${WAYLAND_CLIENT_LIBRARIES} -) diff --git a/src/wayland/config.tests/wayland_test/main.cpp b/src/wayland/config.tests/wayland_test/main.cpp deleted file mode 100644 index 433aefa..0000000 --- a/src/wayland/config.tests/wayland_test/main.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include - -#include -#include -#include - -#include -#include "qwayland-treeland-personalization-manager-v1.h" -#include - -#include -#include -#include -#include - -class PersonalizationWindowContext : public QWaylandClientExtensionTemplate, - public QtWayland::treeland_personalization_window_context_v1 -{ -public: - PersonalizationWindowContext(struct ::treeland_personalization_window_context_v1 *context) - : QWaylandClientExtensionTemplate(1) - , QtWayland::treeland_personalization_window_context_v1(context) - { - set_titlebar(enable_mode::enable_mode_disable); - } -}; - -int main(int argc, char *argv[]) -{ - QGuiApplication app(argc, argv); - return 0; -} diff --git a/src/wayland/personalizationwaylandclientextension.cpp b/src/wayland/personalizationwaylandclientextension.cpp deleted file mode 100644 index f6b702c..0000000 --- a/src/wayland/personalizationwaylandclientextension.cpp +++ /dev/null @@ -1,153 +0,0 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "personalizationwaylandclientextension.h" - -#include -#include -#include -#include -#include -#include -#include - -DGUI_BEGIN_NAMESPACE - -class PersonalizationManager_: public PersonalizationManager {}; -Q_GLOBAL_STATIC(PersonalizationManager_, personalizationManager) - -PersonalizationManager::PersonalizationManager() - : QWaylandClientExtensionTemplate(treeland_personalization_manager_v1_interface.version) - , m_isSupported(false) -{ - QtWaylandClient::QWaylandIntegration *waylandIntegration = static_cast(QGuiApplicationPrivate::platformIntegration()); - if (!waylandIntegration) { - qWarning() << "waylandIntegration is nullptr!!!"; - return; - } - m_waylandDisplay = waylandIntegration->display(); - if (!m_waylandDisplay) { - qWarning() << "waylandDisplay is nullptr!!!"; - return; - } - addListener(); - m_isSupported = m_waylandDisplay->hasRegistryGlobal(QString::fromUtf8(treeland_personalization_manager_v1_interface.name)); - if (!m_isSupported) { - qWarning() << "PersonalizationManager is not support"; - } -} - -PersonalizationManager::~PersonalizationManager() -{ - qDeleteAll(m_windowContexts); - m_windowContexts.clear(); -} - -PersonalizationManager *PersonalizationManager::instance() -{ - return personalizationManager; -} - -bool PersonalizationManager::isSupported() const -{ - return m_isSupported; -} - -PersonalizationWindowContext *PersonalizationManager::getWindowContext(QWindow *window) -{ - if (!m_isSupported) { - return nullptr; - } - if (!window) { - qWarning() << "window is nullptr!!!"; - return nullptr; - } - if (m_windowContexts.contains(window)) { - return m_windowContexts.value(window); - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - auto waylandWindow = window->nativeInterface(); -#else - auto waylandWindow = dynamic_cast(window->handle()); -#endif - if (!waylandWindow) { - qWarning() << "waylandWindow is nullptr!!!"; - return nullptr; - } -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - auto surface = waylandWindow->surface(); -#else - auto surface = waylandWindow->waylandSurface()->object(); -#endif - if (!surface) { - qWarning() << "waylandSurface is nullptr!!!"; - return nullptr; - } - - // FIXME: Before calling get_window_context, it was not determined whether PersonalizationManager was isActive - auto context = new PersonalizationWindowContext(get_window_context(surface)); - connect(window, &QWindow::visibleChanged, context, [this, context, window](bool visible){ - if (!visible) { - context->deleteLater(); - m_windowContexts.remove(window); - } - }); - - m_windowContexts.insert(window, context); - return context; -} - -void PersonalizationManager::addListener() -{ - if (!m_waylandDisplay) { - qWarning() << "waylandDisplay is nullptr!, skip addListener"; - return; - } - m_waylandDisplay->addRegistryListener(&handleListenerGlobal, this); -} - -void PersonalizationManager::removeListener() -{ - if (!m_waylandDisplay) { - qWarning() << "waylandDisplay is nullptr!, skip removeListener"; - return; - } - m_waylandDisplay->removeListener(&handleListenerGlobal, this); -} - -void PersonalizationManager::handleListenerGlobal(void *data, wl_registry *registry, uint32_t id, const QString &interface, uint32_t version) -{ - if (interface == treeland_personalization_manager_v1_interface.name) { - PersonalizationManager *integration = static_cast(data); - if (!integration) { - qWarning() << "integration is nullptr!!!"; - return; - } - - integration->init(registry, id, version); - } -} - -void PersonalizationManager::setEnableTitleBar(QWindow *window, bool enable) -{ - auto windowContext = getWindowContext(window); - if (!windowContext) { - qWarning() << "windowContext is nullptr!"; - return; - } - windowContext->setEnableTitleBar(enable); -} - -PersonalizationWindowContext::PersonalizationWindowContext(struct ::treeland_personalization_window_context_v1 *context) - : QWaylandClientExtensionTemplate(treeland_personalization_window_context_v1_interface.version) - , QtWayland::treeland_personalization_window_context_v1(context) -{ -} - -void PersonalizationWindowContext::setEnableTitleBar(bool enable) -{ - set_titlebar(enable ? enable_mode::enable_mode_enable : enable_mode::enable_mode_disable); -} - -DGUI_END_NAMESPACE diff --git a/src/wayland/personalizationwaylandclientextension.h b/src/wayland/personalizationwaylandclientextension.h deleted file mode 100644 index 74858d0..0000000 --- a/src/wayland/personalizationwaylandclientextension.h +++ /dev/null @@ -1,54 +0,0 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include - -#include "qwayland-treeland-personalization-manager-v1.h" - -#include -#include -#include - -DGUI_BEGIN_NAMESPACE -class PersonalizationWindowContext; -class PersonalizationAppearanceContext; - - -class PersonalizationManager: public QWaylandClientExtensionTemplate, - public QtWayland::treeland_personalization_manager_v1 -{ - Q_OBJECT -public: - static PersonalizationManager *instance(); - ~PersonalizationManager(); - - void setEnableTitleBar(QWindow *window, bool enable); - bool isSupported() const; - -protected: - explicit PersonalizationManager(); - -private: - void addListener(); - void removeListener(); - PersonalizationWindowContext *getWindowContext(QWindow *window); - - static void handleListenerGlobal(void *data, wl_registry *registry, uint32_t id, const QString &interface, uint32_t version); - -private: - QHash m_windowContexts; - QtWaylandClient::QWaylandDisplay *m_waylandDisplay = nullptr; - bool m_isSupported; -}; - -class PersonalizationWindowContext : public QWaylandClientExtensionTemplate, - public QtWayland::treeland_personalization_window_context_v1 -{ - Q_OBJECT -public: - explicit PersonalizationWindowContext(struct ::treeland_personalization_window_context_v1 *context); - - void setEnableTitleBar(bool enable); -}; -DGUI_END_NAMESPACE diff --git a/src/wayland/wayland.cmake b/src/wayland/wayland.cmake deleted file mode 100644 index 08663d3..0000000 --- a/src/wayland/wayland.cmake +++ /dev/null @@ -1,10 +0,0 @@ -file(GLOB WAYLAND_HEADER - ${CMAKE_CURRENT_LIST_DIR}/*.h -) -file(GLOB WAYLAND_SOURCE - ${CMAKE_CURRENT_LIST_DIR}/*.cpp -) -set(wayland_SRC - ${WAYLAND_HEADER} - ${WAYLAND_SOURCE} -)