Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/plugin-qt/xsettings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
# SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
set(BIN_NAME "plugin-dde-xsettings")
Expand All @@ -11,6 +11,7 @@ set(CMAKE_AUTORCC ON)

include(GNUInstallDirs)
file(GLOB_RECURSE SRCS "*.h" "*.cpp")
list(FILTER SRCS EXCLUDE REGEX "/tests/")

find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core DBus)
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Gui Core)
Expand Down Expand Up @@ -45,3 +46,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/misc/org.deepin.dde.XSettings1.service
RENAME org.deepin.dde.XSettings1.service
)
install_user_symlink(org.deepin.dde.XSettings1.service dde-session-pre.target.wants)

if(BUILD_TESTING)
add_subdirectory(tests)
endif()
12 changes: 5 additions & 7 deletions src/plugin-qt/xsettings/impl/xsettingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ void XSettingsManager::setScreenScaleFactors(const ScaleFactors &factors, bool e
}

setScreenScaleFactorsForQt(factors);

updateDPI();
}

void XSettingsManager::setString(const QString &prop, const QString &v)
Expand Down Expand Up @@ -391,15 +393,11 @@ void XSettingsManager::updateDPI()
int tempXftDpi = m_settingDconfig->value(dcKeyXftDpi).toInt(&bOk);
if (bOk) {
scaledDpi = static_cast<int>((DPI_FALLBACK * 1024) * scale);
if (tempXftDpi != scaledDpi) {
const auto update = makeXftDpiUpdate(tempXftDpi, scaledDpi);
if (update.needsPersist) {
m_settingDconfig->setValue(dcKeyXftDpi, scaledDpi);
XsSetting setting;
setting.prop = "Xft/DPI";
setting.value = scaledDpi;
setting.type = HeadTypeInteger;

xsSettngVec.push_back(setting);
}
xsSettngVec.push_back(update.setting);
}

bOk = false;
Expand Down
16 changes: 15 additions & 1 deletion src/plugin-qt/xsettings/modules/common/common.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2025 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef COMMON_H
Expand Down Expand Up @@ -52,4 +52,18 @@
const int8_t HeadTypeString = 1;
const int8_t HeadTypeColor = 2;

struct XftDpiUpdate
{
bool needsPersist;
XsSetting setting;
};

inline XftDpiUpdate makeXftDpiUpdate(int storedDpi, int scaledDpi)

Check warning on line 61 in src/plugin-qt/xsettings/modules/common/common.h

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'makeXftDpiUpdate' is never used.
{
return {
storedDpi != scaledDpi,
{ HeadTypeInteger, QStringLiteral("Xft/DPI"), scaledDpi },
};
}

#endif // COMMON_H
20 changes: 20 additions & 0 deletions src/plugin-qt/xsettings/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later

find_package(Qt6 REQUIRED COMPONENTS Test)

add_executable(tst-xftdpiupdate
tst_xftdpiupdate.cpp
)

target_include_directories(tst-xftdpiupdate PRIVATE
..
)

target_link_libraries(tst-xftdpiupdate PRIVATE
Qt6::Core
Qt6::Test
)

add_test(NAME xsettings-xftdpiupdate COMMAND tst-xftdpiupdate)
39 changes: 39 additions & 0 deletions src/plugin-qt/xsettings/tests/tst_xftdpiupdate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <QtTest>

Check warning on line 5 in src/plugin-qt/xsettings/tests/tst_xftdpiupdate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtTest> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "modules/common/common.h"

Check warning on line 7 in src/plugin-qt/xsettings/tests/tst_xftdpiupdate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "modules/common/common.h" not found.

class XftDpiUpdateTest : public QObject
{
Q_OBJECT

private Q_SLOTS:

Check warning on line 13 in src/plugin-qt/xsettings/tests/tst_xftdpiupdate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it.
void persistsChangedValue();
void republishesUnchangedValue();
};

void XftDpiUpdateTest::persistsChangedValue()
{
const auto update = makeXftDpiUpdate(96 * 1024, 192 * 1024);

QVERIFY(update.needsPersist);
QCOMPARE(update.setting.prop, QStringLiteral("Xft/DPI"));
QCOMPARE(update.setting.type, HeadTypeInteger);
QCOMPARE(std::get<int>(update.setting.value), 192 * 1024);
}

void XftDpiUpdateTest::republishesUnchangedValue()
{
const auto update = makeXftDpiUpdate(192 * 1024, 192 * 1024);

QVERIFY(!update.needsPersist);
QCOMPARE(update.setting.prop, QStringLiteral("Xft/DPI"));
QCOMPARE(std::get<int>(update.setting.value), 192 * 1024);
}

QTEST_APPLESS_MAIN(XftDpiUpdateTest)

#include "tst_xftdpiupdate.moc"

Check warning on line 39 in src/plugin-qt/xsettings/tests/tst_xftdpiupdate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "tst_xftdpiupdate.moc" not found.
Loading