Skip to content

Commit

Permalink
fix: stack overflow with property/setProperty
Browse files Browse the repository at this point in the history
commit 1272c42 引入base 的 property/setProperty 会走自己的
read/write 方法,这里直接在 read/write 方法中调用 property/setProperty
会导致递归调用最终栈溢出崩溃

解决办法: 加一个 nativesettings 代理,并且通过同名 property/setProperty
函数隐藏父类的实现
  • Loading branch information
kegechen committed Nov 9, 2023
1 parent 1272c42 commit 49210a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 12 additions & 1 deletion xcb/dnotitlebarwindowhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ DNoTitlebarWindowHelper::DNoTitlebarWindowHelper(QWindow *window, quint32 window
window->setFlags(window->flags() & ~Qt::FramelessWindowHint);

mapped[window] = this;
m_nativeSettingsValid = DPlatformIntegration::buildNativeSettings(this, windowID);
m_settingsProxy = new QObject(this);
m_nativeSettingsValid = DPlatformIntegration::buildNativeSettings(m_settingsProxy, windowID);
Q_ASSERT(m_nativeSettingsValid);

// 本地设置无效时不可更新窗口属性,否则会导致setProperty函数被循环调用
Expand Down Expand Up @@ -446,6 +447,16 @@ void DNoTitlebarWindowHelper::updateAutoInputMaskByClipPathFromProperty()
updateWindowShape();
}

bool DNoTitlebarWindowHelper::setProperty(const char *name, const QVariant &value)
{
return m_settingsProxy ? m_settingsProxy->setProperty(name, value) : false;
}

QVariant DNoTitlebarWindowHelper::property(const char *name) const
{
return m_settingsProxy ? m_settingsProxy->property(name) : QVariant();
}

bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
{
QWindow *w = this->window();
Expand Down
5 changes: 4 additions & 1 deletion xcb/dnotitlebarwindowhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ private slots:
Q_SLOT void updateWindowBlurPathsFromProperty();
Q_SLOT void updateAutoInputMaskByClipPathFromProperty();

protected:
bool setProperty(const char *name, const QVariant &value);
QVariant property(const char *name) const;
private:
bool windowEvent(QEvent *event);
bool isEnableSystemMove(quint32 winId);
Expand All @@ -113,7 +116,7 @@ private slots:
bool m_enableSystemMove = true;
bool m_enableBlurWindow = false;
bool m_autoInputMaskByClipPath = false;
DNativeSettings *m_settings;
QObject *m_settingsProxy = nullptr;

static QHash<const QWindow*, DNoTitlebarWindowHelper*> mapped;

Expand Down

0 comments on commit 49210a2

Please sign in to comment.