Skip to content
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

feat: treeland window background for fullscreen frame #377

Merged
merged 1 commit into from
Aug 2, 2024
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ add_subdirectory(src/gioutils)
add_subdirectory(src/utils)
add_subdirectory(src/quick)
add_subdirectory(src/ddeintegration)
add_subdirectory(src/treelandintegration)
add_subdirectory(src/models)
add_subdirectory(qml/windowed)

Expand Down Expand Up @@ -158,6 +159,7 @@ target_link_libraries(${BIN_NAME} PRIVATE
launcher-qml-utils
launcher-models
dde-integration-dbus
treeland-integration
)

install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down
2 changes: 2 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Build-Depends:
qt6-declarative-dev,
qt6-tools-dev,
qt6-tools-dev-tools,
qt6-wayland-dev,
qt6-wayland-private-dev,
libdtkcommon-dev,
libdtk6core-dev,
# v-- provides qdbusxml2cpp-fix binary
Expand Down
5 changes: 5 additions & 0 deletions desktopintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ QString DesktopIntegration::currentDE()
return qEnvironmentVariable("XDG_CURRENT_DESKTOP", QStringLiteral("DDE")).split(':').constFirst();
}

bool DesktopIntegration::isTreeLand()
{
return qEnvironmentVariable("DDE_CURRENT_COMPOSITOR") == QStringLiteral("TreeLand");
}

void DesktopIntegration::openShutdownScreen()
{
DDBusSender()
Expand Down
1 change: 1 addition & 0 deletions desktopintegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DesktopIntegration : public QObject
}

Q_INVOKABLE static QString currentDE();
Q_INVOKABLE static bool isTreeLand();
Q_INVOKABLE static void openShutdownScreen();
Q_INVOKABLE static void openSystemSettings();
Q_INVOKABLE static void launchByDesktopId(const QString & desktopId);
Expand Down
8 changes: 8 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

#include "categorizedsortproxymodel.h"
#include "launchercontroller.h"
#include "personalizationmanager.h"

#include <QDBusConnection>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickStyle>
#include <QCommandLineParser>
#include <QWindow>
#include <DGuiApplicationHelper>
#include <DStandardPaths>
#include <DPathBuf>
Expand Down Expand Up @@ -75,6 +77,12 @@ int main(int argc, char* argv[])
engine.loadFromModule("org.deepin.launchpad", "Main");
if (engine.rootObjects().isEmpty())
return -1;
QWindow * windowdFrameWindow = engine.rootObjects().at(0)->findChild<QWindow *>("WindowedFrameApplicationWindow");
Q_CHECK_PTR(windowdFrameWindow);
PersonalizationManager personalizationmgr;
if (windowdFrameWindow) {
personalizationmgr.personalizeWindow(windowdFrameWindow, PersonalizationManager::BgBlurredWallpaper);
}

return app.exec();
}
2 changes: 1 addition & 1 deletion qml/FullscreenFrame.qml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ InputEventItem {
}

background: Image {
source: DesktopIntegration.backgroundUrl
source: DesktopIntegration.isTreeLand() ? undefined : DesktopIntegration.backgroundUrl

Rectangle {
anchors.fill: parent
Expand Down
1 change: 1 addition & 0 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ QtObject {
objectName: "FullscreenFrameApplicationWindow"
title: "Fullscreen Launchpad"
visible: LauncherController.visible && (LauncherController.currentFrame !== "WindowedFrame")
color: "transparent"

DLayerShellWindow.anchors: DLayerShellWindow.AnchorBottom | DLayerShellWindow.AnchorTop | DLayerShellWindow.AnchorLeft | DLayerShellWindow.AnchorRight
DLayerShellWindow.layer: DLayerShellWindow.LayerTop
Expand Down
4 changes: 3 additions & 1 deletion src/models/sortproxymodel.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
This file is part of KDToolBox.
This file was part of KDToolBox, modified by deepin to fit their own needs.

SPDX-FileCopyrightText: 2018 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
Author: André Somers <[email protected]>
SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
Author: Wang Zichong <[email protected]>

SPDX-License-Identifier: MIT
*/
Expand Down
30 changes: 30 additions & 0 deletions src/treelandintegration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: CC0-1.0

find_package(Qt6 REQUIRED COMPONENTS WaylandClient)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_library(treeland-integration OBJECT
personalizationmanager.cpp
personalizationwindow.cpp
)

qt_generate_wayland_protocol_client_sources(treeland-integration
FILES
${CMAKE_CURRENT_SOURCE_DIR}/treeland-personalization-manager-v1.xml
)

target_sources(treeland-integration PUBLIC
FILE_SET HEADERS
FILES
personalizationmanager.h
personalizationwindow.h
)

target_link_libraries(treeland-integration
PRIVATE
Qt6::WaylandClient
Qt6::WaylandClientPrivate
)
93 changes: 93 additions & 0 deletions src/treelandintegration/personalizationmanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "personalizationmanager.h"
#include "personalizationwindow.h"

#include "qwayland-treeland-personalization-manager-v1.h"

#include <QGuiApplication>
#include <QWindow>

#include <private/qwaylandwindow_p.h>

class PersonalizationManagerPrivate : public QWaylandClientExtensionTemplate<PersonalizationManagerPrivate>,
public QtWayland::treeland_personalization_manager_v1
{
Q_OBJECT
public:
explicit PersonalizationManagerPrivate();
bool personalizeWindow(QWindow * window, PersonalizationManager::BgState state);

private:
bool doPersonalizeWindow(QWindow * window, PersonalizationManager::BgState state);
QList<std::pair<QWindow *, PersonalizationManager::BgState> > m_queue;
};


PersonalizationManagerPrivate::PersonalizationManagerPrivate()
: QWaylandClientExtensionTemplate<PersonalizationManagerPrivate>(1)
{
connect(this, &PersonalizationManagerPrivate::activeChanged, this, [this](){
if (!isActive()) return;
for (std::pair<QWindow *, PersonalizationManager::BgState> task_pair : std::as_const(m_queue)) {
doPersonalizeWindow(task_pair.first, task_pair.second);
}
m_queue.clear();
});
}

// return if the window is "personalized" right away.
bool PersonalizationManagerPrivate::personalizeWindow(QWindow * window, PersonalizationManager::BgState state)
{
if (!isActive()) {
m_queue.append(std::make_pair(window, state));
return false;
} else {
doPersonalizeWindow(window, state);
return true;
}
}

// return if success
bool PersonalizationManagerPrivate::doPersonalizeWindow(QWindow * window, PersonalizationManager::BgState state)
{
Q_ASSERT(isActive());
if (window && window->handle()) {
QtWaylandClient::QWaylandWindow *waylandWindow =
static_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
struct wl_surface *surface = waylandWindow->wlSurface();
if (surface) {
PersonalizationWindow *context =
new PersonalizationWindow(get_window_context(surface));
context->set_background_type(state);
qDebug() << "Applied background type" << state << "to window" << window;
return true;
}
}
return false;
}

// ----------------------------------------------------

PersonalizationManager::PersonalizationManager(QObject * parent)
: QObject(parent)
{
if (QGuiApplication::platformName() == "wayland") {
m_dptr = new PersonalizationManagerPrivate;
}
}

PersonalizationManager::~PersonalizationManager()
{
if (m_dptr) delete m_dptr;
}

// return if the window is "personalized" right away.
bool PersonalizationManager::personalizeWindow(QWindow * window, PersonalizationManager::BgState state)
{
return m_dptr ? m_dptr->personalizeWindow(window, state) : true;
}

#include "personalizationmanager.moc"
27 changes: 27 additions & 0 deletions src/treelandintegration/personalizationmanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QtWaylandClient/QWaylandClientExtension>

class QWindow;
class PersonalizationManagerPrivate;
class PersonalizationManager : public QObject
{
Q_OBJECT
public:
enum BgState {
BgNormal = 0,
BgWallpaper = 1,
BgBlurredWallpaper = 2,
};

explicit PersonalizationManager(QObject * parent = nullptr);
~PersonalizationManager();
bool personalizeWindow(QWindow * window, BgState state);

private:
PersonalizationManagerPrivate * m_dptr = nullptr;
};
11 changes: 11 additions & 0 deletions src/treelandintegration/personalizationwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "personalizationwindow.h"

PersonalizationWindow::PersonalizationWindow(struct ::personalization_window_context_v1 *object)
: QWaylandClientExtensionTemplate<PersonalizationWindow>(1)
, QtWayland::personalization_window_context_v1(object)
{
}
17 changes: 17 additions & 0 deletions src/treelandintegration/personalizationwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include "qwayland-treeland-personalization-manager-v1.h"

#include <QtWaylandClient/QWaylandClientExtension>

class PersonalizationWindow : public QWaylandClientExtensionTemplate<PersonalizationWindow>,
public QtWayland::personalization_window_context_v1
{
Q_OBJECT
public:
explicit PersonalizationWindow(struct ::personalization_window_context_v1 *object);
};
Loading
Loading