fix(wayland): layershell windows are recreated if attach fails

Usually this happens if the namespace changes
This commit is contained in:
outfoxxed 2024-02-25 16:13:24 -08:00
parent c2930783ea
commit 13c5d7c7a9
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
5 changed files with 41 additions and 13 deletions

View file

@ -5,6 +5,7 @@
#include <qobject.h>
#include <qqmllist.h>
#include <qquickitem.h>
#include <qquickwindow.h>
#include <qtmetamacros.h>
#include <qtypes.h>
@ -17,6 +18,31 @@ WaylandLayershell::WaylandLayershell(QObject* parent)
: ProxyWindowBase(parent)
, ext(new LayershellWindowExtension(this)) {}
QQuickWindow* WaylandLayershell::createWindow(QObject* oldInstance) {
auto* old = qobject_cast<WaylandLayershell*>(oldInstance);
QQuickWindow* window = nullptr;
if (old == nullptr || old->window == nullptr) {
window = new QQuickWindow();
} else {
window = old->disownWindow();
if (this->ext->attach(window)) {
return window;
} else {
window->deleteLater();
window = new QQuickWindow();
}
}
if (!this->ext->attach(window)) {
qWarning() << "Could not attach Layershell extension to new QQUickWindow. Layer will not "
"behave correctly.";
}
return window;
}
void WaylandLayershell::setupWindow() {
this->ProxyWindowBase::setupWindow();
@ -32,10 +58,6 @@ void WaylandLayershell::setupWindow() {
QObject::connect(this, &WaylandLayershell::anchorsChanged, this, &WaylandLayershell::updateAutoExclusion);
QObject::connect(this, &WaylandLayershell::marginsChanged, this, &WaylandLayershell::updateAutoExclusion);
// clang-format on
if (!this->ext->attach(this->window)) {
// todo: discard window
}
}
void WaylandLayershell::setWidth(qint32 width) {