Repository navigation
fix: upgrade treeland output protocol from v1 to v2 with UUID support [cherry-pick] #1918
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; | ||
|
|
||
| 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(); | ||
|
Comment on lines
+141
to
+143
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 stays stale after invalid output When the compositor reports Emit the brightness update and retry acquiring the UUID and picture control after invalid output. Prompt for AI agentsIn `panels/notification/osd/brightness/treelandbrightness.cpp` at lines 141-143:
**Brightness stays stale after invalid output**
When the compositor reports `commit_result_invalid_output` while the primary screen remains unchanged, the handler deletes `m_control` and clears `m_currentUuid` without emitting `brightnessChanged` or requesting a replacement control, so the provider loses brightness and the applet keeps displaying its cached value until another refresh trigger.
Emit the brightness update and retry acquiring the UUID and picture control after invalid output. |
||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| 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 |
|---|---|---|
| @@ -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.
🟠 High · Event handling crashes the OSD
When a UUID or picture-control proxy delivers its event, the callbacks synchronously delete the proxy whose event is being dispatched, which can invalidate the active Wayland callback and crash the OSD.
Defer proxy deletion until event dispatch has returned.
Also at
panels/notification/osd/brightness/treelandbrightness.cpp:141-143.Prompt for AI agents