Skip to content

Commit

Permalink
chore: 添加紧凑模式属性
Browse files Browse the repository at this point in the history
  • Loading branch information
fuleyi authored and fly602 committed Sep 12, 2024
1 parent 4c3c41d commit 4c87a35
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 3 deletions.
1 change: 1 addition & 0 deletions dbus/org.deepin.dde.Appearance1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<property access='readwrite' type='s' name='QtActiveColor' />
<property access='read' type='s' name='StandardFont' />
<property access='readwrite' type='s' name='WallpaperSlideShow' />
<property access='readwrite' type='i' name='DTKSizeMode' />
<property access='read' type='s' name='WallpaperURls' />

<signal name='Changed'>
Expand Down
20 changes: 20 additions & 0 deletions misc/dconfig/org.deepin.dde.appearance.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@
"description": "Save all the wallpaper URL information.",
"permissions": "readwrite",
"visibility": "private"
},
"Dtk_Size_Mode": {
"value": 0,
"serial": 0,
"flags": [],
"name": "Dtk_Size_Mode",
"name[zh_CN]": "紧凑模式",
"description": "Compact Mode.",
"permissions": "readwrite",
"visibility": "private"
},
"Compact_Font_Size": {
"value": 9.0,
"serial": 0,
"flags": [],
"name": "Compact_Font_Size",
"name[zh_CN]": "紧凑模式下,字体大小",
"description": "Compact font size.",
"permissions": "readwrite",
"visibility": "private"
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/service/dbus/appearance1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,23 @@ int Appearance1::windowRadius() const
return appearance1Thread->windowRadius();
}

int Appearance1::dtkSizeMode() const
{
return appearance1Thread->dtkSizeMode();
}

void Appearance1::setWindowRadius(int value)
{
// message.setDelayedReply(true);
QMetaObject::invokeMethod(appearance1Thread.get(), "setWindowRadius", Qt::QueuedConnection, Q_ARG(int, value));
}

void Appearance1::setDTKSizeMode(int value)
{
// message.setDelayedReply(true);
QMetaObject::invokeMethod(appearance1Thread.get(), "setDTKSizeMode", Qt::QueuedConnection, Q_ARG(int, value));
}

void Appearance1::Delete(const QString &ty, const QString &name)
{
auto message = this->message();
Expand Down
4 changes: 4 additions & 0 deletions src/service/dbus/appearance1.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class Appearance1 : public QObject, protected QDBusContext
int windowRadius() const;
void setWindowRadius(int value);

Q_PROPERTY(int DTKSizeMode READ dtkSizeMode WRITE setDTKSizeMode)
int dtkSizeMode() const;
void setDTKSizeMode(int value);

public Q_SLOTS: // METHODS
void Delete(const QString &ty, const QString &name);
QString GetCurrentWorkspaceBackground();
Expand Down
17 changes: 15 additions & 2 deletions src/service/dbus/appearance1thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Appearance1Thread::Appearance1Thread()
property->cursorTheme.init(settingDconfig.value(GSKEYCURSORTHEME).toString());
property->standardFont.init(settingDconfig.value(GSKEYFONTSTANDARD).toString());
property->monospaceFont.init(settingDconfig.value(GSKEYFONTMONOSPACE).toString());
property->fontSize.init(settingDconfig.value(GSKEYFONTSIZE).toDouble());
property->dtkSizeMode.init(settingDconfig.value(DDTKSIZEMODE).toInt());
// dtkSizeMode必须先于fontSize初始化,紧凑模式下,使用Compact_Font_Size配置
property->fontSize.init(settingDconfig.value(property->dtkSizeMode == 1 ? DCOMPACTFONTSIZE : GSKEYFONTSIZE).toDouble());
property->opacity.init(settingDconfig.value(GSKEYOPACITY).toDouble());
property->wallpaperSlideShow.init(settingDconfig.value(GSKEYWALLPAPERSLIDESHOW).toString());
property->wallpaperURls.init(settingDconfig.value(GSKEYWALLPAPERURIS).toString());
Expand Down Expand Up @@ -139,6 +141,17 @@ QString Appearance1Thread::wallpaperURls() const
return property->wallpaperURls;
}

int Appearance1Thread::dtkSizeMode() const
{
return property->dtkSizeMode;
}

void Appearance1Thread::setDTKSizeMode(int value)
{
QMutexLocker locker(&mutex);
appearanceManager->doSetDTKSizeMode(value);
}

int Appearance1Thread::windowRadius() const
{
return property->windowRadius;
Expand Down Expand Up @@ -210,7 +223,7 @@ void Appearance1Thread::Reset(const QDBusMessage &message)
{
Q_UNUSED(message);
QMutexLocker locker(&mutex);
QStringList keys{GSKEYGLOBALTHEME, GSKEYGTKTHEME, GSKEYICONTHEM, GSKEYCURSORTHEME, GSKEYFONTSIZE};
QStringList keys{GSKEYGLOBALTHEME, GSKEYGTKTHEME, GSKEYICONTHEM, GSKEYCURSORTHEME, GSKEYFONTSIZE, DDTKSIZEMODE, DCOMPACTFONTSIZE};

appearanceManager->doResetSettingBykeys(keys);

Expand Down
4 changes: 4 additions & 0 deletions src/service/dbus/appearance1thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ class Appearance1Thread : public QObject
Q_PROPERTY(int WindowRadius READ windowRadius WRITE setWindowRadius)
int windowRadius() const;

Q_PROPERTY(int DTKSizeMode READ dtkSizeMode WRITE setDTKSizeMode)
int dtkSizeMode() const;

public Q_SLOTS:
// PROPERTIES
void setFontSize(double value);
void setOpacity(double value);
void setQtActiveColor(const QString &value);
void setWallpaperSlideShow(const QString &value);
void setWindowRadius(int value);
void setDTKSizeMode(int value);
// METHODS
void Delete(const QString &ty, const QString &name, const QDBusMessage &message);
QString GetCurrentWorkspaceBackground(const QDBusMessage &message);
Expand Down
4 changes: 4 additions & 0 deletions src/service/dbus/appearancedbusproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ void AppearanceDBusProxy::SetString(const QString &prop, const QString &v)
{
m_xSettingsInterface->asyncCall(QStringLiteral("SetString"), prop, v);
}
void AppearanceDBusProxy::SetInteger(const QString &prop, const int &v)
{
m_xSettingsInterface->asyncCall(QStringLiteral("SetInteger"), prop, v);
}
double AppearanceDBusProxy::GetScaleFactor()
{
return QDBusPendingReply<double>(m_xSettingsInterface->asyncCall(QStringLiteral("GetScaleFactor")));
Expand Down
1 change: 1 addition & 0 deletions src/service/dbus/appearancedbusproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public Q_SLOTS:
// xSettingsInterface
public Q_SLOTS:
void SetString(const QString &prop, const QString &v);
void SetInteger(const QString &prop, const int &v);
double GetScaleFactor();
void SetScaleFactor(double scale);
ScaleFactors GetScreenScaleFactors();
Expand Down
1 change: 1 addition & 0 deletions src/service/dbus/appearanceproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ AppearanceProperty::AppearanceProperty()
, wallpaperSlideShow("WallpaperSlideShow")
, wallpaperURls("WallpaperURls")
, windowRadius("WindowRadius")
, dtkSizeMode("DTKSizeMode")
{
fontSize.init(0.0);
opacity.init(0.0);
Expand Down
1 change: 1 addition & 0 deletions src/service/dbus/appearanceproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class AppearanceProperty
DBusProperty<QString> wallpaperSlideShow;
DBusProperty<QString> wallpaperURls;
DBusProperty<int> windowRadius;
DBusProperty<int> dtkSizeMode;
};

#endif // APPEARANCEPROPERTY_H
53 changes: 52 additions & 1 deletion src/service/impl/appearancemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ bool AppearanceManager::init()
connect(m_dbusProxy.get(), &AppearanceDBusProxy::TimeUpdate, this, &AppearanceManager::handleTimeUpdate);
connect(m_dbusProxy.get(), &AppearanceDBusProxy::HandleForSleep, this, &AppearanceManager::handlePrepareForSleep);

initDtkSizeMode();
initGlobalTheme();

QVector<QSharedPointer<Theme>> iconList = m_subthemes->listIconThemes();
Expand Down Expand Up @@ -353,6 +354,10 @@ void AppearanceManager::handleSettingDConfigChange(QString key)
bSuccess = doSetMonospaceFont(value);
} else if (key == GSKEYFONTSIZE) {
type = TYPEFONTSIZE;
// 如果是紧凑模式,使用compact-font-size
if (m_property->dtkSizeMode == 1) {
break;
}
double size = m_settingDconfig.value(key).toDouble();
if (size == m_property->fontSize) {
break;
Expand Down Expand Up @@ -389,6 +394,25 @@ void AppearanceManager::handleSettingDConfigChange(QString key)
break;
}
utils::writeWallpaperConfig(wallpaper);
} else if (key == DDTKSIZEMODE) {
type = TYPEDTKSIZEMODE;
bool ok = false;
int mode = m_settingDconfig.value(key).toInt(&ok);
if (ok) {
doSetDTKSizeMode(mode);
double size = m_settingDconfig.value(mode == 1 ? DCOMPACTFONTSIZE : GSKEYFONTSIZE).toDouble(&ok);
if (ok) {
bSuccess = doSetFonts(size);
}
}
} else if (key == DCOMPACTFONTSIZE) {
type = TYPECOMPACTFONTSIZE;
bool ok = false;
double size = m_settingDconfig.value(key).toDouble(&ok);
if (ok && m_property->dtkSizeMode == 1) {
bSuccess = doSetFonts(size);
value = QString::number(size);
}
} else {
return;
}
Expand Down Expand Up @@ -490,7 +514,7 @@ void AppearanceManager::setFontSize(double value)
}

if (m_settingDconfig.isValid() && !qFuzzyCompare(value, m_property->fontSize)) {
m_settingDconfig.setValue(GSKEYFONTSIZE, value);
m_settingDconfig.setValue(m_property->dtkSizeMode == 1 ? DCOMPACTFONTSIZE : GSKEYFONTSIZE, value);
m_property->fontSize = value;
updateCustomTheme(TYPEFONTSIZE, QString::number(value));
}
Expand Down Expand Up @@ -554,6 +578,14 @@ void AppearanceManager::setMonospaceFont(QString value)
}
}

void AppearanceManager::setDTKSizeMode(int value)
{
if (value != m_property->dtkSizeMode && m_settingDconfig.isValid()) {
m_settingDconfig.setValue(DDTKSIZEMODE, value);
m_property->dtkSizeMode = value;
}
}

void AppearanceManager::setWindowRadius(int value)
{
if (value != m_property->windowRadius && m_xSetting) {
Expand Down Expand Up @@ -1514,7 +1546,15 @@ void AppearanceManager::doSetByType(const QString &type, const QString &value)
} else if (type == TYPEWALLPAPER) {
doSetCurrentWorkspaceBackground(value);
updateValut = true;
} else if (type == TYPEDTKSIZEMODE) {
bool ok = false;
int mode = value.toInt(&ok);
if (ok) {
QString fontSizeKey = GSKEYFONTSIZE;
doSetDTKSizeMode(mode);
}
}

if (updateValut) {
updateCustomTheme(type, value);
}
Expand Down Expand Up @@ -1734,6 +1774,10 @@ QString AppearanceManager::getWallpaperUri(const QString &index, const QString &
return wallpaper;
}

void AppearanceManager::initDtkSizeMode(){
m_dbusProxy->SetInteger("DTK/SizeMode",m_property->dtkSizeMode);
}

void AppearanceManager::initGlobalTheme()
{
QVector<QSharedPointer<Theme>> globalList = m_subthemes->listGlobalThemes();
Expand Down Expand Up @@ -1827,6 +1871,13 @@ QString AppearanceManager::doGetWorkspaceBackgroundForMonitor(const int &index,
return getWallpaperUri(QString::number(index), strMonitorName);
}

void AppearanceManager::doSetDTKSizeMode(int value) {
if (value != m_property->dtkSizeMode) {
setDTKSizeMode(value);
m_dbusProxy->SetInteger("DTK/SizeMode",value);
}
}

void AppearanceManager::autoChangeBg(QString monitorSpace, QDateTime date)
{
qDebug() << "autoChangeBg: " << monitorSpace << ", " << date;
Expand Down
4 changes: 4 additions & 0 deletions src/service/impl/appearancemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class AppearanceManager : public QObject
void setQtActiveColor(const QString &value);
bool setWallpaperSlideShow(const QString &value);
bool setWallpaperURls(const QString &value);
void setDTKSizeMode(int value);
bool doSetFonts(double size);
bool doUpdateFonts(double size);
bool doSetGlobalTheme(QString value);
Expand All @@ -75,6 +76,7 @@ class AppearanceManager : public QObject
bool doSetBackground(QString value);
bool doSetGreeterBackground(QString value);
QString doGetWallpaperSlideShow(QString monitorName);
void doSetDTKSizeMode(int value);
double getScaleFactor();
ScaleFactors getScreenScaleFactors();
bool setScaleFactor(double scale);
Expand Down Expand Up @@ -108,6 +110,7 @@ class AppearanceManager : public QObject
inline QString getWallpaperSlideShow() {return m_property->wallpaperSlideShow; }
inline QString getWallpaperURls() {return m_property->wallpaperURls;}
inline int getWindowRadius() {return m_property->windowRadius; }
inline int getDTKSizeMode() {return m_property->dtkSizeMode; }

inline QString getGreetBg() {return m_greeterBg; }
inline QMap<QString,QString>& getMonitor() {return m_monitorMap; }
Expand Down Expand Up @@ -139,6 +142,7 @@ public Q_SLOTS:
void initUserObj();
void initCurrentBgs();
void initWallpaperSlideshow();
void initDtkSizeMode();
void iso6709Parsing(QString city, QString coordinates);
void doUpdateWallpaperURIs();
void setPropertyWallpaperURIs(QMap<QString,QString> monitorWallpaperUris);
Expand Down
4 changes: 4 additions & 0 deletions src/service/modules/common/commondefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const QString APPEARANCE_INTERFACE = "org.deepin.dde.Appearance1";
#define GSKEYDTKWINDOWRADIUS "dtkWindowRadius"
#define GSKEYFONTNAME "gtkFontName"
#define DCKEYALLWALLPAPER "All_Wallpaper_Uris"
#define DDTKSIZEMODE "Dtk_Size_Mode"
#define DCOMPACTFONTSIZE "Compact_Font_Size"

#define GTK2CONFDELIM "="
#define GTK3GROUPSETTINGS "Settings"
Expand Down Expand Up @@ -84,6 +86,8 @@ const QString APPEARANCE_INTERFACE = "org.deepin.dde.Appearance1";
#define TYPWINDOWRADIUS "windowradius"
#define TYPEWALLPAPERSLIDESHOW "wallpaperflideshow"
#define TYPEALLWALLPAPER "allwallpaperuris"
#define TYPEDTKSIZEMODE "dtksizemode"
#define TYPECOMPACTFONTSIZE "compactfontsize"
#define MIMETYPEGLOBAL "application/x-global-theme"
#define MIMETYPEGTK "application/x-gtk-theme"
#define MIMETYPEICON "application/x-icon-theme"
Expand Down

0 comments on commit 4c87a35

Please sign in to comment.