Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkgui
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkgui.

Source-pull-request: linuxdeepin/dtkgui#300
  • Loading branch information
deepin-ci-robot committed Jan 13, 2025
1 parent 12f516f commit ee404f9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 63 deletions.
109 changes: 55 additions & 54 deletions src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ void DTreeLandPlatformWindowHelper::onActiveChanged()

void DTreeLandPlatformWindowHelper::onSurfaceCreated()
{
Q_EMIT surfaceCreated();
if (m_isNoTitlebar) {
doSetEnabledNoTitlebar();
}
if (m_isWindowBlur) {
doSetEnabledBlurWindow();
}
}

void DTreeLandPlatformWindowHelper::onSurfaceDestroyed()
Expand Down Expand Up @@ -258,33 +263,56 @@ PersonalizationWindowContext *DTreeLandPlatformWindowHelper::windowContext() con
return m_windowContext;
}

void DTreeLandPlatformWindowHelper::setEnabledNoTitlebar(bool enable)
{
m_isNoTitlebar = enable;
doSetEnabledNoTitlebar();
}
void DTreeLandPlatformWindowHelper::setWindowRadius(int windowRadius)
{
m_radius = windowRadius;
doSetWindowRadius();
}
void DTreeLandPlatformWindowHelper::setEnableBlurWindow(bool enableBlurWindow)
{
m_isWindowBlur = enableBlurWindow;
doSetEnabledBlurWindow();
}

void DTreeLandPlatformWindowHelper::doSetEnabledNoTitlebar()
{
if (auto context = windowContext()) {
context->set_titlebar(m_isNoTitlebar ? PersonalizationWindowContext::enable_mode_disable : PersonalizationWindowContext::enable_mode_enable);
}
}

void DTreeLandPlatformWindowHelper::doSetWindowRadius()
{
if (auto context = windowContext()) {
context->set_round_corner_radius(m_radius);
}
}

void DTreeLandPlatformWindowHelper::doSetEnabledBlurWindow()
{
if (auto context = windowContext()) {
context->set_blend_mode(m_isWindowBlur ? PersonalizationWindowContext::blend_mode_blur : PersonalizationWindowContext::blend_mode_transparent);
}
}

DTreeLandPlatformWindowInterface::DTreeLandPlatformWindowInterface(QWindow *window, DPlatformHandle *platformHandle, QObject *parent)
: QObject(parent)
, DPlatformWindowInterface(window, platformHandle)
{
if (!MoveWindowHelper::mapped.value(window)) {
Q_UNUSED(new MoveWindowHelper(window))
}

if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
connect(helper, &DTreeLandPlatformWindowHelper::surfaceCreated, this, &DTreeLandPlatformWindowInterface::onSurfaceCreated);
}
}

DTreeLandPlatformWindowInterface::~DTreeLandPlatformWindowInterface()
{
}

void DTreeLandPlatformWindowInterface::onSurfaceCreated()
{
if (m_isNoTitlebar) {
doSetEnabledNoTitlebar();
}
if (m_isWindowBlur) {
doSetEnabledBlurWindow();
}
}

void DTreeLandPlatformWindowInterface::setEnabled(bool enabled)
{
if (setEnabledNoTitlebar(enabled)) {
Expand All @@ -308,7 +336,9 @@ bool DTreeLandPlatformWindowInterface::setEnabledNoTitlebar(bool enable)
return true;
}
m_isNoTitlebar = enable;
doSetEnabledNoTitlebar();
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
helper->setEnabledNoTitlebar(enable);
}
return true;
}

Expand All @@ -323,7 +353,12 @@ void DTreeLandPlatformWindowInterface::setWindowRadius(int windowRadius)
return;
}
m_radius = windowRadius;
doSetWindowRadius();
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
helper->setWindowRadius(m_radius);
}
if (m_platformHandle) {
Q_EMIT m_platformHandle->windowRadiusChanged();
}
}

bool DTreeLandPlatformWindowInterface::enableBlurWindow() const
Expand All @@ -337,45 +372,11 @@ void DTreeLandPlatformWindowInterface::setEnableBlurWindow(bool enable)
return;
}
m_isWindowBlur = enable;
doSetEnabledBlurWindow();
}

void DTreeLandPlatformWindowInterface::doSetEnabledNoTitlebar()
{
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
auto context = helper->windowContext();
if (!context) {
return;
}
context->set_titlebar(m_isNoTitlebar ? PersonalizationWindowContext::enable_mode_disable : PersonalizationWindowContext::enable_mode_enable);
}
}

void DTreeLandPlatformWindowInterface::doSetWindowRadius()
{
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
auto context = helper->windowContext();
if (!context) {
return;
}
context->set_round_corner_radius(m_radius);
if (m_platformHandle) {
Q_EMIT m_platformHandle->windowRadiusChanged();
}
helper->setEnableBlurWindow(enable);
}
}

void DTreeLandPlatformWindowInterface::doSetEnabledBlurWindow()
{
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
auto context = helper->windowContext();
if (!context) {
return;
}
context->set_blend_mode(m_isWindowBlur ? PersonalizationWindowContext::blend_mode_blur : PersonalizationWindowContext::blend_mode_transparent);
if (m_platformHandle) {
Q_EMIT m_platformHandle->enableBlurWindowChanged();
}
if (m_platformHandle) {
Q_EMIT m_platformHandle->enableBlurWindowChanged();
}
}
DGUI_END_NAMESPACE
21 changes: 12 additions & 9 deletions src/plugins/platform/treeland/dtreelandplatformwindowinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class DTreeLandPlatformWindowHelper : public QObject {
QWindow *window() const { return qobject_cast<QWindow *>(parent()); }
PersonalizationWindowContext *windowContext() const;

Q_SIGNALS:
void surfaceCreated();
void setEnabledNoTitlebar(bool enable);
void setWindowRadius(int windowRadius);
void setEnableBlurWindow(bool enableBlurWindow);

private slots:

Check warning on line 29 in src/plugins/platform/treeland/dtreelandplatformwindowinterface.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
void onActiveChanged();
void onSurfaceCreated();
Expand All @@ -32,9 +34,17 @@ private slots:
explicit DTreeLandPlatformWindowHelper(QWindow *window);
bool eventFilter(QObject *watched, QEvent *event) override;
void initWaylandWindow();

void doSetEnabledNoTitlebar();
void doSetWindowRadius();
void doSetEnabledBlurWindow();
private:
PersonalizationWindowContext *m_windowContext = nullptr;
static QMap<QWindow *, DTreeLandPlatformWindowHelper*> windowMap;

bool m_isNoTitlebar = false;
bool m_isWindowBlur = false;
int m_radius = 0;
};

class DTreeLandPlatformWindowInterface : public QObject, public DPlatformWindowInterface
Expand All @@ -56,14 +66,7 @@ class DTreeLandPlatformWindowInterface : public QObject, public DPlatformWindowI
bool enableBlurWindow() const override;
void setEnableBlurWindow(bool enableBlurWindow) override;

public slots:
void onSurfaceCreated();

private:
void doSetEnabledNoTitlebar();
void doSetWindowRadius();
void doSetEnabledBlurWindow();

bool m_isNoTitlebar = false;
bool m_isWindowBlur = false;
int m_radius = 0;
Expand Down

0 comments on commit ee404f9

Please sign in to comment.