Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 将dde-appearance 改成插件 #130

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

add_compile_options(-DQT_NO_KEYWORDS)
set(PROJECT_NAME dde-appearance)
set(BIN_NAME "plugin-dde-appearance")

find_package(Qt5 REQUIRED COMPONENTS Core DBus Concurrent Gui)
find_package(DtkCore REQUIRED)
Expand All @@ -33,7 +35,7 @@ qt5_add_dbus_adaptor(ADAPTER_SOURCES


set(SRCS
./main.cpp
./plugin.cpp
./dbus/scaleFactors.h
./dbus/scaleFactors.cpp
./dbus/appearancedbusproxy.h
Expand Down Expand Up @@ -94,11 +96,11 @@ set(SRCS
${ADAPTER_SOURCES}
)

add_executable(dde-appearance
${SRCS}
add_library(${BIN_NAME} MODULE
${SRCS}
)

target_link_libraries(dde-appearance
target_link_libraries(${BIN_NAME} PRIVATE
Qt5::Core
Qt5::DBus
Qt5::Concurrent
Expand All @@ -113,5 +115,6 @@ target_link_libraries(dde-appearance
${DtkCore_LIBRARIES}
${DtkGui_LIBRARIES}
)

install(TARGETS dde-appearance DESTINATION ${CMAKE_INSTALL_BINDIR})
include(GNUInstallDirs)
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/deepin-service-manager/)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/plugin-dde-appearance.json DESTINATION share/deepin-service-manager/user/)
9 changes: 0 additions & 9 deletions src/service/dbus/appearance1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include "appearance1thread.h"
#include "modules/common/commondefine.h"

#include <DGuiApplicationHelper>

DGUI_USE_NAMESPACE

#include <QDBusMessage>

// 仅实现异步调用Appearance1Thread(属性等直接返回,复杂方法异步处理)
Expand All @@ -21,11 +17,6 @@ Appearance1::Appearance1(QObject *parent)
registerScaleFactorsMetaType();
connect(appearance1Thread.data(), SIGNAL(Changed(QString, QString)), this, SIGNAL(Changed(const QString &, const QString &)));
connect(appearance1Thread.data(), SIGNAL(Refreshed(QString)), this, SIGNAL(Refreshed(const QString)));

// NOTE: because I do not know when themetype will change, so when themetype has changed, notify again
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [this] {
Q_EMIT Changed(TYPEGLOBALTHEME, appearance1Thread.data()->globalTheme());
});
}

Appearance1::~Appearance1()
Expand Down
1 change: 1 addition & 0 deletions src/service/dbus/appearance1thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Appearance1Thread::Appearance1Thread()
, thread(new QThread(this))
{
// 属性初始化
DTK_CORE_NAMESPACE::DConfig::setAppId(APPEARANCEAPPID);
DTK_CORE_NAMESPACE::DConfig settingDconfig(APPEARANCESCHEMA);
property->globalTheme.init(settingDconfig.value(GSKEYGLOBALTHEME).toString());
property->gtkTheme.init(settingDconfig.value(GSKEYGTKTHEME).toString());
Expand Down
10 changes: 3 additions & 7 deletions src/service/impl/appearancemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
#include <QTimer>
#include <QMetaObject>
#include <QCoreApplication>
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>

#include <pwd.h>
#include <QThread>

#define NAN_ANGLE (-200.0) // 异常经纬度
#define DEFAULT_WORKSPACE_COUNT (2) // 默认工作区数量
Expand Down Expand Up @@ -87,13 +90,6 @@ bool AppearanceManager::init()
initUserObj();
initCurrentBgs();

xcb_connection_t *conn = xcb_connect(nullptr, nullptr);
xcb_randr_query_version_reply_t *v = xcb_randr_query_version_reply(conn, xcb_randr_query_version(conn, 1, 1), nullptr);
if (v == nullptr) {
qWarning() << "xcb_randr_query_version_reply faile";
return false;
}

connect(m_dbusProxy.get(), &AppearanceDBusProxy::workspaceCountChanged, this, &AppearanceManager::handleWmWorkspaceCountChanged);
connect(m_dbusProxy.get(), &AppearanceDBusProxy::SetScaleFactorStarted, this, &AppearanceManager::handleSetScaleFactorStarted);
connect(m_dbusProxy.get(), &AppearanceDBusProxy::SetScaleFactorDone, this, &AppearanceManager::handleSetScaleFactorDone);
Expand Down
43 changes: 0 additions & 43 deletions src/service/main.cpp

This file was deleted.

9 changes: 7 additions & 2 deletions src/service/modules/api/syncconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
#include <QDBusPendingReply>
#include <QDebug>
// 数据同步处理,和UOS ID同步数据
extern QDBusConnection *pluginDbus;
SyncConfig::SyncConfig(QString name, QString path)
: name(name)
, path(path)
{
QDBusConnection::sessionBus().registerObject(path, this, QDBusConnection::ExportNonScriptableSlots);
QDBusConnection::sessionBus().connect("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged", this, SLOT(handleNameOwnerChanged(QString, QString, QString)));
if (!pluginDbus) {
qWarning() << "pluginDbus is null:" <<name << path;
return;
}
pluginDbus->registerObject(path, this, QDBusConnection::ExportNonScriptableSlots);
pluginDbus->connect("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged", this, SLOT(handleNameOwnerChanged(QString, QString, QString)));
registerConfig();
}

Expand Down
7 changes: 7 additions & 0 deletions src/service/modules/api/themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ bool ThemesApi::setGlobalTheme(QString name)
return true;
}

QString ThemesApi::getGtkTheme(){
if (!xSetting) {
return QString();
}
return xSetting->get(XSKEYTHEME).toString();
}

bool ThemesApi::setGtkTheme(QString name)
{
if (!scanner->isGtkTheme(getThemePath(name, TYPEGTK, "themes"))) {
Expand Down
1 change: 1 addition & 0 deletions src/service/modules/api/themes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ThemesApi : public QObject
bool setWMTheme(QString name);
bool setGlobalTheme(QString name);
bool setGtkTheme(QString name);
QString getGtkTheme();
bool setIconTheme(QString name);
bool setCursorTheme(QString name);
QString getThemePath(QString name, QString ty, QString key);
Expand Down
8 changes: 2 additions & 6 deletions src/service/modules/api/themethumb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>

#include <DGuiApplicationHelper>

#include <X11/Xcursor/Xcursor.h>

#undef Bool
Expand All @@ -23,8 +21,6 @@
#undef True
#undef False

using Dtk::Gui::DGuiApplicationHelper;

const int width = 320;
const int height = 70;
const int baseCursorSize = 24;
Expand Down Expand Up @@ -367,7 +363,7 @@ QImage* loadXCursor(QString fileName, int size)
return image;
}

QString getGlobal(QString id, QString descFile)
QString getGlobal(QString id, QString descFile, QString gtkTheme)
{
if (!checkScaleFactor()) {
qInfo() << "scaleFactor <= 0";
Expand All @@ -377,7 +373,7 @@ QString getGlobal(QString id, QString descFile)
keyFile.loadFile(descFile);
QStringList example = keyFile.getStrList("Deepin Theme", "Example");
if (!example.isEmpty()) {
bool isdark = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::ColorType::DarkType;
bool isdark = (gtkTheme == "deepin-dark") ;
QString path = isdark ? example.last() : example.first();
QFileInfo file(path);
if (file.isRelative()) {
Expand Down
2 changes: 1 addition & 1 deletion src/service/modules/api/themethumb.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ QImage CompositeImages(QVector<QImage *>, int width, int height, int inconSize,
QImage *loadXCursor(QString fileName, int size);
QList<QIcon> getIcons(QString theme, int size);
QVector<QImage *> getCursors(QString dir, int size);
QString getGlobal(QString id, QString descFile);
QString getGlobal(QString id, QString descFile,QString gtkTheme);
QString getGtk(QString id, QString descFile);
QString getIcon(QString id, QString descFile);
bool shouldGenerateNew(QString descFile, QString out);
Expand Down
1 change: 1 addition & 0 deletions src/service/modules/common/commondefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const QString APPEARANCE_SERVICE = "org.deepin.dde.Appearance1";
const QString APPEARANCE_PATH = "/org/deepin/dde/Appearance1";
const QString APPEARANCE_INTERFACE = "org.deepin.dde.Appearance1";

#define APPEARANCEAPPID "org.deepin.dde.appearance"
#define APPEARANCESCHEMA "org.deepin.dde.appearance"
#define XSETTINGSSCHEMA "com.deepin.xsettings"
#define WRAPBGSCHEMA "com.deepin.wrap.gnome.desktop.background"
Expand Down
4 changes: 2 additions & 2 deletions src/service/modules/subthemes/subthemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ QString Subthemes::getGlobalThumbnail(QString id)
{
return "";
}

QString gtkTheme = themeApi->getGtkTheme();
QString path = theme->getPath()+"/index.theme";
return getGlobal(id,path);
return getGlobal(id,path,gtkTheme);
}

QString Subthemes::getGtkThumbnail(QString id)
Expand Down
13 changes: 13 additions & 0 deletions src/service/plugin-dde-appearance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "org.deepin.dde.Appearance1",
"libPath": "libplugin-dde-appearance.so",
"group": "core",
"policyStartType": "Resident",
"pluginType": "qt",
"startDelay": 0,
"policy": [
{
"path": "/org/deepin/dde/Appearance1"
}
]
}
49 changes: 49 additions & 0 deletions src/service/plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "appearance1adaptor.h"
#include "dbus/appearance1.h"
#include "modules/common/commondefine.h"
#include <QCoreApplication>

static Appearance1 *appearance = nullptr;
QDBusConnection *pluginDbus = nullptr;

extern "C" int DSMRegister(const char *name, void *data)
{
(void)name;
(void)data;
pluginDbus = reinterpret_cast<QDBusConnection *>(data);
QTranslator translator;
QString languagePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QString("dde-appearance/translations"),
QStandardPaths::LocateDirectory);
translator.load(languagePath+"/dde-appearance_" + QLocale::system().name());
qApp->installTranslator(&translator);

appearance = new Appearance1();

new Appearance1Adaptor(appearance);
bool appearanceRegister = pluginDbus->registerService(APPEARANCE_SERVICE);
bool appearanceObjectRegister = pluginDbus->registerObject(APPEARANCE_PATH, APPEARANCE_INTERFACE, appearance);

if (!appearanceRegister || ! appearanceObjectRegister) {
qWarning() << "appearance dbus service already registered";
return -1;
}
return 0;
}

// 该函数用于资源释放
// 非常驻插件必须实现该函数,以防内存泄漏
extern "C" int DSMUnRegister(const char *name, void *data)
{
(void)name;
(void)data;
if (appearance) {
appearance->deleteLater();
}
appearance = nullptr;
return 0;
}
Loading