screencopy: don't spam sw cursor locks

This commit is contained in:
Vaxry 2024-05-11 22:10:42 +01:00
parent 494b9415a1
commit 8562d38477
2 changed files with 28 additions and 7 deletions

View file

@ -1,5 +1,6 @@
#include "Screencopy.hpp"
#include "../Compositor.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp"
#include "../managers/PointerManager.hpp"
#include <algorithm>
@ -35,6 +36,20 @@ CScreencopyProtocolManager::CScreencopyProtocolManager() {
wl_display_add_destroy_listener(g_pCompositor->m_sWLDisplay, &m_liDisplayDestroy);
Debug::log(LOG, "ScreencopyProtocolManager started successfully!");
m_pSoftwareCursorTimer = makeShared<CEventLoopTimer>(
std::nullopt,
[this](SP<CEventLoopTimer> self, void* data) {
// TODO: make it per-monitor
for (auto& m : g_pCompositor->m_vMonitors) {
g_pPointerManager->unlockSoftwareForMonitor(m);
}
m_bTimerArmed = false;
Debug::log(LOG, "[screencopy] Releasing software cursor lock");
},
nullptr);
g_pEventLoopManager->addTimer(m_pSoftwareCursorTimer);
}
static void handleCaptureOutput(wl_client* client, wl_resource* resource, uint32_t frame, int32_t overlay_cursor, wl_resource* output) {
@ -184,11 +199,6 @@ void CScreencopyProtocolManager::removeFrame(SScreencopyFrame* frame, bool force
if (!frame)
return;
if (frame->lockedSWCursors) {
g_pPointerManager->unlockSoftwareForMonitor(frame->pMonitor->self.lock());
g_pPointerManager->damageCursor(frame->pMonitor->self.lock());
}
std::erase_if(m_vFramesAwaitingWrite, [&](const auto& other) { return other == frame; });
wl_resource_set_user_data(frame->resource, nullptr);
@ -360,8 +370,15 @@ void CScreencopyProtocolManager::copyFrame(wl_client* client, wl_resource* resou
g_pHyprRenderer->m_bDirectScanoutBlocked = true;
if (PFRAME->overlayCursor && !PFRAME->lockedSWCursors) {
PFRAME->lockedSWCursors = true;
g_pPointerManager->lockSoftwareForMonitor(PFRAME->pMonitor->self.lock());
g_pPointerManager->damageCursor(PFRAME->pMonitor->self.lock());
// TODO: make it per-monitor
if (!m_bTimerArmed) {
for (auto& m : g_pCompositor->m_vMonitors) {
g_pPointerManager->lockSoftwareForMonitor(m);
}
m_bTimerArmed = true;
Debug::log(LOG, "[screencopy] Locking sw cursors due to screensharing");
}
m_pSoftwareCursorTimer->updateTimeout(std::chrono::seconds(1));
}
if (!PFRAME->withDamage)

View file

@ -7,6 +7,7 @@
#include <vector>
#include "../managers/HookSystemManager.hpp"
#include "../helpers/Timer.hpp"
#include "../managers/eventLoop/EventLoopTimer.hpp"
class CMonitor;
@ -84,6 +85,9 @@ class CScreencopyProtocolManager {
std::list<SScreencopyFrame> m_lFrames;
std::list<CScreencopyClient> m_lClients;
SP<CEventLoopTimer> m_pSoftwareCursorTimer;
bool m_bTimerArmed = false;
wl_listener m_liDisplayDestroy;
std::vector<SScreencopyFrame*> m_vFramesAwaitingWrite;