Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}
Expand All @@ -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
Expand Down
14 changes: 11 additions & 3 deletions shell/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "shell.h"
#include "treelandoutputwatcher.h"

#include <memory>
#include <DConfig>
#include <QDBusConnection>
#include <QDBusError>
#include <QGuiApplication>
#include <QLoggingCategory>
#include <QQmlAbstractUrlInterceptor>
#include <memory>
#include <qmlengine.h>
#include <QDBusConnection>
#include <QDBusError>

DS_BEGIN_NAMESPACE

Expand Down Expand Up @@ -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()
Expand Down
35 changes: 35 additions & 0 deletions shell/treelandoutputwatcher.cpp
Original file line number Diff line number Diff line change
@@ -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 <QGuiApplication>
#include <QScreen>

#include <qpa/qwindowsysteminterface.h>

TreelandOutputWatcher::TreelandOutputWatcher(QObject *parent)
: QWaylandClientExtensionTemplate<TreelandOutputWatcher>(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;
}
}
}
19 changes: 19 additions & 0 deletions shell/treelandoutputwatcher.h
Original file line number Diff line number Diff line change
@@ -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 <QtWaylandClient/QWaylandClientExtension>

class TreelandOutputWatcher : public QWaylandClientExtensionTemplate<TreelandOutputWatcher>, 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;
};