Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions src/output/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
#include <wxdgpopupsurfaceitem.h>

#include <qwlayershellv1.h>
#include <qwoutputlayout.h>

Check warning on line 30 in src/output/output.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <qwoutputlayout.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QQmlEngine>

Check warning on line 32 in src/output/output.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QQmlEngine> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPointer>

Check warning on line 33 in src/output/output.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPointer> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <algorithm>

Check warning on line 35 in src/output/output.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <algorithm> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <optional>

Check warning on line 36 in src/output/output.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <optional> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#define SAME_APP_OFFSET_FACTOR 1.0
#define DIFF_APP_OFFSET_FACTOR 2.0
Expand Down Expand Up @@ -454,6 +455,28 @@
// Reposition should ignore positionAutomatic
arrangePopupSurface(surface);
});

auto parentLayerSurface = surface->parentSurface();
if (parentLayerSurface
&& parentLayerSurface->type() == SurfaceWrapper::Type::Layer) {
QPointer<SurfaceWrapper> surfacePtr(surface);
auto conn1 = connect(parentLayerSurface, &SurfaceWrapper::normalGeometryChanged,
this, [surfacePtr, this] {
if (!surfacePtr) return;
QMetaObject::invokeMethod(this, [surfacePtr, this] {
if (!surfacePtr) return;
arrangePopupSurface(surfacePtr);
}, Qt::QueuedConnection);
});
auto conn2 = connect(parentLayerSurface, &SurfaceWrapper::hasInitializeContainerChanged,
this, [surfacePtr, this] {
if (!surfacePtr) return;
if (!surfacePtr->parentSurface()
|| !surfacePtr->parentSurface()->hasInitializeContainer()) return;
arrangePopupSurface(surfacePtr);
});
m_parentLayerConnections[surface] = {conn1, conn2};
}
} else if (surface->type() == SurfaceWrapper::Type::InputPopup) {
auto inputPopupSurfaceItem = qobject_cast<WInputPopupSurfaceItem *>(surface->surfaceItem());
connect(inputPopupSurfaceItem, &WInputPopupSurfaceItem::referenceRectChanged, this, [surface, this] {
Expand All @@ -469,6 +492,16 @@
clearPopupCache(surface);
m_initialWindowPositionRatio.remove(surface);
Q_ASSERT(hasSurface(surface));

if (surface->type() == SurfaceWrapper::Type::XdgPopup) {
auto it = m_parentLayerConnections.find(surface);
if (it != m_parentLayerConnections.end()) {
for (auto &conn : it.value())
QObject::disconnect(conn);
m_parentLayerConnections.erase(it);
}
}

SurfaceListModel::removeSurface(surface);
surface->disconnect(this);

Expand Down Expand Up @@ -846,7 +879,21 @@
return;
}

auto parentOutput = surface->parentSurface()->ownsOutput()->outputItem();
auto parentSurface = surface->parentSurface();
if (!parentSurface->hasInitializeContainer()) {
qCInfo(lcTlOutput) << " LayerShell parent not initialized, deferring popup positioning"
<< "surface=" << surface << "parent=" << parentSurface;
return;
}

QRectF parentGeo = parentSurface->normalGeometry();
if (parentGeo.isEmpty()) {
qCInfo(lcTlOutput) << " LayerShell parent geometry is empty, deferring popup positioning"
<< "surface=" << surface << "parentGeo=" << parentGeo;
return;
}

auto parentOutput = parentSurface->ownsOutput()->outputItem();
auto dPos = popupDPos(surface);
if (!dPos.has_value())
return;
Expand Down Expand Up @@ -917,13 +964,21 @@
{
SurfaceWrapper *parentSurfaceWrapper = surface->parentSurface();
if (!parentSurfaceWrapper) {
// When an input popup is still alive while its parent text-input client is being torn down,
// arrangePopupSurface() can run in a transient state where parentSurface is temporarily unavailable.
// When an input popup is still alive while its parent text-input client is being torn down,
// arrangePopupSurface() can run in a transient state where parentSurface is temporarily unavailable.
qCWarning(lcTlSurface) << "[popup] skip arrangePopupSurface: missing parent surface"
<< "surface=" << surface;
return;
}

if (parentSurfaceWrapper->type() == SurfaceWrapper::Type::Layer
&& !parentSurfaceWrapper->hasInitializeContainer()) {
qCInfo(lcTlSurface) << "[popup] skip arrangePopupSurface: LayerShell parent not initialized"
<< "surface=" << surface
<< "parentSurface=" << parentSurfaceWrapper;
return;
}

QRectF normalGeo = surface->normalGeometry();
if (normalGeo.isEmpty()) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/output/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public Q_SLOTS:

QMap<SurfaceWrapper*, QPair<QPointF, QRectF>> m_positionCache;
QHash<SurfaceWrapper*, QPointF> m_initialWindowPositionRatio;
QHash<SurfaceWrapper*, QVector<QMetaObject::Connection>> m_parentLayerConnections;

std::unique_ptr<Backlight> m_backlight = nullptr;
OutputConfig *m_config;
Expand Down
Loading