| 1 |
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#include "personalizationwaylandclientextension.h" |
| 6 |
|
| 7 |
#include <private/qguiapplication_p.h> |
| 8 |
#include <private/qwaylandintegration_p.h> |
| 9 |
#include <private/qwaylandwindow_p.h> |
| 10 |
#include <qwaylandclientextension.h> |
| 11 |
#include "dplatformtheme.h" |
| 12 |
|
| 13 |
#include <QtWaylandClient/private/qwaylandsurface_p.h> |
| 14 |
#include <QtWaylandClient/private/qwaylandwindow_p.h> |
| 15 |
#include <QGuiApplication> |
| 16 |
|
| 17 |
DGUI_BEGIN_NAMESPACE |
| 18 |
|
| 19 |
PersonalizationManager::PersonalizationManager() |
| 20 |
: QWaylandClientExtensionTemplate<PersonalizationManager>(treeland_personalization_manager_v1_interface.version) |
| 21 |
, m_isSupported(false) |
| 22 |
{ |
| 23 |
QtWaylandClient::QWaylandIntegration *waylandIntegration = static_cast<QtWaylandClient::QWaylandIntegration *>(QGuiApplicationPrivate::platformIntegration()); |
| 24 |
if (!waylandIntegration) { |
| 25 |
qWarning() << "waylandIntegration is nullptr!!!"; |
| 26 |
return; |
| 27 |
} |
| 28 |
m_waylandDisplay = waylandIntegration->display(); |
| 29 |
if (m_waylandDisplay == nullptr) { |
| 30 |
qWarning() << "waylandDisplay is nullptr!!!"; |
| 31 |
return; |
| 32 |
} |
| 33 |
addListener(); |
| 34 |
m_isSupported = m_waylandDisplay->hasRegistryGlobal(QString::fromUtf8(treeland_personalization_manager_v1_interface.name)); |
| 35 |
if (!m_isSupported) { |
| 36 |
qWarning() << "PersonalizationManager is not support"; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
void PersonalizationManager::addListener() |
| 41 |
{ |
| 42 |
m_waylandDisplay->addRegistryListener(&handleListenerGlobal, this); |
| 43 |
} |
| 44 |
|
| 45 |
void PersonalizationManager::removeListener() |
| 46 |
{ |
| 47 |
m_waylandDisplay->removeListener(&handleListenerGlobal, this); |
| 48 |
} |
| 49 |
|
| 50 |
void PersonalizationManager::handleListenerGlobal(void *data, wl_registry *registry, uint32_t id, const QString &interface, uint32_t version) |
| 51 |
{ |
| 52 |
if (interface == treeland_personalization_manager_v1_interface.name) { |
| 53 |
PersonalizationManager *integration = static_cast<PersonalizationManager *>(data); |
| 54 |
if (!integration) { |
| 55 |
qWarning() << "integration is nullptr!!!"; |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
integration->init(registry, id, version); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
PersonalizationManager *PersonalizationManager::instance() |
| 64 |
{ |
| 65 |
static PersonalizationManager instance; |
| 66 |
return &instance; |
| 67 |
} |
| 68 |
|
| 69 |
PersonalizationWindowContext::PersonalizationWindowContext(struct ::treeland_personalization_window_context_v1 *context) |
| 70 |
: QWaylandClientExtensionTemplate<PersonalizationWindowContext>(treeland_personalization_window_context_v1_interface.version) |
| 71 |
, QtWayland::treeland_personalization_window_context_v1(context) |
| 72 |
{ |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
PersonalizationAppearanceContext::PersonalizationAppearanceContext(struct ::treeland_personalization_appearance_context_v1 *context, DTreelandPlatformInterface *interface) |
| 77 |
: QWaylandClientExtensionTemplate<PersonalizationAppearanceContext>(treeland_personalization_appearance_context_v1_interface.version) |
| 78 |
, QtWayland::treeland_personalization_appearance_context_v1(context) |
| 79 |
, m_interface(interface) |
| 80 |
{ |
| 81 |
get_round_corner_radius(); |
| 82 |
get_icon_theme(); |
| 83 |
get_active_color(); |
| 84 |
get_window_theme_type(); |
| 85 |
get_window_opacity(); |
| 86 |
} |
| 87 |
|
| 88 |
void PersonalizationAppearanceContext::treeland_personalization_appearance_context_v1_round_corner_radius(int32_t radius) |
| 89 |
{ |
| 90 |
m_interface->m_windowRadius = radius; |
| 91 |
emit m_interface->m_platformTheme->windowRadiusChanged(radius); |
| 92 |
} |
| 93 |
|
| 94 |
void PersonalizationAppearanceContext::treeland_personalization_appearance_context_v1_icon_theme(const QString &theme_name) |
| 95 |
{ |
| 96 |
m_interface->m_iconThemeName = theme_name.toUtf8(); |
| 97 |
emit m_interface->m_platformTheme->iconThemeNameChanged(theme_name.toUtf8()); |
| 98 |
} |
| 99 |
|
| 100 |
void PersonalizationAppearanceContext::treeland_personalization_appearance_context_v1_active_color(const QString &active_color) |
| 101 |
{ |
| 102 |
m_interface->m_activeColor = active_color; |
| 103 |
emit m_interface->m_platformTheme->activeColorChanged(active_color); |
| 104 |
} |
| 105 |
|
| 106 |
void PersonalizationAppearanceContext::treeland_personalization_appearance_context_v1_window_theme_type(uint32_t type) |
| 107 |
{ |
| 108 |
QString theme = QStringLiteral("deepin"); |
| 109 |
if (type == PersonalizationAppearanceContext::theme_type::theme_type_dark) { |
| 110 |
theme = theme + QStringLiteral("-dark"); |
| 111 |
} |
| 112 |
m_interface->m_themeName = theme.toUtf8(); |
| 113 |
emit m_interface->m_platformTheme->themeNameChanged(theme.toUtf8()); |
| 114 |
} |
| 115 |
|
| 116 |
void PersonalizationAppearanceContext::treeland_personalization_appearance_context_v1_window_opacity(uint32_t opacity) |
| 117 |
{ |
| 118 |
m_interface->m_blurOpacity = opacity; |
| 119 |
} |
| 120 |
|
| 121 |
PersonalizationFontContext::PersonalizationFontContext(struct ::treeland_personalization_font_context_v1 *context, DTreelandPlatformInterface *interface) |
| 122 |
: QWaylandClientExtensionTemplate<PersonalizationFontContext>(treeland_personalization_font_context_v1_interface.version) |
| 123 |
, QtWayland::treeland_personalization_font_context_v1(context) |
| 124 |
, m_interface(interface) |
| 125 |
{ |
| 126 |
get_font(); |
| 127 |
get_monospace_font(); |
| 128 |
get_font_size(); |
| 129 |
} |
| 130 |
|
| 131 |
void PersonalizationFontContext::treeland_personalization_font_context_v1_font(const QString &font_name) |
| 132 |
{ |
| 133 |
m_interface->m_fontName = font_name.toUtf8(); |
| 134 |
emit m_interface->m_platformTheme->fontNameChanged(font_name.toUtf8()); |
| 135 |
} |
| 136 |
|
| 137 |
void PersonalizationFontContext::treeland_personalization_font_context_v1_monospace_font(const QString &font_name) |
| 138 |
{ |
| 139 |
m_interface->m_monoFontName = font_name.toUtf8(); |
| 140 |
emit m_interface->m_platformTheme->monoFontNameChanged(font_name.toUtf8()); |
| 141 |
} |
| 142 |
|
| 143 |
void PersonalizationFontContext::treeland_personalization_font_context_v1_font_size(uint32_t font_size) |
| 144 |
{ |
| 145 |
// treeland侧无法存储浮点数,约定 font_size 为 10 倍的 pointSize |
| 146 |
qreal pointSize = font_size / 10.0; |
| 147 |
pointSize = qBound(8.25, pointSize, 15.00); |
| 148 |
m_interface->m_fontPointSize = pointSize; |
| 149 |
emit m_interface->m_platformTheme->fontPointSizeChanged(pointSize); |
| 150 |
} |
| 151 |
|
| 152 |
DGUI_END_NAMESPACE |