From f0afc1ab21887cb27fda8bd417852e987e3f8b9b Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 28 Aug 2023 15:52:58 +0200 Subject: [PATCH] minor fixas --- src/portals/Screencopy.cpp | 18 ++++++++++++------ src/shared/ScreencopyShared.cpp | 10 +++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/portals/Screencopy.cpp b/src/portals/Screencopy.cpp index 694631c..ad7c870 100644 --- a/src/portals/Screencopy.cpp +++ b/src/portals/Screencopy.cpp @@ -96,6 +96,7 @@ static void wlrOnBufferDone(void* data, struct zwlr_screencopy_frame_v1* frame) Debug::log(TRACE, "[sc] wlrOnBufferDone: no stream"); zwlr_screencopy_frame_v1_destroy(frame); PSESSION->sharingData.frameCallback = nullptr; + PSESSION->sharingData.status = FRAME_NONE; return; } @@ -110,6 +111,7 @@ static void wlrOnBufferDone(void* data, struct zwlr_screencopy_frame_v1* frame) zwlr_screencopy_frame_v1_destroy(frame); g_pPortalManager->m_sPortals.screencopy->m_pPipewire->updateStreamParam(PSTREAM); g_pPortalManager->m_sPortals.screencopy->queueNextShareFrame(PSESSION); + PSESSION->sharingData.status = FRAME_NONE; return; } @@ -122,6 +124,7 @@ static void wlrOnBufferDone(void* data, struct zwlr_screencopy_frame_v1* frame) zwlr_screencopy_frame_v1_destroy(frame); PSESSION->sharingData.frameCallback = nullptr; Debug::log(LOG, "[screencopy/pipewire] Out of buffers"); + PSESSION->sharingData.status = FRAME_NONE; return; } @@ -430,6 +433,11 @@ void CScreencopyPortal::startFrameCopy(CScreencopyPortal::SSession* pSession) { } void CScreencopyPortal::queueNextShareFrame(CScreencopyPortal::SSession* pSession) { + const auto PSTREAM = m_pPipewire->streamFromSession(pSession); + + if (PSTREAM && !PSTREAM->streamState) + return; + g_pPortalManager->m_vTimers.emplace_back( std::make_unique(1000.0 / pSession->sharingData.framerate, [pSession]() { g_pPortalManager->m_sPortals.screencopy->startFrameCopy(pSession); })); } @@ -512,12 +520,7 @@ static void pwStreamStateChange(void* data, pw_stream_state old, pw_stream_state if (PSTREAM->pSession->sharingData.status == FRAME_NONE) g_pPortalManager->m_sPortals.screencopy->startFrameCopy(PSTREAM->pSession); break; - case PW_STREAM_STATE_PAUSED: - if (old == PW_STREAM_STATE_STREAMING) - g_pPortalManager->m_sPortals.screencopy->m_pPipewire->enqueue(PSTREAM->pSession); - PSTREAM->streamState = false; - break; - default: PSTREAM->streamState = false; + default: PSTREAM->streamState = false; break; } if (state == PW_STREAM_STATE_UNCONNECTED) @@ -699,6 +702,9 @@ static void pwStreamRemoveBuffer(void* data, pw_buffer* buffer) { if (!PBUFFER) return; + if (PSTREAM->currentPWBuffer == PBUFFER) + PSTREAM->currentPWBuffer = nullptr; + wl_buffer_destroy(PBUFFER->wlBuffer); for (int plane = 0; plane < PBUFFER->planeCount; plane++) { close(PBUFFER->fd[plane]); diff --git a/src/shared/ScreencopyShared.cpp b/src/shared/ScreencopyShared.cpp index 109d36c..c23b90e 100644 --- a/src/shared/ScreencopyShared.cpp +++ b/src/shared/ScreencopyShared.cpp @@ -14,6 +14,8 @@ SSelectionData promptForScreencopySelection() { const auto RETVAL = execAndGet("hyprland-share-picker"); + Debug::log(LOG, "[sc] Selection: {}", RETVAL); + if (RETVAL.find("screen:") == 0) { data.type = TYPE_OUTPUT; data.output = RETVAL.substr(7); @@ -28,15 +30,13 @@ SSelectionData promptForScreencopySelection() { data.output = running.substr(0, running.find_first_of('@')); running = running.substr(running.find_first_of('@') + 1); - data.x = std::stoi(running.substr(running.find_first_of(','))); + data.x = std::stoi(running.substr(0, running.find_first_of(','))); running = running.substr(running.find_first_of(',') + 1); - data.y = std::stoi(running.substr(running.find_first_of(','))); + data.y = std::stoi(running.substr(0, running.find_first_of(','))); running = running.substr(running.find_first_of(',') + 1); - data.w = std::stoi(running.substr(running.find_first_of(','))); + data.w = std::stoi(running.substr(0, running.find_first_of(','))); running = running.substr(running.find_first_of(',') + 1); data.h = std::stoi(running); - - data.output.pop_back(); } return data;