Skip to content
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
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ qt_add_qml_module(libtreeland
workspace/workspaceanimationcontroller.h
workspace/workspacemodel.cpp
workspace/workspacemodel.h
xsettings/abstractsettings.h
xsettings/abstractsettings.cpp
xsettings/xsettings.h
xsettings/xsettings.cpp
xsettings/xresource.h
xsettings/xresource.cpp
xsettings/settingmanager.h
xsettings/settingmanager.cpp

QML_FILES
core/qml/PrimaryOutput.qml
Expand Down
3 changes: 3 additions & 0 deletions src/common/treelandlogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ Q_LOGGING_CATEGORY(treelandGreeter, "treeland.greeter")

// FPS display
Q_LOGGING_CATEGORY(treelandFpsDisplay, "treeland.fpsdisplay")

// xsettings
Q_LOGGING_CATEGORY(treelandXsettings, "treeland.xsettings")
3 changes: 3 additions & 0 deletions src/common/treelandlogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ Q_DECLARE_LOGGING_CATEGORY(treelandGreeter)
// FPS display
Q_DECLARE_LOGGING_CATEGORY(treelandFpsDisplay)

// xsettings
Q_DECLARE_LOGGING_CATEGORY(treelandXsettings)

#endif // TREELAND_LOGGING_H
12 changes: 0 additions & 12 deletions src/core/shellhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,6 @@ WXWayland *ShellHandler::createXWayland(WServer *server,
xwayland->setAtomSupported(atomPid, true);
auto atomNoTitlebar = xwayland->atom("_DEEPIN_NO_TITLEBAR");
xwayland->setAtomSupported(atomNoTitlebar, true);
// TODO: set other xsettings and sync
setResourceManagerAtom(
xwayland,
QString("Xft.dpi:\t%1")
.arg(96 * m_rootSurfaceContainer->window()->effectiveDevicePixelRatio())
.toUtf8());
connect(Helper::instance()->window(),
&WOutputRenderWindow::effectiveDevicePixelRatioChanged,
xwayland,
[xwayland, this](qreal dpr) {
setResourceManagerAtom(xwayland, QString("Xft.dpi:\t%1").arg(96 * dpr).toUtf8());
});
});
return xwayland;
}
Expand Down
35 changes: 35 additions & 0 deletions src/seat/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
#include "common/treelandlogging.h"
#include "modules/ddm/ddminterfacev1.h"
#include "treelandconfig.hpp"
#include "core/treeland.h"

Check warning on line 41 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "core/treeland.h" not found.
#include "greeter/greeterproxy.h"

Check warning on line 42 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "greeter/greeterproxy.h" not found.
#include "modules/screensaver/screensaverinterfacev1.h"

Check warning on line 43 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "modules/screensaver/screensaverinterfacev1.h" not found.
#include "xsettings/settingmanager.h"

Check warning on line 44 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "xsettings/settingmanager.h" not found.

#include <xcb/xcb.h>

Check warning on line 46 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <xcb/xcb.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <xcb/xproto.h>

Check warning on line 47 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <WBackend>
#include <WForeignToplevel>
Expand Down Expand Up @@ -97,9 +98,10 @@
#include <qwxwaylandsurface.h>
#include <qwoutputpowermanagementv1.h>
#include <qwidlenotifyv1.h>
#include <qwidleinhibitv1.h>

Check warning on line 101 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <qwidleinhibitv1.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <qwalphamodifierv1.h>

Check warning on line 102 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <qwalphamodifierv1.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <qwdrm.h>

Check warning on line 103 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <qwdrm.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <qwxwayland.h>

Check warning on line 104 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QAction>
#include <QKeySequence>
Expand Down Expand Up @@ -176,6 +178,16 @@
{
qCDebug(treelandCore) << "Deleting session for uid:" << uid << socket;
Q_EMIT aboutToBeDestroyed();

if (settingManagerThread) {
settingManagerThread->quit();
settingManagerThread->wait(QDeadlineTimer(25000));
}

if (settingManager) {
delete settingManager;
settingManager = nullptr;
}
if (xwayland)
Helper::instance()->shellHandler()->removeXWayland(xwayland);
if (socket)
Expand Down Expand Up @@ -2299,6 +2311,29 @@
if (!session->noTitlebarAtom) {
qCWarning(treelandInput) << "Failed to intern atom:" << _DEEPIN_NO_TITLEBAR;
}
session->settingManager = new SettingManager(session->xwayland->xcbConnection(),
session->xwayland);
session->settingManagerThread = new QThread(session->xwayland);

session->settingManager->moveToThread(session->settingManagerThread);
connect(session->settingManagerThread, &QThread::started, this, [this, session]{
const qreal scale = m_rootSurfaceContainer->window()->effectiveDevicePixelRatio();
QMetaObject::invokeMethod(session->settingManager, [session, scale]() {
session->settingManager->setGlobalScale(scale);
session->settingManager->apply();
}, Qt::QueuedConnection);

QObject::connect(Helper::instance()->window(),
&WOutputRenderWindow::effectiveDevicePixelRatioChanged,
session->settingManager,
[session](qreal dpr) {
session->settingManager->setGlobalScale(dpr);
session->settingManager->apply();
}, Qt::QueuedConnection);
});

connect(session->settingManagerThread, &QThread::finished, session->settingManagerThread, &QThread::deleteLater);
session->settingManagerThread->start();
}
});
return xwayland;
Expand Down
4 changes: 4 additions & 0 deletions src/seat/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class DDMInterfaceV1;
class TreelandConfig;
class FpsDisplayManager;
class ScreensaverInterfaceV1;
class SettingManager;

struct wlr_idle_inhibitor_v1;
struct wlr_output_power_v1_set_mode_event;
struct wlr_ext_foreign_toplevel_image_capture_source_manager_v1_request;
Expand All @@ -121,6 +123,8 @@ struct Session : QObject {
WSocket *socket = nullptr;
WXWayland *xwayland = nullptr;
quint32 noTitlebarAtom = XCB_ATOM_NONE;
SettingManager *settingManager = nullptr;
QThread *settingManagerThread = nullptr;

~Session();

Expand Down
14 changes: 14 additions & 0 deletions src/xsettings/abstractsettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2025 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "abstractsettings.h"

AbstractSettings::AbstractSettings(xcb_connection_t *connection, QObject *parent)
: QObject(parent)
, m_connection(connection)
{
}

AbstractSettings::~AbstractSettings()
{
}
35 changes: 35 additions & 0 deletions src/xsettings/abstractsettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2025 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#pragma once

#include <xcb/xcb.h>

#include <QObject>
#include <QVariant>

class AbstractSettings : public QObject
{
Q_OBJECT
public:
explicit AbstractSettings(xcb_connection_t *connection, QObject *parent = nullptr);
~AbstractSettings() override;

virtual bool initialized() const = 0;
virtual bool isEmpty() const = 0;

virtual bool contains(const QByteArray &property) const = 0;
virtual QVariant getPropertyValue(const QByteArray &property) const = 0;
virtual void setPropertyValue(const QByteArray &property, const QVariant &value) = 0;
virtual QByteArrayList propertyList() const = 0;
virtual void apply() = 0;

Q_SIGNALS:
void propertyChanged(const QByteArray &property, const QVariant &value);
void propertyAdded(const QByteArray &property, const QVariant &value);
void propertyRemoved(const QByteArray &property, const QVariant &value);

protected:
xcb_connection_t *m_connection = nullptr;
xcb_atom_t m_atom = XCB_ATOM_NONE;
};
109 changes: 109 additions & 0 deletions src/xsettings/settingmanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright (C) 2025 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "settingmanager.h"
#include "common/treelandlogging.h"

const static qreal BASE_DPI = 96;
const static qreal XSETTINGS_BASE_DPI_FIXED = BASE_DPI * 1024;

SettingManager::SettingManager(xcb_connection_t *connection, QObject *parent)
: QObject(parent)
, m_resource(new XResource(connection, this))
, m_settings(new XSettings(connection, this))
{
}

SettingManager::~SettingManager()
{
}

void SettingManager::setGTKTheme(const QString &themeName)
{
m_resource->setPropertyValue(XResource::toByteArray(XResource::Gtk_ThemeName), themeName);
m_settings->setPropertyValue(XSettings::toByteArray(XSettings::Gtk_ThemeName), themeName);
}

QString SettingManager::GTKTheme() const
{
return m_settings->getPropertyValue(XSettings::toByteArray(XSettings::Gtk_ThemeName)).toString();
}

void SettingManager::setFont(const QString &name)
{
m_resource->setPropertyValue(XResource::toByteArray(XResource::Gtk_FontName), name);
m_settings->setPropertyValue(XSettings::toByteArray(XSettings::Gtk_FontName), name);
}

QString SettingManager::font() const
{
return m_settings->getPropertyValue(XSettings::toByteArray(XSettings::Gtk_FontName)).toString();
}

void SettingManager::setIconTheme(const QString &theme)
{
m_resource->setPropertyValue(XResource::toByteArray(XResource::Gtk_IconThemeName), theme);
m_settings->setPropertyValue(XSettings::toByteArray(XSettings::Gtk_IconThemeName), theme);
}

QString SettingManager::iconTheme() const
{
return m_settings->getPropertyValue(XSettings::toByteArray(XSettings::Gtk_IconThemeName)).toString();
}

void SettingManager::setSoundTheme(const QString &theme)
{
m_resource->setPropertyValue(XResource::toByteArray(XResource::Net_SoundThemeName), theme);
m_settings->setPropertyValue(XSettings::toByteArray(XSettings::Net_SoundThemeName), theme);
}

QString SettingManager::soundTheme() const
{
return m_settings->getPropertyValue(XSettings::toByteArray(XSettings::Net_SoundThemeName)).toString();
}

void SettingManager::setCursorTheme(const QString &theme)
{
m_resource->setPropertyValue(XResource::toByteArray(XResource::Gtk_CursorThemeName), theme);
m_settings->setPropertyValue(XSettings::toByteArray(XSettings::Gtk_CursorThemeName), theme);
}

QString SettingManager::cursorTheme() const
{
return m_settings->getPropertyValue(XSettings::toByteArray(XSettings::Gtk_CursorThemeName)).toString();
}

void SettingManager::setCursorSize(qreal value)
{
m_resource->setPropertyValue(XResource::toByteArray(XResource::Xcursor_Size), value);
m_settings->setPropertyValue(XSettings::toByteArray(XSettings::Xcursor_Size), value);
}

qreal SettingManager::cursorSize() const
{
return m_settings->getPropertyValue(XSettings::toByteArray(XSettings::Xcursor_Size)).toReal();
}

void SettingManager::setDoubleClickInterval(int interval)
{
m_settings->setPropertyValue(XSettings::toByteArray(XSettings::Net_DoubleClickTime), interval);
}

void SettingManager::setGlobalScale(qreal scale)
{
m_resource->setPropertyValue(XResource::toByteArray(XResource::Xft_DPI), scale * BASE_DPI);
m_settings->setPropertyValue(XSettings::toByteArray(XSettings::Gdk_WindowScalingFactor), qFloor(scale));
m_settings->setPropertyValue(XSettings::toByteArray(XSettings::Gdk_UnscaledDPI), scale * XSETTINGS_BASE_DPI_FIXED);
m_settings->setPropertyValue(XSettings::toByteArray(XSettings::Xft_DPI), scale * XSETTINGS_BASE_DPI_FIXED);
}

qreal SettingManager::globalScale() const
{
return m_settings->getPropertyValue(XSettings::toByteArray(XSettings::Gdk_UnscaledDPI)).toReal() / XSETTINGS_BASE_DPI_FIXED;
}

void SettingManager::apply()
{
m_resource->apply();
m_settings->apply();
}
46 changes: 46 additions & 0 deletions src/xsettings/settingmanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2025 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#pragma once

#include "xresource.h"
#include "xsettings.h"

#include <QObject>

class SettingManager : public QObject
{
Q_OBJECT
public:
explicit SettingManager(xcb_connection_t *connection, QObject *parent = nullptr);
~SettingManager() override;

void setGTKTheme(const QString &themeName);
QString GTKTheme() const;

void setFont(const QString &name);
QString font() const;

void setIconTheme(const QString &theme);
QString iconTheme() const;

void setSoundTheme(const QString &theme);
QString soundTheme() const;

void setCursorTheme(const QString &theme);
QString cursorTheme() const;

void setCursorSize(qreal value);
qreal cursorSize() const;

void setDoubleClickInterval(int interval);

void setGlobalScale(qreal scale);
qreal globalScale() const;

void apply();

private:
XResource *m_resource = nullptr;
XSettings *m_settings = nullptr;
};
Loading