Skip to content

Commit

Permalink
fix: missing window decoration for treeland
Browse files Browse the repository at this point in the history
It's exist when using DPlatformHandle by stack variable.
We save window decoration state in DTreeLandPlatformWindowHelper, and refresh them when surface created.

pms: BUG-278281
  • Loading branch information
18202781743 committed Jan 14, 2025
1 parent b566c12 commit 976aa91
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 63 deletions.
112 changes: 58 additions & 54 deletions src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,15 @@ void DTreeLandPlatformWindowHelper::onActiveChanged()

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

void DTreeLandPlatformWindowHelper::onSurfaceDestroyed()
Expand Down Expand Up @@ -258,33 +266,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 +339,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 +356,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 +375,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:
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 976aa91

Please sign in to comment.