From f6eccc78982df87e190c0d603a42e9f7c68cfef2 Mon Sep 17 00:00:00 2001 From: luhongxu Date: Wed, 9 Sep 2026 17:09:48 +0800 Subject: [PATCH] fix: migrate treeland output protocol v1 to v2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Update find_package to require TreelandProtocols 0.6 in both CMakeLists 2. Migrate treelandoutputwatcher to treeland_output_manager_v2 with wl_output 3. Migrate treelandbrightness from color_control_v1 to picture_control_v2 4. Handle null primary_output with early return for v2 allow-null Log: Migrated treeland output protocol consumers from v1 to v2 Influence: 1. Test primary screen switching in multi-monitor setups 2. Verify OSD brightness display reflects correct values 3. Test dde-shell does not crash when no output is available fix: 迁移 treeland output 协议 v1 到 v2 1. 更新两处 CMakeLists 的 find_package 要求 TreelandProtocols 0.6 2. 迁移 treelandoutputwatcher 至 treeland_output_manager_v2 使用 wl_output 3. 迁移 treelandbrightness 从 color_control_v1 到 picture_control_v2 4. 处理 null primary_output 提前返回以适配 v2 allow-null 语义 Log: 迁移 treeland output 协议消费者从 v1 到 v2 Influence: 1. 测试多屏环境下主屏切换功能 2. 验证 OSD 亮度显示反映正确数值 3. 测试无输出设备时 dde-shell 不崩溃 Ref: DDE-232 --- panels/notification/osd/brightness/CMakeLists.txt | 4 ++-- .../osd/brightness/treelandbrightness.cpp | 12 ++++++------ .../osd/brightness/treelandbrightness.h | 14 +++++++------- shell/CMakeLists.txt | 4 ++-- shell/treelandoutputwatcher.cpp | 11 ++++++----- shell/treelandoutputwatcher.h | 8 +++++--- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/panels/notification/osd/brightness/CMakeLists.txt b/panels/notification/osd/brightness/CMakeLists.txt index 9a1e2b0b8..98a60b822 100644 --- a/panels/notification/osd/brightness/CMakeLists.txt +++ b/panels/notification/osd/brightness/CMakeLists.txt @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -find_package(TreelandProtocols REQUIRED) +find_package(TreelandProtocols 0.6 REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(WaylandClient REQUIRED IMPORTED_TARGET wayland-client) @@ -16,7 +16,7 @@ add_library(osd-brightness SHARED qt_generate_wayland_protocol_client_sources(osd-brightness NO_INCLUDE_CORE_ONLY FILES - ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-manager-v1.xml + ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-manager-unstable-v2.xml ) target_link_libraries(osd-brightness PRIVATE diff --git a/panels/notification/osd/brightness/treelandbrightness.cpp b/panels/notification/osd/brightness/treelandbrightness.cpp index dd6b99983..1e3046228 100644 --- a/panels/notification/osd/brightness/treelandbrightness.cpp +++ b/panels/notification/osd/brightness/treelandbrightness.cpp @@ -4,7 +4,7 @@ #include "treelandbrightness.h" -#include "wayland-treeland-output-manager-v1-client-protocol.h" +#include "wayland-treeland-output-manager-unstable-v2-client-protocol.h" #include #include @@ -13,9 +13,9 @@ namespace osd { -TreelandColorControl::TreelandColorControl(struct ::treeland_output_color_control_v1 *object, QObject *parent) +TreelandColorControl::TreelandColorControl(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) { } @@ -31,14 +31,14 @@ double TreelandColorControl::brightness() const return m_brightness; } -void TreelandColorControl::treeland_output_color_control_v1_brightness(wl_fixed_t brightness) +void TreelandColorControl::treeland_output_picture_control_v2_brightness(wl_fixed_t brightness) { m_brightness = wl_fixed_to_double(brightness); Q_EMIT brightnessChanged(m_brightness); } TreelandBrightness::TreelandBrightness(QObject *parent) - : QWaylandClientExtensionTemplate(treeland_output_manager_v1_interface.version) + : QWaylandClientExtensionTemplate(treeland_output_manager_v2_interface.version) { setParent(parent); connect(this, &TreelandBrightness::activeChanged, this, &TreelandBrightness::refresh); @@ -76,7 +76,7 @@ void TreelandBrightness::refresh() return; } - auto *raw = get_color_control(output); + auto *raw = get_picture_control(output); if (!raw) { return; } diff --git a/panels/notification/osd/brightness/treelandbrightness.h b/panels/notification/osd/brightness/treelandbrightness.h index ea87d8a92..2b4b9d07b 100644 --- a/panels/notification/osd/brightness/treelandbrightness.h +++ b/panels/notification/osd/brightness/treelandbrightness.h @@ -4,23 +4,23 @@ #pragma once -#include "qwayland-treeland-output-manager-v1.h" +#include "qwayland-treeland-output-manager-unstable-v2.h" #include #include #include struct wl_output; -struct treeland_output_color_control_v1; +struct treeland_output_picture_control_v2; namespace osd { -class TreelandColorControl : public QObject, public QtWayland::treeland_output_color_control_v1 +class TreelandColorControl : public QObject, public QtWayland::treeland_output_picture_control_v2 { Q_OBJECT public: - explicit TreelandColorControl(struct ::treeland_output_color_control_v1 *object, QObject *parent = nullptr); + explicit TreelandColorControl(struct ::treeland_output_picture_control_v2 *object, QObject *parent = nullptr); ~TreelandColorControl() override; double brightness() const; @@ -29,18 +29,18 @@ class TreelandColorControl : public QObject, public QtWayland::treeland_output_c void brightnessChanged(double brightness); protected: - void treeland_output_color_control_v1_brightness(wl_fixed_t brightness) override; + void treeland_output_picture_control_v2_brightness(wl_fixed_t brightness) override; private: double m_brightness = 0.0; }; // Read-only Treeland brightness provider for the OSD. It binds a single -// treeland_output_color_control_v1 to the primary wl_output and caches the +// treeland_output_picture_control_v2 to the primary wl_output and caches the // brightness reported by the compositor. It never commits brightness changes; // dde-shortcut-tool is responsible for adjusting brightness, and this provider // only reflects the resulting value. -class TreelandBrightness : public QWaylandClientExtensionTemplate, public QtWayland::treeland_output_manager_v1 +class TreelandBrightness : public QWaylandClientExtensionTemplate, public QtWayland::treeland_output_manager_v2 { Q_OBJECT diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index 8f6adb1c9..3ffcd2df2 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -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.6 REQUIRED) pkg_check_modules(WaylandClient REQUIRED IMPORTED_TARGET wayland-client) if (NOT DEFINED SYSTEMD_USER_UNIT_DIR) @@ -30,7 +30,7 @@ add_executable(dde-shell 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 ) target_compile_definitions(dde-shell diff --git a/shell/treelandoutputwatcher.cpp b/shell/treelandoutputwatcher.cpp index 39954129d..874f2e07f 100644 --- a/shell/treelandoutputwatcher.cpp +++ b/shell/treelandoutputwatcher.cpp @@ -3,7 +3,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "treelandoutputwatcher.h" -#include "wayland-treeland-output-manager-v1-client-protocol.h" +#include "wayland-treeland-output-manager-unstable-v2-client-protocol.h" #include #include @@ -11,7 +11,7 @@ #include TreelandOutputWatcher::TreelandOutputWatcher(QObject *parent) - : QWaylandClientExtensionTemplate(treeland_output_manager_v1_interface.version) + : QWaylandClientExtensionTemplate(treeland_output_manager_v2_interface.version) { setParent(parent); } @@ -21,13 +21,14 @@ TreelandOutputWatcher::~TreelandOutputWatcher() destroy(); } -void TreelandOutputWatcher::treeland_output_manager_v1_primary_output(const QString &output_name) +void TreelandOutputWatcher::treeland_output_manager_v2_primary_output(struct ::wl_output *output) { - if (qApp->primaryScreen()->name() == output_name) + if (!output) return; for (auto screen : qApp->screens()) { - if (screen->name() == output_name) { + auto *waylandScreen = screen->nativeInterface(); + if (waylandScreen && waylandScreen->output() == output) { QWindowSystemInterface::handlePrimaryScreenChanged(screen->handle()); return; } diff --git a/shell/treelandoutputwatcher.h b/shell/treelandoutputwatcher.h index e951de424..3e2b3c7ef 100644 --- a/shell/treelandoutputwatcher.h +++ b/shell/treelandoutputwatcher.h @@ -4,10 +4,12 @@ #pragma once -#include "qwayland-treeland-output-manager-v1.h" +#include "qwayland-treeland-output-manager-unstable-v2.h" #include -class TreelandOutputWatcher : public QWaylandClientExtensionTemplate, public QtWayland::treeland_output_manager_v1 +struct wl_output; + +class TreelandOutputWatcher : public QWaylandClientExtensionTemplate, public QtWayland::treeland_output_manager_v2 { Q_OBJECT public: @@ -15,5 +17,5 @@ class TreelandOutputWatcher : public QWaylandClientExtensionTemplate