Skip to content

Commit

Permalink
feat: treeland window background for fullscreen frame
Browse files Browse the repository at this point in the history
通过 TreeLand 特性让合成器绘制全屏启动器的模糊背景。

Log:
  • Loading branch information
BLumia committed Aug 2, 2024
1 parent 3adb574 commit 09a8fe9
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 3 deletions.
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
6 changes: 6 additions & 0 deletions desktopintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <appmgr.h>

#include <AppStreamQt/pool.h>
#include <qstringliteral.h>

#include "appwiz.h"
#include "ddedock.h"
Expand All @@ -26,6 +27,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
9 changes: 9 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@

#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>
#include <launcherappiconprovider.h>
#include <launcherfoldericonprovider.h>
#include <blurhashimageprovider.h>
#include <DLog>
#include <qassert.h>

DCORE_USE_NAMESPACE
DGUI_USE_NAMESPACE
Expand Down Expand Up @@ -75,6 +78,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
3 changes: 2 additions & 1 deletion 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: "#00000000"

DLayerShellWindow.anchors: DLayerShellWindow.AnchorBottom | DLayerShellWindow.AnchorTop | DLayerShellWindow.AnchorLeft | DLayerShellWindow.AnchorRight
DLayerShellWindow.layer: DLayerShellWindow.LayerTop
Expand All @@ -295,7 +296,7 @@ QtObject {
// visibility: Window.FullScreen
flags: {
if (DebugHelper.useRegularWindow) return Qt.Window
return (Qt.FramelessWindowHint | Qt.Tool)
return (Qt.FramelessWindowHint | Qt.Tool | Qt.WA_TranslucentBackground)
}

DWindow.enabled: !DebugHelper.useRegularWindow
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
)
101 changes: 101 additions & 0 deletions src/treelandintegration/personalizationmanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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 <QWindow>

#include <private/qwaylandwindow_p.h>
#include <qguiapplication.h>
#include <qobject.h>
#include <qtmetamacros.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 (window && window->handle()) {
QtWaylandClient::QWaylandWindow *waylandWindow =
static_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
struct wl_surface *surface = waylandWindow->wlSurface();

Check warning on line 49 in src/treelandintegration/personalizationmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'surface' is assigned a value that is never used.
}

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

0 comments on commit 09a8fe9

Please sign in to comment.