wayland/layershell: ensure bridge is nulled on layer destruction

Fixes rare race condition crashes.
This commit is contained in:
outfoxxed 2025-05-25 16:11:57 -07:00
parent 2bcd9e07fd
commit bf235d3d4d
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
3 changed files with 34 additions and 3 deletions

View file

@ -34,7 +34,8 @@ ProxiedWindow* WlrLayershell::retrieveWindow(QObject* oldInstance) {
auto* window = old == nullptr ? nullptr : old->disownWindow();
if (window != nullptr) {
this->bridge = LayerSurfaceBridge::init(window, this->computeState());
this->connectBridge(LayerSurfaceBridge::init(window, this->computeState()));
if (this->bridge) {
return window;
} else {
@ -48,7 +49,7 @@ ProxiedWindow* WlrLayershell::retrieveWindow(QObject* oldInstance) {
ProxiedWindow* WlrLayershell::createQQuickWindow() {
auto* window = this->ProxyWindowBase::createQQuickWindow();
this->bridge = LayerSurfaceBridge::init(window, this->computeState());
this->connectBridge(LayerSurfaceBridge::init(window, this->computeState()));
if (!this->bridge) {
qWarning() << "Could not attach Layershell extension to new QQuickWindow. Layer will not "
"behave correctly.";
@ -72,6 +73,30 @@ void WlrLayershell::connectWindow() {
this->updateAutoExclusion();
}
ProxiedWindow* WlrLayershell::disownWindow(bool keepItemOwnership) {
auto* window = this->ProxyWindowBase::disownWindow(keepItemOwnership);
if (this->bridge) {
this->connectBridge(nullptr);
}
return window;
}
void WlrLayershell::connectBridge(LayerSurfaceBridge* bridge) {
if (this->bridge) {
QObject::disconnect(this->bridge, nullptr, this, nullptr);
}
this->bridge = bridge;
if (bridge) {
QObject::connect(this->bridge, &QObject::destroyed, this, &WlrLayershell::onBridgeDestroyed);
}
}
void WlrLayershell::onBridgeDestroyed() { this->bridge = nullptr; }
bool WlrLayershell::deleteOnInvisible() const {
// Qt windows behave weirdly when geometry is modified and setVisible(false)
// is subsequently called in the same frame.