summaryrefslogtreecommitdiff
path: root/src/protocols/Screencopy.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2023-04-17 22:57:24 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2023-04-17 22:57:24 +0100
commitae82c3a639691c8c9ce9d631e18d74772c36b113 (patch)
treec156546da25aa85c93bc4b86351d92260591b37e /src/protocols/Screencopy.cpp
parentb4f75525d9d11364a69944c48b5ace21dc229fca (diff)
screencopy: improve consistency of share indicator
Diffstat (limited to 'src/protocols/Screencopy.cpp')
-rw-r--r--src/protocols/Screencopy.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp
index 9826ad15..f42fa3a5 100644
--- a/src/protocols/Screencopy.cpp
+++ b/src/protocols/Screencopy.cpp
@@ -118,25 +118,28 @@ CScreencopyClient::~CScreencopyClient() {
}
CScreencopyClient::CScreencopyClient() {
- lastMeasure = std::chrono::system_clock::now();
+ lastMeasure.reset();
+ lastFrame.reset();
tickCallback = g_pHookSystem->hookDynamic("tick", [&](void* self, std::any data) { onTick(); });
}
void CScreencopyClient::onTick() {
- const auto SINCELAST = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - lastMeasure).count() / 1000.0;
-
- if (SINCELAST < 0.5)
+ if (lastMeasure.getMillis() < 500)
return;
framesInLastHalfSecond = frameCounter;
frameCounter = 0;
- lastMeasure = std::chrono::system_clock::now();
+ lastMeasure.reset();
+
+ const auto LASTFRAMEDELTA = lastFrame.getMillis() / 1000.0;
+ const bool FRAMEAWAITING = std::ranges::any_of(g_pProtocolManager->m_pScreencopyProtocolManager->m_lFrames, [&](const auto& frame) { return frame.client == this; }) ||
+ std::ranges::any_of(g_pProtocolManager->m_pToplevelExportProtocolManager->m_lFrames, [&](const auto& frame) { return frame.client == this; });
if (framesInLastHalfSecond > 3 && !sentScreencast) {
EMIT_HOOK_EVENT("screencast", (std::vector<uint64_t>{1, (uint64_t)framesInLastHalfSecond, (uint64_t)clientOwner}));
g_pEventManager->postEvent(SHyprIPCEvent{"screencast", "1," + std::to_string(clientOwner)});
sentScreencast = true;
- } else if (framesInLastHalfSecond < 4 && sentScreencast) {
+ } else if (framesInLastHalfSecond < 4 && sentScreencast && LASTFRAMEDELTA > 1.0 && !FRAMEAWAITING) {
EMIT_HOOK_EVENT("screencast", (std::vector<uint64_t>{0, (uint64_t)framesInLastHalfSecond, (uint64_t)clientOwner}));
g_pEventManager->postEvent(SHyprIPCEvent{"screencast", "0," + std::to_string(clientOwner)});
sentScreencast = false;
@@ -350,6 +353,7 @@ void CScreencopyProtocolManager::shareAllFrames(CMonitor* pMonitor, bool dmabuf)
shareFrame(f);
+ f->client->lastFrame.reset();
++f->client->frameCounter;
framesToRemove.push_back(f);