From ef60cd521f7a21aa712d3abdf5502b97c4952e17 Mon Sep 17 00:00:00 2001 From: Tsic Liu Date: Thu, 31 Oct 2024 18:01:37 +0800 Subject: [PATCH] feat: use treeland output manager to update primaryScreen info Since Wayland has no concept of primaryScreen. We create a TreelandOutputWatcher to update the client's primaryScreen information log: as title --- shell/CMakeLists.txt | 15 +++++++++++++- shell/shell.cpp | 14 ++++++++++--- shell/treelandoutputwatcher.cpp | 35 +++++++++++++++++++++++++++++++++ shell/treelandoutputwatcher.h | 19 ++++++++++++++++++ 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 shell/treelandoutputwatcher.cpp create mode 100644 shell/treelandoutputwatcher.h diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index 0151edd28..7b7084118 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -2,7 +2,10 @@ # # SPDX-License-Identifier: CC0-1.0 -find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Widgets) +find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Widgets Gui WaylandClient) +find_package(TreelandProtocols REQUIRED) +pkg_check_modules(WaylandClient REQUIRED IMPORTED_TARGET wayland-client) + if (NOT DEFINED SYSTEMD_USER_UNIT_DIR) find_package(PkgConfig REQUIRED) pkg_check_modules(Systemd REQUIRED systemd) @@ -15,10 +18,17 @@ add_executable(dde-shell appletloader.cpp shell.h shell.cpp + treelandoutputwatcher.h + treelandoutputwatcher.cpp dde-shell.qrc override_dtkdeclarative_qml.qrc ) +qt_generate_wayland_protocol_client_sources(dde-shell + FILES + ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-output-manager-v1.xml +) + target_compile_definitions(dde-shell PRIVATE DS_VERSION=${CMAKE_PROJECT_VERSION} @@ -27,9 +37,12 @@ PRIVATE target_link_libraries(dde-shell PRIVATE dde-shell-frame Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::GuiPrivate Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::WaylandClient Dtk${DTK_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::DBus + PkgConfig::WaylandClient ) configure_file(${CMAKE_SOURCE_DIR}/misc/dde-shell-plugin@.service.in diff --git a/shell/shell.cpp b/shell/shell.cpp index 08de0b9f9..9bb09d1fe 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -3,14 +3,16 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "shell.h" +#include "treelandoutputwatcher.h" -#include #include +#include +#include +#include #include #include +#include #include -#include -#include DS_BEGIN_NAMESPACE @@ -39,7 +41,13 @@ class DtkInterceptor : public QObject, public QQmlAbstractUrlInterceptor Shell::Shell(QObject *parent) : QObject(parent) { + // Since Wayland has no concept of primaryScreen, it is necessary to rely on wayland private protocols + // to update the client's primaryScreen information + auto platformName = QGuiApplication::platformName(); + if (QStringLiteral("wayland") == platformName) { + new TreelandOutputWatcher(this); + } } void Shell::installDtkInterceptor() diff --git a/shell/treelandoutputwatcher.cpp b/shell/treelandoutputwatcher.cpp new file mode 100644 index 000000000..39954129d --- /dev/null +++ b/shell/treelandoutputwatcher.cpp @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "treelandoutputwatcher.h" +#include "wayland-treeland-output-manager-v1-client-protocol.h" + +#include +#include + +#include + +TreelandOutputWatcher::TreelandOutputWatcher(QObject *parent) + : QWaylandClientExtensionTemplate(treeland_output_manager_v1_interface.version) +{ + setParent(parent); +} + +TreelandOutputWatcher::~TreelandOutputWatcher() +{ + destroy(); +} + +void TreelandOutputWatcher::treeland_output_manager_v1_primary_output(const QString &output_name) +{ + if (qApp->primaryScreen()->name() == output_name) + return; + + for (auto screen : qApp->screens()) { + if (screen->name() == output_name) { + QWindowSystemInterface::handlePrimaryScreenChanged(screen->handle()); + return; + } + } +} diff --git a/shell/treelandoutputwatcher.h b/shell/treelandoutputwatcher.h new file mode 100644 index 000000000..e951de424 --- /dev/null +++ b/shell/treelandoutputwatcher.h @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "qwayland-treeland-output-manager-v1.h" +#include + +class TreelandOutputWatcher : public QWaylandClientExtensionTemplate, public QtWayland::treeland_output_manager_v1 +{ + Q_OBJECT +public: + TreelandOutputWatcher(QObject *parent = nullptr); + ~TreelandOutputWatcher(); + +protected: + void treeland_output_manager_v1_primary_output(const QString &output_name) override; +};