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: outfoxxed
GPG key ID: 4C88A185FB89301E
5 changed files with 41 additions and 13 deletions

View file

@ -13,7 +13,6 @@ pkg_check_modules(wayland REQUIRED IMPORTED_TARGET wayland-client wayland-protoc
find_package(Qt6 REQUIRED COMPONENTS WaylandClient)
target_link_libraries(quickshell-wayland PRIVATE ${QT_DEPS} wayland-client)
message(STATUS Qt6::WaylandClient)
# wayland protocols

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) {

View file

@ -2,6 +2,8 @@
#include <qobject.h>
#include <qqmlintegration.h>
#include <qquickitem.h>
#include <qquickwindow.h>
#include <qtmetamacros.h>
#include <qtypes.h>
@ -30,6 +32,7 @@ class WaylandLayershell: public ProxyWindowBase {
public:
explicit WaylandLayershell(QObject* parent = nullptr);
QQuickWindow* createWindow(QObject* oldInstance) override;
void setupWindow() override;
void setWidth(qint32 width) override;