lock: fix red screen issues with multiple monitors (#5100)

* lock: use uint64_t for iMonitorID

* lock: move activateLock to onNewSessionLock

* lock: add red screen fade

* lock: damage when fading the red screen and delay for screencopy

* lock: remove redundant scheduleFrameForMonitor
This commit is contained in:
Maximilian Seidler 2024-03-15 17:17:13 +01:00 committed by GitHub
parent bb933dcf04
commit a958884b52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 11 deletions

View file

@ -15,8 +15,6 @@ static void handleSurfaceMap(void* owner, void* data) {
if (PMONITOR) if (PMONITOR)
g_pHyprRenderer->damageMonitor(PMONITOR); g_pHyprRenderer->damageMonitor(PMONITOR);
g_pSessionLockManager->activateLock(); // activate lock here to prevent the red screen from flashing before that
} }
static void handleSurfaceCommit(void* owner, void* data) { static void handleSurfaceCommit(void* owner, void* data) {
@ -97,6 +95,8 @@ void CSessionLockManager::onNewSessionLock(wlr_session_lock_v1* pWlrLock) {
m_sSessionLock.active = false; m_sSessionLock.active = false;
m_sSessionLock.mMonitorsWithoutMappedSurfaceTimers.clear();
g_pCompositor->m_sSeat.exclusiveClient = nullptr; g_pCompositor->m_sSeat.exclusiveClient = nullptr;
g_pInputManager->refocus(); g_pInputManager->refocus();
@ -126,13 +126,15 @@ void CSessionLockManager::onNewSessionLock(wlr_session_lock_v1* pWlrLock) {
pWlrLock, "wlr_session_lock_v1"); pWlrLock, "wlr_session_lock_v1");
wlr_session_lock_v1_send_locked(pWlrLock); wlr_session_lock_v1_send_locked(pWlrLock);
g_pSessionLockManager->activateLock();
} }
bool CSessionLockManager::isSessionLocked() { bool CSessionLockManager::isSessionLocked() {
return m_sSessionLock.active; return m_sSessionLock.active;
} }
SSessionLockSurface* CSessionLockManager::getSessionLockSurfaceForMonitor(const int& id) { SSessionLockSurface* CSessionLockManager::getSessionLockSurfaceForMonitor(uint64_t id) {
for (auto& sls : m_sSessionLock.vSessionLockSurfaces) { for (auto& sls : m_sSessionLock.vSessionLockSurfaces) {
if (sls->iMonitorID == id) { if (sls->iMonitorID == id) {
if (sls->mapped) if (sls->mapped)
@ -145,6 +147,20 @@ SSessionLockSurface* CSessionLockManager::getSessionLockSurfaceForMonitor(const
return nullptr; return nullptr;
} }
// We don't want the red screen to flash.
// This violates the protocol a bit, but tries to handle the missing sync between a lock surface beeing created and the red screen beeing drawn.
float CSessionLockManager::getRedScreenAlphaForMonitor(uint64_t id) {
const auto& NOMAPPEDSURFACETIMER = m_sSessionLock.mMonitorsWithoutMappedSurfaceTimers.find(id);
if (NOMAPPEDSURFACETIMER == m_sSessionLock.mMonitorsWithoutMappedSurfaceTimers.end()) {
m_sSessionLock.mMonitorsWithoutMappedSurfaceTimers.emplace(id, CTimer());
m_sSessionLock.mMonitorsWithoutMappedSurfaceTimers[id].reset();
return 0.f;
}
return std::clamp(NOMAPPEDSURFACETIMER->second.getSeconds() - /* delay for screencopy */ 0.5f, 0.f, 1.f);
}
bool CSessionLockManager::isSurfaceSessionLock(wlr_surface* pSurface) { bool CSessionLockManager::isSurfaceSessionLock(wlr_surface* pSurface) {
for (auto& sls : m_sSessionLock.vSessionLockSurfaces) { for (auto& sls : m_sSessionLock.vSessionLockSurfaces) {
if (sls->pWlrLockSurface->surface == pSurface) if (sls->pWlrLockSurface->surface == pSurface)

View file

@ -1,10 +1,13 @@
#pragma once #pragma once
#include "../defines.hpp" #include "../defines.hpp"
#include "../helpers/Timer.hpp"
#include <cstdint>
#include <unordered_map>
struct SSessionLockSurface { struct SSessionLockSurface {
wlr_session_lock_surface_v1* pWlrLockSurface = nullptr; wlr_session_lock_surface_v1* pWlrLockSurface = nullptr;
int iMonitorID = -1; uint64_t iMonitorID = -1;
bool mapped = false; bool mapped = false;
@ -18,6 +21,7 @@ struct SSessionLock {
wlr_session_lock_v1* pWlrLock = nullptr; wlr_session_lock_v1* pWlrLock = nullptr;
std::vector<std::unique_ptr<SSessionLockSurface>> vSessionLockSurfaces; std::vector<std::unique_ptr<SSessionLockSurface>> vSessionLockSurfaces;
std::unordered_map<uint64_t, CTimer> mMonitorsWithoutMappedSurfaceTimers;
DYNLISTENER(newSurface); DYNLISTENER(newSurface);
DYNLISTENER(unlock); DYNLISTENER(unlock);
@ -30,7 +34,9 @@ class CSessionLockManager {
~CSessionLockManager() = default; ~CSessionLockManager() = default;
void onNewSessionLock(wlr_session_lock_v1*); void onNewSessionLock(wlr_session_lock_v1*);
SSessionLockSurface* getSessionLockSurfaceForMonitor(const int&); SSessionLockSurface* getSessionLockSurfaceForMonitor(uint64_t);
float getRedScreenAlphaForMonitor(uint64_t);
bool isSessionLocked(); bool isSessionLocked();
bool isSurfaceSessionLock(wlr_surface*); bool isSurfaceSessionLock(wlr_surface*);

View file

@ -815,16 +815,23 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace*
g_pHyprOpenGL->m_RenderData.renderModif = {}; g_pHyprOpenGL->m_RenderData.renderModif = {};
} }
void CHyprRenderer::renderLockscreen(CMonitor* pMonitor, timespec* now) { void CHyprRenderer::renderLockscreen(CMonitor* pMonitor, timespec* now, const CBox& geometry) {
TRACY_GPU_ZONE("RenderLockscreen"); TRACY_GPU_ZONE("RenderLockscreen");
if (g_pSessionLockManager->isSessionLocked()) { if (g_pSessionLockManager->isSessionLocked()) {
const auto PSLS = g_pSessionLockManager->getSessionLockSurfaceForMonitor(pMonitor->ID); Vector2D translate = {geometry.x, geometry.y};
float scale = (float)geometry.width / pMonitor->vecPixelSize.x;
const auto PSLS = g_pSessionLockManager->getSessionLockSurfaceForMonitor(pMonitor->ID);
if (!PSLS) { if (!PSLS) {
// locked with no surface, fill with red // locked with no surface, fill with red
CBox boxe = {0, 0, INT16_MAX, INT16_MAX}; const auto ALPHA = g_pSessionLockManager->getRedScreenAlphaForMonitor(pMonitor->ID);
g_pHyprOpenGL->renderRect(&boxe, CColor(1.0, 0.2, 0.2, 1.0));
CBox monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale};
g_pHyprOpenGL->renderRect(&monbox, CColor(1.0, 0.2, 0.2, ALPHA));
if (ALPHA < 1.f) /* animate */
damageMonitor(pMonitor);
} else { } else {
renderSessionLockSurface(PSLS, pMonitor, now); renderSessionLockSurface(PSLS, pMonitor, now);
} }
@ -1206,7 +1213,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
CBox renderBox = {0, 0, (int)pMonitor->vecPixelSize.x, (int)pMonitor->vecPixelSize.y}; CBox renderBox = {0, 0, (int)pMonitor->vecPixelSize.x, (int)pMonitor->vecPixelSize.y};
renderWorkspace(pMonitor, g_pCompositor->getWorkspaceByID(pMonitor->activeWorkspace), &now, renderBox); renderWorkspace(pMonitor, g_pCompositor->getWorkspaceByID(pMonitor->activeWorkspace), &now, renderBox);
renderLockscreen(pMonitor, &now); renderLockscreen(pMonitor, &now, renderBox);
if (pMonitor == g_pCompositor->m_pLastMonitor) { if (pMonitor == g_pCompositor->m_pLastMonitor) {
g_pHyprNotificationOverlay->draw(pMonitor); g_pHyprNotificationOverlay->draw(pMonitor);

View file

@ -59,7 +59,7 @@ class CHyprRenderer {
void setCursorHidden(bool hide); void setCursorHidden(bool hide);
void calculateUVForSurface(CWindow*, wlr_surface*, bool main = false, const Vector2D& projSize = {}, bool fixMisalignedFSV1 = false); void calculateUVForSurface(CWindow*, wlr_surface*, bool main = false, const Vector2D& projSize = {}, bool fixMisalignedFSV1 = false);
std::tuple<float, float, float> getRenderTimes(CMonitor* pMonitor); // avg max min std::tuple<float, float, float> getRenderTimes(CMonitor* pMonitor); // avg max min
void renderLockscreen(CMonitor* pMonitor, timespec* now); void renderLockscreen(CMonitor* pMonitor, timespec* now, const CBox& geometry);
void setOccludedForBackLayers(CRegion& region, CWorkspace* pWorkspace); void setOccludedForBackLayers(CRegion& region, CWorkspace* pWorkspace);
void setOccludedForMainWorkspace(CRegion& region, CWorkspace* pWorkspace); // TODO: merge occlusion methods void setOccludedForMainWorkspace(CRegion& region, CWorkspace* pWorkspace); // TODO: merge occlusion methods
bool canSkipBackBufferClear(CMonitor* pMonitor); bool canSkipBackBufferClear(CMonitor* pMonitor);