Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/core/Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,9 @@ void CBackend::cleanup() {
if (m_cleaned.exchange(true))
return;

// apps drop their windows and outputs after enterLoop() returns, past the disconnect below
g_waylandPlatform->releaseProxies();

g_asyncResourceGatherer.reset();

m_waylandPostDispatch.reset();
Expand Down
22 changes: 22 additions & 0 deletions src/core/platforms/WaylandPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ CWaylandPlatform::~CWaylandPlatform() {
wl_display_disconnect(DPY);
}

void CWaylandPlatform::releaseProxies() {
// by value: a release can drop the last ref and the destructor erases from the list
const auto release = [](auto windows) {
for (const auto& w : windows) {
if (const auto window = w.lock())
window->releaseWayland();
}
};

release(m_windows);
release(m_layers);

if (const auto lock = m_sessionLockState.lock()) {
release(lock->m_lockSurfaces);
lock->m_lock.reset();
}

for (const auto& o : m_outputs) {
o->m_wlOutput.reset();
}
}

bool CWaylandPlatform::dispatchEvents() {
int ret = 0;
do {
Expand Down
1 change: 1 addition & 0 deletions src/core/platforms/WaylandPlatform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Hyprtoolkit {
void setCursor(ePointerShape shape);

bool dispatchEvents();
void releaseProxies();

void setClipboard(const std::string& text);
std::string readClipboard();
Expand Down
14 changes: 14 additions & 0 deletions src/window/IWaylandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ SP<IWindow> IWaylandWindow::openPopup(const SWindowCreationData& data) {
return x;
}

void IWaylandWindow::releaseWayland() {
// popup close() erases itself from m_popups
const auto popups = m_popups;
for (const auto& p : popups) {
if (const auto popup = reinterpretPointerCast<IWaylandWindow>(p.lock()))
popup->releaseWayland();
}

close();

// layers and lock surfaces keep their wl_surface across close() for a reopen
m_waylandState = {};
}

void IWaylandWindow::mouseButton(const Input::eMouseButton button, bool state) {
if (m_popups.empty() || !state || m_ignoreNextButtonEvent) {
m_ignoreNextButtonEvent = false;
Expand Down
1 change: 1 addition & 0 deletions src/window/IWaylandWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace Hyprtoolkit {
virtual void setIMTo(const Hyprutils::Math::CBox& box, const std::string& str, size_t cursor);
virtual void resetIM();
virtual void onPreRender();
void releaseWayland();

std::vector<WP<IWindow>> m_popups;

Expand Down
4 changes: 3 additions & 1 deletion src/window/WaylandPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ void CWaylandPopup::open() {
}

void CWaylandPopup::close() {
if (g_waylandPlatform->m_currentWindow == m_self)
// the app can drop a popup after the backend is gone
if (g_waylandPlatform && g_waylandPlatform->m_currentWindow == m_self)
g_waylandPlatform->m_currentWindow = m_parent;

if (m_parent)
Expand All @@ -138,6 +139,7 @@ void CWaylandPopup::close() {
m_waylandState.surface->sendDestroy();

m_waylandState = {};
m_wlPopupState = {};

m_events.popupClosed.emit();
}
Expand Down
Loading