mirror of
https://github.com/hyprwm/Hyprland.git
synced 2024-09-11 13:25:42 +03:00
fix crashes
This commit is contained in:
parent
4a5f39ceb6
commit
dc23ed8a4e
@ -556,6 +556,8 @@ void Events::listener_unmapWindow(void* owner, void* data) {
|
|||||||
|
|
||||||
g_pEventManager->postEvent(SHyprIPCEvent{"closewindow", getFormat("%x", PWINDOW)});
|
g_pEventManager->postEvent(SHyprIPCEvent{"closewindow", getFormat("%x", PWINDOW)});
|
||||||
|
|
||||||
|
g_pProtocolManager->m_pToplevelExportProtocolManager->onWindowUnmap(PWINDOW);
|
||||||
|
|
||||||
if (!PWINDOW->m_bIsX11) {
|
if (!PWINDOW->m_bIsX11) {
|
||||||
Debug::log(LOG, "Unregistered late callbacks XDG");
|
Debug::log(LOG, "Unregistered late callbacks XDG");
|
||||||
PWINDOW->hyprListener_commitWindow.removeCallback();
|
PWINDOW->hyprListener_commitWindow.removeCallback();
|
||||||
|
@ -77,14 +77,16 @@ SToplevelFrame* frameFromResource(wl_resource* resource) {
|
|||||||
return (SToplevelFrame*)wl_resource_get_user_data(resource);
|
return (SToplevelFrame*)wl_resource_get_user_data(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CToplevelExportProtocolManager::removeClient(SToplevelClient* client) {
|
void CToplevelExportProtocolManager::removeClient(SToplevelClient* client, bool force) {
|
||||||
if (!client || client->ref <= 0)
|
if (!force) {
|
||||||
return;
|
if (!client || client->ref <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (--client->ref != 0)
|
if (--client->ref != 0)
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_lClients.remove(*client);
|
m_lClients.remove(*client); // TODO: this doesn't get cleaned up after sharing app exits???
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleManagerResourceDestroy(wl_resource* resource) {
|
void handleManagerResourceDestroy(wl_resource* resource) {
|
||||||
@ -119,13 +121,15 @@ void handleFrameResourceDestroy(wl_resource* resource) {
|
|||||||
g_pProtocolManager->m_pToplevelExportProtocolManager->removeFrame(PFRAME);
|
g_pProtocolManager->m_pToplevelExportProtocolManager->removeFrame(PFRAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CToplevelExportProtocolManager::removeFrame(SToplevelFrame* frame) {
|
void CToplevelExportProtocolManager::removeFrame(SToplevelFrame* frame, bool force) {
|
||||||
if (!frame)
|
if (!frame)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
std::erase_if(m_vFramesAwaitingWrite, [&] (const auto& other) { return other == frame; });
|
||||||
|
|
||||||
wl_resource_set_user_data(frame->resource, nullptr);
|
wl_resource_set_user_data(frame->resource, nullptr);
|
||||||
wlr_buffer_unlock(frame->buffer);
|
wlr_buffer_unlock(frame->buffer);
|
||||||
removeClient(frame->client);
|
removeClient(frame->client, force);
|
||||||
m_lFrames.remove(*frame);
|
m_lFrames.remove(*frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,24 +138,26 @@ void CToplevelExportProtocolManager::captureToplevel(wl_client* client, wl_resou
|
|||||||
|
|
||||||
const auto PWINDOW = g_pCompositor->getWindowFromHandle(handle);
|
const auto PWINDOW = g_pCompositor->getWindowFromHandle(handle);
|
||||||
|
|
||||||
if (!PWINDOW) {
|
|
||||||
Debug::log(ERR, "Client requested sharing of window handle %x which does not exist!", handle);
|
|
||||||
hyprland_toplevel_export_frame_v1_send_failed(resource);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PWINDOW->m_bIsMapped || PWINDOW->isHidden()) {
|
|
||||||
Debug::log(ERR, "Client requested sharing of window handle %x which is not shareable!", handle);
|
|
||||||
hyprland_toplevel_export_frame_v1_send_failed(resource);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create a frame
|
// create a frame
|
||||||
const auto PFRAME = &m_lFrames.emplace_back();
|
const auto PFRAME = &m_lFrames.emplace_back();
|
||||||
PFRAME->overlayCursor = !!overlay_cursor;
|
PFRAME->overlayCursor = !!overlay_cursor;
|
||||||
PFRAME->resource = wl_resource_create(client, &hyprland_toplevel_export_frame_v1_interface, wl_resource_get_version(resource), frame);
|
PFRAME->resource = wl_resource_create(client, &hyprland_toplevel_export_frame_v1_interface, wl_resource_get_version(resource), frame);
|
||||||
PFRAME->pWindow = PWINDOW;
|
PFRAME->pWindow = PWINDOW;
|
||||||
|
|
||||||
|
if (!PWINDOW) {
|
||||||
|
Debug::log(ERR, "Client requested sharing of window handle %x which does not exist!", handle);
|
||||||
|
hyprland_toplevel_export_frame_v1_send_failed(PFRAME->resource);
|
||||||
|
removeFrame(PFRAME);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!PWINDOW->m_bIsMapped || PWINDOW->isHidden()) {
|
||||||
|
Debug::log(ERR, "Client requested sharing of window handle %x which is not shareable!", handle);
|
||||||
|
hyprland_toplevel_export_frame_v1_send_failed(PFRAME->resource);
|
||||||
|
removeFrame(PFRAME);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!PFRAME->resource) {
|
if (!PFRAME->resource) {
|
||||||
Debug::log(ERR, "Couldn't alloc frame for sharing! (no memory)");
|
Debug::log(ERR, "Couldn't alloc frame for sharing! (no memory)");
|
||||||
m_lFrames.remove(*PFRAME);
|
m_lFrames.remove(*PFRAME);
|
||||||
@ -264,9 +270,15 @@ void CToplevelExportProtocolManager::onMonitorRender(CMonitor* pMonitor) {
|
|||||||
if (m_vFramesAwaitingWrite.empty())
|
if (m_vFramesAwaitingWrite.empty())
|
||||||
return; // nothing to share
|
return; // nothing to share
|
||||||
|
|
||||||
|
std::vector<SToplevelFrame*> framesToRemove;
|
||||||
|
|
||||||
// share frame if correct output
|
// share frame if correct output
|
||||||
for (auto& f : m_vFramesAwaitingWrite) {
|
for (auto& f : m_vFramesAwaitingWrite) {
|
||||||
|
if (!f->pWindow) {
|
||||||
|
framesToRemove.push_back(f);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
wlr_box geometry = { f->pWindow->m_vRealPosition.vec().x, f->pWindow->m_vRealPosition.vec().y,
|
wlr_box geometry = { f->pWindow->m_vRealPosition.vec().x, f->pWindow->m_vRealPosition.vec().y,
|
||||||
f->pWindow->m_vRealSize.vec().x, f->pWindow->m_vRealSize.vec().y };
|
f->pWindow->m_vRealSize.vec().x, f->pWindow->m_vRealSize.vec().y };
|
||||||
|
|
||||||
@ -274,18 +286,22 @@ void CToplevelExportProtocolManager::onMonitorRender(CMonitor* pMonitor) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
shareFrame(f);
|
shareFrame(f);
|
||||||
|
|
||||||
|
framesToRemove.push_back(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& f : framesToRemove) {
|
||||||
|
removeFrame(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CToplevelExportProtocolManager::shareFrame(SToplevelFrame* frame) {
|
void CToplevelExportProtocolManager::shareFrame(SToplevelFrame* frame) {
|
||||||
if (!frame->buffer)
|
if (!frame->buffer) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: damage
|
// TODO: damage
|
||||||
|
|
||||||
// remove this frame from awaiting.
|
|
||||||
std::erase_if(m_vFramesAwaitingWrite, [&] (const SToplevelFrame* other) { return other == frame; });
|
|
||||||
|
|
||||||
timespec now;
|
timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
|
||||||
@ -293,13 +309,11 @@ void CToplevelExportProtocolManager::shareFrame(SToplevelFrame* frame) {
|
|||||||
if (frame->bufferCap == WLR_BUFFER_CAP_DMABUF) {
|
if (frame->bufferCap == WLR_BUFFER_CAP_DMABUF) {
|
||||||
if (!copyFrameDmabuf(frame)) {
|
if (!copyFrameDmabuf(frame)) {
|
||||||
hyprland_toplevel_export_frame_v1_send_failed(frame->resource);
|
hyprland_toplevel_export_frame_v1_send_failed(frame->resource);
|
||||||
removeFrame(frame);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!copyFrameShm(frame, &now)) {
|
if (!copyFrameShm(frame, &now)) {
|
||||||
hyprland_toplevel_export_frame_v1_send_failed(frame->resource);
|
hyprland_toplevel_export_frame_v1_send_failed(frame->resource);
|
||||||
removeFrame(frame);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,7 +323,6 @@ void CToplevelExportProtocolManager::shareFrame(SToplevelFrame* frame) {
|
|||||||
uint32_t tvSecHi = (sizeof(now.tv_sec) > 4) ? now.tv_sec >> 32 : 0;
|
uint32_t tvSecHi = (sizeof(now.tv_sec) > 4) ? now.tv_sec >> 32 : 0;
|
||||||
uint32_t tvSecLo = now.tv_sec & 0xFFFFFFFF;
|
uint32_t tvSecLo = now.tv_sec & 0xFFFFFFFF;
|
||||||
hyprland_toplevel_export_frame_v1_send_ready(frame->resource, tvSecHi, tvSecLo, now.tv_nsec);
|
hyprland_toplevel_export_frame_v1_send_ready(frame->resource, tvSecHi, tvSecLo, now.tv_nsec);
|
||||||
removeFrame(frame);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CToplevelExportProtocolManager::copyFrameShm(SToplevelFrame* frame, timespec* now) {
|
bool CToplevelExportProtocolManager::copyFrameShm(SToplevelFrame* frame, timespec* now) {
|
||||||
@ -359,4 +372,11 @@ bool CToplevelExportProtocolManager::copyFrameDmabuf(SToplevelFrame* frame) {
|
|||||||
// todo
|
// todo
|
||||||
Debug::log(ERR, "DMABUF copying not impl'd!");
|
Debug::log(ERR, "DMABUF copying not impl'd!");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CToplevelExportProtocolManager::onWindowUnmap(CWindow* pWindow) {
|
||||||
|
for (auto& f : m_lFrames) {
|
||||||
|
if (f.pWindow == pWindow)
|
||||||
|
f.pWindow = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
@ -46,12 +46,13 @@ public:
|
|||||||
|
|
||||||
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
|
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
|
||||||
void captureToplevel(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, uint32_t handle);
|
void captureToplevel(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, uint32_t handle);
|
||||||
void removeClient(SToplevelClient* client);
|
void removeClient(SToplevelClient* client, bool force = false);
|
||||||
void removeFrame(SToplevelFrame* frame);
|
void removeFrame(SToplevelFrame* frame, bool force = false);
|
||||||
void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer, int32_t ignore_damage);
|
void copyFrame(wl_client* client, wl_resource* resource, wl_resource* buffer, int32_t ignore_damage);
|
||||||
|
|
||||||
void onMonitorRender(CMonitor* pMonitor);
|
void onMonitorRender(CMonitor* pMonitor);
|
||||||
void displayDestroy();
|
void displayDestroy();
|
||||||
|
void onWindowUnmap(CWindow* pWindow);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wl_global* m_pGlobal = nullptr;
|
wl_global* m_pGlobal = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user