From 195bcf36df1503c403367fd4ab354cacaeb432ed Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Mon, 23 Aug 2021 19:01:11 +0200 Subject: [PATCH 1/2] Add new DecorationThemeProvider class This will avoid the ugly hack inside of KWin and allow consumers to port away from registering plugins using keywords Task: https://phabricator.kde.org/T14744 --- CMakeLists.txt | 1 + src/CMakeLists.txt | 3 ++ src/decorationthemeprovider.cpp | 85 +++++++++++++++++++++++++++++++++ src/decorationthemeprovider.h | 75 +++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 src/decorationthemeprovider.cpp create mode 100644 src/decorationthemeprovider.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e497318..33ac19e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ endif() set(KDECORATION2_INCLUDEDIR "${KDE_INSTALL_INCLUDEDIR}/KDecoration2") find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED) +find_package(KF5CoreAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050d00) add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x054200) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd8de05..dbc268c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,7 @@ set(libkdecoration2_SRCS decorationbuttongroup.cpp decorationsettings.cpp decorationshadow.cpp + decorationthemeprovider.cpp ) add_library(kdecorations2 SHARED ${libkdecoration2_SRCS}) @@ -28,6 +29,7 @@ target_link_libraries(kdecorations2 PRIVATE kdecorations2private KF5::I18n + KF5::CoreAddons ) target_include_directories(kdecorations2 INTERFACE "$" ) @@ -45,6 +47,7 @@ ecm_generate_headers(KDecoration2_CamelCase_HEADERS DecorationButtonGroup DecorationSettings DecorationShadow + DecorationThemeProvider PREFIX KDecoration2 REQUIRED_HEADERS KDecoration2_HEADERS diff --git a/src/decorationthemeprovider.cpp b/src/decorationthemeprovider.cpp new file mode 100644 index 0000000..817d55d --- /dev/null +++ b/src/decorationthemeprovider.cpp @@ -0,0 +1,85 @@ +/* + * SPDX-FileCopyrightText: 2021 Alexander Lohnau + * + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL + */ + +#include "decorationthemeprovider.h" + +#include + +class DecorationThemeMetaDataPrivate +{ +public: + QString visibleName; + QString themeName; + QString pluginId; + bool hasConfig = false; + KDecoration2::BorderSize borderSize = KDecoration2::BorderSize::Normal; +}; + +using namespace KDecoration2; + +DecorationThemeMetaData::DecorationThemeMetaData() + : d(new DecorationThemeMetaDataPrivate()) +{ +} + +DecorationThemeMetaData::~DecorationThemeMetaData() = default; + +QString DecorationThemeMetaData::visibleName() const +{ + return d->visibleName; +} + +void DecorationThemeMetaData::setVisibleName(const QString &name) +{ + d->visibleName = name; +} + +bool DecorationThemeMetaData::hasConfiguration() const +{ + return d->hasConfig; +} + +void DecorationThemeMetaData::setHasConfiguration(bool hasConfig) +{ + d->hasConfig = hasConfig; +} + +QString DecorationThemeMetaData::themeName() const +{ + return d->themeName; +} + +void DecorationThemeMetaData::setThemeName(const QString &name) +{ + d->themeName = name; +} + +void DecorationThemeMetaData::setBorderSize(KDecoration2::BorderSize size) +{ + d->borderSize = size; +} + +KDecoration2::BorderSize DecorationThemeMetaData::borderSize() const +{ + return d->borderSize; +} + +QString DecorationThemeMetaData::pluginId() const +{ + return d->pluginId; +} + +void DecorationThemeMetaData::setPluginId(const QString &id) +{ + d->pluginId = id; +} + +DecorationThemeProvider::DecorationThemeProvider(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : QObject(parent) +{ + Q_UNUSED(data) + Q_UNUSED(args) +} diff --git a/src/decorationthemeprovider.h b/src/decorationthemeprovider.h new file mode 100644 index 0000000..94a1b5e --- /dev/null +++ b/src/decorationthemeprovider.h @@ -0,0 +1,75 @@ +/* + * SPDX-FileCopyrightText: 2021 Alexander Lohnau + * + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL + */ + +#ifndef KDECORATION2_DECORATION_THEME_PROVIDER +#define KDECORATION2_DECORATION_THEME_PROVIDER + +#include "decorationdefines.h" +#include +#include +#include + +class KPluginMetaData; +class DecorationThemeMetaDataPrivate; + +namespace KDecoration2 +{ +/** + * Class providing type-safe access to data of themes + * + * @since 5.23 + * @author Alexander Lohnau + */ +class KDECORATIONS2_EXPORT DecorationThemeMetaData +{ +public: + explicit DecorationThemeMetaData(); + virtual ~DecorationThemeMetaData(); + + /// User-visible name of the theme + QString visibleName() const; + void setVisibleName(const QString &name); + + /// Internal name of the theme + QString themeName() const; + void setThemeName(const QString &name); + + /// Indicates that the theme has KCMs + bool hasConfiguration() const; + void setHasConfiguration(bool hasConfig); + + /// Border size of the decoration, this gets set based on the "recommendedBorderSize" key in the json metadata + /// @internal + KDecoration2::BorderSize borderSize() const; + void setBorderSize(KDecoration2::BorderSize size); + + /// @internal + QString pluginId() const; + void setPluginId(const QString &id); + +private: + std::shared_ptr d; +}; +/** + * Class to give the KWin decorationmodel access to the plugin's themes. + * + * @since 5.23 + * @author Alexander Lohnau + */ +class KDECORATIONS2_EXPORT DecorationThemeProvider : public QObject +{ + Q_OBJECT + +public: + explicit DecorationThemeProvider(QObject *parent, const KPluginMetaData &data, const QVariantList &args); + + /** + * List containing information of supported themes + */ + virtual QList themes() const = 0; +}; +} +#endif -- GitLab From 343cade16a283cab3a3bef641e47b42c1b137d1f Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Mon, 6 Sep 2021 16:36:18 +0200 Subject: [PATCH 2/2] Use QSharedData for DecorationThemeMetaDataPrivate class --- src/decorationthemeprovider.cpp | 6 +++++- src/decorationthemeprovider.h | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/decorationthemeprovider.cpp b/src/decorationthemeprovider.cpp index 817d55d..5a470e8 100644 --- a/src/decorationthemeprovider.cpp +++ b/src/decorationthemeprovider.cpp @@ -8,7 +8,7 @@ #include -class DecorationThemeMetaDataPrivate +class DecorationThemeMetaDataPrivate : public QSharedData { public: QString visibleName; @@ -83,3 +83,7 @@ DecorationThemeProvider::DecorationThemeProvider(QObject *parent, const KPluginM Q_UNUSED(data) Q_UNUSED(args) } + +DecorationThemeMetaData::DecorationThemeMetaData(const DecorationThemeMetaData &other) = default; + +DecorationThemeMetaData &DecorationThemeMetaData::operator=(const DecorationThemeMetaData &other) = default; diff --git a/src/decorationthemeprovider.h b/src/decorationthemeprovider.h index 94a1b5e..0c6da3d 100644 --- a/src/decorationthemeprovider.h +++ b/src/decorationthemeprovider.h @@ -9,8 +9,8 @@ #include "decorationdefines.h" #include +#include #include -#include class KPluginMetaData; class DecorationThemeMetaDataPrivate; @@ -28,6 +28,8 @@ class KDECORATIONS2_EXPORT DecorationThemeMetaData public: explicit DecorationThemeMetaData(); virtual ~DecorationThemeMetaData(); + DecorationThemeMetaData(const DecorationThemeMetaData &other); + DecorationThemeMetaData &operator=(const DecorationThemeMetaData &other); /// User-visible name of the theme QString visibleName() const; @@ -46,12 +48,13 @@ public: KDecoration2::BorderSize borderSize() const; void setBorderSize(KDecoration2::BorderSize size); - /// @internal + /// plugin id of theme provider + /// @see KPluginMetaData::pluginId QString pluginId() const; void setPluginId(const QString &id); private: - std::shared_ptr d; + QSharedDataPointer d; }; /** * Class to give the KWin decorationmodel access to the plugin's themes. -- GitLab