screencopy: improve consistency of share indicator

This commit is contained in:
vaxerski 2023-04-17 22:57:24 +01:00
parent b4f75525d9
commit ae82c3a639
4 changed files with 27 additions and 16 deletions

View file

@ -118,25 +118,28 @@ CScreencopyClient::~CScreencopyClient() {
} }
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(); }); tickCallback = g_pHookSystem->hookDynamic("tick", [&](void* self, std::any data) { onTick(); });
} }
void CScreencopyClient::onTick() { void CScreencopyClient::onTick() {
const auto SINCELAST = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - lastMeasure).count() / 1000.0; if (lastMeasure.getMillis() < 500)
if (SINCELAST < 0.5)
return; return;
framesInLastHalfSecond = frameCounter; framesInLastHalfSecond = frameCounter;
frameCounter = 0; 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) { if (framesInLastHalfSecond > 3 && !sentScreencast) {
EMIT_HOOK_EVENT("screencast", (std::vector<uint64_t>{1, (uint64_t)framesInLastHalfSecond, (uint64_t)clientOwner})); 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)}); g_pEventManager->postEvent(SHyprIPCEvent{"screencast", "1," + std::to_string(clientOwner)});
sentScreencast = true; 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})); 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)}); g_pEventManager->postEvent(SHyprIPCEvent{"screencast", "0," + std::to_string(clientOwner)});
sentScreencast = false; sentScreencast = false;
@ -350,6 +353,7 @@ void CScreencopyProtocolManager::shareAllFrames(CMonitor* pMonitor, bool dmabuf)
shareFrame(f); shareFrame(f);
f->client->lastFrame.reset();
++f->client->frameCounter; ++f->client->frameCounter;
framesToRemove.push_back(f); framesToRemove.push_back(f);

View file

@ -6,6 +6,7 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include "../managers/HookSystemManager.hpp" #include "../managers/HookSystemManager.hpp"
#include "../helpers/Timer.hpp"
class CMonitor; class CMonitor;
@ -27,7 +28,8 @@ class CScreencopyClient {
int frameCounter = 0; int frameCounter = 0;
int framesInLastHalfSecond = 0; int framesInLastHalfSecond = 0;
std::chrono::system_clock::time_point lastMeasure; CTimer lastMeasure;
CTimer lastFrame;
bool sentScreencast = false; bool sentScreencast = false;
void onTick(); void onTick();
@ -94,4 +96,6 @@ class CScreencopyProtocolManager {
void sendFrameDamage(SScreencopyFrame* frame); void sendFrameDamage(SScreencopyFrame* frame);
bool copyFrameDmabuf(SScreencopyFrame* frame); bool copyFrameDmabuf(SScreencopyFrame* frame);
bool copyFrameShm(SScreencopyFrame* frame, timespec* now); bool copyFrameShm(SScreencopyFrame* frame, timespec* now);
friend class CScreencopyClient;
}; };

View file

@ -300,6 +300,7 @@ void CToplevelExportProtocolManager::onMonitorRender(CMonitor* pMonitor) {
shareFrame(f); shareFrame(f);
f->client->lastFrame.reset();
++f->client->frameCounter; ++f->client->frameCounter;
framesToRemove.push_back(f); framesToRemove.push_back(f);

View file

@ -37,4 +37,6 @@ class CToplevelExportProtocolManager {
bool copyFrameShm(SScreencopyFrame* frame, timespec* now); bool copyFrameShm(SScreencopyFrame* frame, timespec* now);
void onMonitorRender(CMonitor* pMonitor); void onMonitorRender(CMonitor* pMonitor);
friend class CScreencopyClient;
}; };