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: use treeland wallpper color as dock themeType #812

Merged
merged 1 commit into from
Oct 21, 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
9 changes: 8 additions & 1 deletion panels/dock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
configure_file(environments.h.in environments.h @ONLY)

find_package(PkgConfig REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} COMPONENTS Core DBus Gui Qml WaylandCompositor Widgets)
find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} COMPONENTS Core DBus Gui Qml WaylandCompositor Widgets WaylandClient)
find_package(DdeTrayLoader REQUIRED)
find_package(TreeLandProtocols REQUIRED)
pkg_check_modules(WaylandClient REQUIRED IMPORTED_TARGET wayland-client)

file(
Expand Down Expand Up @@ -60,8 +61,14 @@ add_library(dockpanel SHARED
${dock_panel_sources}
)

qt_generate_wayland_protocol_client_sources(dockpanel
FILES
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-wallpaper-color-v1.xml
)

target_link_libraries(dockpanel PRIVATE
PkgConfig::WaylandClient
Qt${QT_VERSION_MAJOR}::WaylandClient
dde-shell-frame
)

Expand Down
56 changes: 55 additions & 1 deletion panels/dock/waylanddockhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,33 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "waylanddockhelper.h"
#include "constants.h"
#include "dockpanel.h"

namespace dock {
WaylandDockHelper::WaylandDockHelper(DockPanel* panel)
WaylandDockHelper::WaylandDockHelper(DockPanel *panel)
: DockHelper(panel)
, m_panel(panel)
{
m_wallpaperColorManager.reset(new WallpaperColorManager(this));

connect(m_panel, &DockPanel::rootObjectChanged, this, [this]() {
m_wallpaperColorManager->watchScreen(dockScreenName());
});

connect(m_panel, &DockPanel::dockScreenChanged, this, [this]() {
m_wallpaperColorManager->watchScreen(dockScreenName());
});

connect(m_wallpaperColorManager.get(), &WallpaperColorManager::activeChanged, this, [this]() {
if (m_panel->rootObject() != nullptr) {
m_wallpaperColorManager->watchScreen(dockScreenName());
}
});

if (m_panel->rootObject() != nullptr) {
m_wallpaperColorManager->watchScreen(dockScreenName());
}
}

void WaylandDockHelper::updateDockTriggerArea()
Expand All @@ -20,4 +41,37 @@ HideState WaylandDockHelper::hideState()
{
return Show;
}

QString WaylandDockHelper::dockScreenName()
{
if (m_panel->dockScreen())
return m_panel->dockScreen()->name();

return {};
}

void WaylandDockHelper::setDockColorTheme(const ColorTheme &theme)
{
m_panel->setColorTheme(theme);
}

WallpaperColorManager::WallpaperColorManager(WaylandDockHelper *helper)
: QWaylandClientExtensionTemplate<WallpaperColorManager>(treeland_wallpaper_color_manager_v1_interface.version)
, m_helper(helper)
{
}

void WallpaperColorManager::treeland_wallpaper_color_manager_v1_output_color(const QString &output, uint32_t isDark)
{
if (output == m_helper->dockScreenName()) {
m_helper->setDockColorTheme(isDark ? Dark : Light);
}
}

void WallpaperColorManager::watchScreen(const QString &screeName)
{
if (isActive() && !screeName.isEmpty()) {
watch(screeName);
}
}
}
29 changes: 27 additions & 2 deletions panels/dock/waylanddockhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "dockhelper.h"
#include "dsglobal.h"
#include "dockpanel.h"

#include "qwayland-treeland-wallpaper-color-v1.h"
#include <QtWaylandClient/QWaylandClientExtension>

namespace dock {
class WallpaperColorManager;
class WaylandDockHelper : public DockHelper
{
Q_OBJECT
Expand All @@ -15,8 +18,30 @@ class WaylandDockHelper : public DockHelper
WaylandDockHelper(DockPanel* panel);
HideState hideState() override;

void setDockColorTheme(const ColorTheme &theme);
QString dockScreenName();

public Q_SLOTS:
void updateDockTriggerArea() override;

private:
DockPanel *m_panel;
QScopedPointer<WallpaperColorManager> m_wallpaperColorManager;
};
}

class WallpaperColorManager : public QWaylandClientExtensionTemplate<WallpaperColorManager>, public QtWayland::treeland_wallpaper_color_manager_v1
{
Q_OBJECT
public:
explicit WallpaperColorManager(WaylandDockHelper *helper);

void watchScreen(const QString &screeName);
void treeland_wallpaper_color_manager_v1_output_color(const QString &output, uint32_t isDark) override;

Q_SIGNALS:
void wallpaperColorChanged(uint32_t isDark);

private:
WaylandDockHelper *m_helper;
};
}
Loading