Repository navigation
fix: migrate treeland output protocol v1 to v2 #1729
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,102 +4,151 @@ | |
|
|
||
| #include "treelandbrightness.h" | ||
|
|
||
| #include "wayland-treeland-output-manager-v1-client-protocol.h" | ||
| #include "wayland-treeland-output-manager-unstable-v2-client-protocol.h" | ||
|
|
||
| #include <QGuiApplication> | ||
| #include <QScreen> | ||
|
|
||
| #include <wayland-client.h> | ||
|
|
||
| namespace osd { | ||
|
|
||
| TreelandColorControl::TreelandColorControl(struct ::treeland_output_color_control_v1 *object, QObject *parent) | ||
| TreelandPictureControl::TreelandPictureControl(struct ::treeland_output_picture_control_v2 *object, QObject *parent) | ||
| : QObject(parent) | ||
| , QtWayland::treeland_output_color_control_v1(object) | ||
| , QtWayland::treeland_output_picture_control_v2(object) | ||
| { | ||
| } | ||
|
|
||
| TreelandColorControl::~TreelandColorControl() | ||
| TreelandPictureControl::~TreelandPictureControl() | ||
| { | ||
| if (isInitialized()) { | ||
| destroy(); | ||
| } | ||
| } | ||
|
|
||
| double TreelandColorControl::brightness() const | ||
| double TreelandPictureControl::brightness() const | ||
| { | ||
| return m_brightness; | ||
| } | ||
|
|
||
| void TreelandColorControl::treeland_output_color_control_v1_brightness(wl_fixed_t brightness) | ||
| void TreelandPictureControl::treeland_output_picture_control_v2_brightness(wl_fixed_t brightness) | ||
| { | ||
| m_brightness = wl_fixed_to_double(brightness); | ||
| Q_EMIT brightnessChanged(m_brightness); | ||
| } | ||
|
|
||
| void TreelandPictureControl::treeland_output_picture_control_v2_result(uint32_t result) | ||
| { | ||
| Q_EMIT resultReceived(result); | ||
| } | ||
|
|
||
| TreelandBrightness::TreelandBrightness(QObject *parent) | ||
| : QWaylandClientExtensionTemplate<TreelandBrightness>(treeland_output_manager_v1_interface.version) | ||
| : QWaylandClientExtensionTemplate<TreelandBrightness>(treeland_output_manager_v2_interface.version) | ||
| { | ||
| setParent(parent); | ||
|
|
||
| m_uuidManager = new ::TreelandOutputUuidManager(this); | ||
| connect(m_uuidManager, &::TreelandOutputUuidManager::activeChanged, this, &TreelandBrightness::refresh); | ||
| connect(this, &TreelandBrightness::activeChanged, this, &TreelandBrightness::refresh); | ||
| connect(qApp, &QGuiApplication::primaryScreenChanged, this, &TreelandBrightness::refresh); | ||
| } | ||
|
|
||
| TreelandBrightness::~TreelandBrightness() | ||
| { | ||
| delete m_control; | ||
| m_control = nullptr; | ||
| m_output = nullptr; | ||
| m_primaryScreen = nullptr; | ||
| delete m_uuidRequest; | ||
| m_uuidRequest = nullptr; | ||
| if (isInitialized()) { | ||
| destroy(); | ||
| } | ||
| } | ||
|
|
||
| void TreelandBrightness::refresh() | ||
| { | ||
| if (!isActive()) { | ||
| if (!isActive() || !m_uuidManager || !m_uuidManager->isActive()) { | ||
| delete m_control; | ||
| m_control = nullptr; | ||
| m_output = nullptr; | ||
| m_primaryScreen = nullptr; | ||
| delete m_uuidRequest; | ||
| m_uuidRequest = nullptr; | ||
| m_currentUuid.clear(); | ||
| return; | ||
| } | ||
|
|
||
| struct wl_output *output = primaryWlOutput(); | ||
| if (m_control && m_output == output && output) { | ||
| QScreen *screen = qApp->primaryScreen(); | ||
| if (m_primaryScreen == screen && m_control && !m_currentUuid.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| delete m_control; | ||
| m_control = nullptr; | ||
| m_output = output; | ||
| m_primaryScreen = screen; | ||
| m_currentUuid.clear(); | ||
|
|
||
| if (!output) { | ||
| if (!screen) { | ||
| return; | ||
| } | ||
|
|
||
| auto *raw = get_color_control(output); | ||
| if (!raw) { | ||
| requestPrimaryUuid(); | ||
| } | ||
|
|
||
| void TreelandBrightness::requestPrimaryUuid() | ||
| { | ||
| if (!m_uuidManager || !m_uuidManager->isActive()) | ||
| return; | ||
| } | ||
|
|
||
| m_control = new TreelandColorControl(raw, this); | ||
| connect(m_control, &TreelandColorControl::brightnessChanged, | ||
| this, &TreelandBrightness::brightnessChanged); | ||
| if (!m_primaryScreen) | ||
| return; | ||
|
|
||
| auto *waylandScreen = m_primaryScreen->nativeInterface<QNativeInterface::QWaylandScreen>(); | ||
| if (!waylandScreen || !waylandScreen->output()) | ||
| return; | ||
|
|
||
| struct wl_output *output = waylandScreen->output(); | ||
|
|
||
| delete m_uuidRequest; | ||
| m_uuidRequest = nullptr; | ||
|
|
||
| auto *raw = m_uuidManager->get_uuid(output); | ||
| if (!raw) | ||
| return; | ||
|
|
||
| m_uuidRequest = new ::TreelandOutputUuid(raw, this); | ||
|
|
||
| connect(m_uuidRequest, &::TreelandOutputUuid::uuidReceived, this, [this](const QString &uuid) { | ||
| if (sender() != m_uuidRequest) | ||
| return; | ||
|
|
||
| if (uuid.isEmpty()) | ||
| return; | ||
|
Comment on lines
+124
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Brightness monitoring stops after lookup failures When the UUID is empty, Retry UUID/control resolution and notify brightness consumers on each failed resolution path. Also at Prompt for AI agentsIn `panels/notification/osd/brightness/treelandbrightness.cpp` at lines 124-125:
**Brightness monitoring stops after lookup failures**
When the UUID is empty, `get_picture_control()` returns null, or the picture control reports `commit_result_invalid_output`, `TreelandBrightness` returns or clears its control without retrying UUID/control resolution or notifying brightness consumers, so `brightness()` returns zero or the OSD retains stale brightness until an unrelated refresh.
Retry UUID/control resolution and notify brightness consumers on each failed resolution path.
Also at `panels/notification/osd/brightness/treelandbrightness.cpp:132-133`, `panels/notification/osd/brightness/treelandbrightness.cpp:139-144`. |
||
|
|
||
| m_currentUuid = uuid; | ||
|
|
||
| delete m_uuidRequest; | ||
| m_uuidRequest = nullptr; | ||
|
|
||
| auto *raw = get_picture_control(uuid); | ||
| if (!raw) | ||
| return; | ||
|
|
||
| m_control = new TreelandPictureControl(raw, this); | ||
| connect(m_control, &TreelandPictureControl::brightnessChanged, | ||
| this, &TreelandBrightness::brightnessChanged); | ||
| connect(m_control, &TreelandPictureControl::resultReceived, this, [this](uint32_t result) { | ||
| if (result == TreelandPictureControl::commit_result_invalid_output) { | ||
| delete m_control; | ||
| m_control = nullptr; | ||
| m_currentUuid.clear(); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| double TreelandBrightness::brightness() const | ||
| { | ||
| return m_control ? m_control->brightness() : 0.0; | ||
| } | ||
|
|
||
| struct wl_output *TreelandBrightness::primaryWlOutput() const | ||
| { | ||
| auto *screen = qApp->primaryScreen(); | ||
| if (!screen) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| auto *waylandScreen = screen->nativeInterface<QNativeInterface::QWaylandScreen>(); | ||
| return waylandScreen ? waylandScreen->output() : nullptr; | ||
| } | ||
|
|
||
| } // namespace osd | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
|
|
||
| find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Widget REQUIRED) | ||
| find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Widgets Gui WaylandClient) | ||
| find_package(TreelandProtocols REQUIRED) | ||
| find_package(TreelandProtocols 0.9 REQUIRED) | ||
| pkg_check_modules(WaylandClient REQUIRED IMPORTED_TARGET wayland-client) | ||
|
|
||
| if (NOT DEFINED SYSTEMD_USER_UNIT_DIR) | ||
|
|
@@ -23,14 +23,17 @@ add_executable(dde-shell | |
| shell.cpp | ||
| treelandoutputwatcher.h | ||
| treelandoutputwatcher.cpp | ||
| treelandoutputuuid.h | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 先放osd插件或者搞个库吧,不放在shell里, |
||
| treelandoutputuuid.cpp | ||
| dde-shell.qrc | ||
| override_dtkdeclarative_qml.qrc | ||
| dde-shell-icons.qrc | ||
| ) | ||
|
|
||
| qt_generate_wayland_protocol_client_sources(dde-shell | ||
| FILES | ||
| ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-manager-v1.xml | ||
| ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-manager-unstable-v2.xml | ||
| ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-uuid-unstable-v1.xml | ||
| ) | ||
|
|
||
| target_compile_definitions(dde-shell | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #include "treelandoutputuuid.h" | ||
| #include "wayland-treeland-output-uuid-unstable-v1-client-protocol.h" | ||
|
|
||
| TreelandOutputUuidManager::TreelandOutputUuidManager(QObject *parent) | ||
| : QWaylandClientExtensionTemplate<TreelandOutputUuidManager>(treeland_output_uuid_manager_v1_interface.version) | ||
| { | ||
| setParent(parent); | ||
| } | ||
|
|
||
| TreelandOutputUuidManager::~TreelandOutputUuidManager() | ||
| { | ||
| if (isInitialized()) | ||
| destroy(); | ||
| } | ||
|
|
||
| TreelandOutputUuid::TreelandOutputUuid(struct ::treeland_output_uuid_v1 *object, QObject *parent) | ||
| : QObject(parent) | ||
| , QtWayland::treeland_output_uuid_v1(object) | ||
| { | ||
| } | ||
|
|
||
| TreelandOutputUuid::~TreelandOutputUuid() | ||
| { | ||
| if (isInitialized()) | ||
| destroy(); | ||
| } | ||
|
|
||
| void TreelandOutputUuid::treeland_output_uuid_v1_uuid(const QString &uuid) | ||
| { | ||
| m_uuid = uuid; | ||
| Q_EMIT uuidReceived(uuid); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "qwayland-treeland-output-uuid-unstable-v1.h" | ||
| #include <QtWaylandClient/QWaylandClientExtension> | ||
| #include <QObject> | ||
| #include <QString> | ||
|
|
||
| class TreelandOutputUuidManager | ||
| : public QWaylandClientExtensionTemplate<TreelandOutputUuidManager> | ||
| , public QtWayland::treeland_output_uuid_manager_v1 | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| TreelandOutputUuidManager(QObject *parent = nullptr); | ||
| ~TreelandOutputUuidManager(); | ||
| }; | ||
|
|
||
| class TreelandOutputUuid | ||
| : public QObject | ||
| , public QtWayland::treeland_output_uuid_v1 | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| TreelandOutputUuid(struct ::treeland_output_uuid_v1 *object, QObject *parent = nullptr); | ||
| ~TreelandOutputUuid() override; | ||
|
|
||
| QString uuid() const { return m_uuid; } | ||
|
|
||
| Q_SIGNALS: | ||
| void uuidReceived(const QString &uuid); | ||
|
|
||
| protected: | ||
| void treeland_output_uuid_v1_uuid(const QString &uuid) override; | ||
|
|
||
| private: | ||
| QString m_uuid; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Brightness stays bound to old output
When the primary screen changes or disappears while a UUID request is outstanding and the new screen has no usable Wayland output,
refresh()andrequestPrimaryUuid()return without cancelling the old request, so its callback passes the sender check and installs a picture control for the previous output; the OSD then reports stale brightness.Cancel or invalidate the outstanding UUID request before returning when the primary screen has no usable Wayland output.
Also at
panels/notification/osd/brightness/treelandbrightness.cpp:102-118,panels/notification/osd/brightness/treelandbrightness.cpp:120-122.Prompt for AI agents