diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2025-04-08 19:39:53 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-08 19:39:53 +0200 |
| commit | 260d8e1f71b1dc6f3f354747debdc87d96b9e99f (patch) | |
| tree | 9e13cd67a6b08e356a8773b093a9c8d9fdf645b0 /src/protocols/ToplevelExport.cpp | |
| parent | 642f394eb3f8fd99a51f4c8279497c458c40ba65 (diff) | |
Permission Manager: add permission management for screencopy (#9930)
Diffstat (limited to 'src/protocols/ToplevelExport.cpp')
| -rw-r--r-- | src/protocols/ToplevelExport.cpp | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp index 66e74164..8f18afbc 100644 --- a/src/protocols/ToplevelExport.cpp +++ b/src/protocols/ToplevelExport.cpp @@ -8,6 +8,7 @@ #include "../helpers/Format.hpp" #include "../managers/EventManager.hpp" #include "../managers/input/InputManager.hpp" +#include "../managers/permissions/DynamicPermissionManager.hpp" #include "../render/Renderer.hpp" #include <algorithm> @@ -231,7 +232,8 @@ void CToplevelExportFrame::share() { } bool CToplevelExportFrame::copyShm(timespec* now) { - auto shm = buffer->shm(); + const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(resource->client(), PERMISSION_TYPE_SCREENCOPY); + auto shm = buffer->shm(); auto [pixelData, fmt, bufLen] = buffer->beginDataPtr(0); // no need for end, cuz it's shm // render the client @@ -256,12 +258,18 @@ bool CToplevelExportFrame::copyShm(timespec* now) { g_pHyprOpenGL->clear(CHyprColor(0, 0, 0, 1.0)); // render client at 0,0 - g_pHyprRenderer->m_bBlockSurfaceFeedback = g_pHyprRenderer->shouldRenderWindow(pWindow); // block the feedback to avoid spamming the surface if it's visible - g_pHyprRenderer->renderWindow(pWindow, PMONITOR, now, false, RENDER_PASS_ALL, true, true); - g_pHyprRenderer->m_bBlockSurfaceFeedback = false; - - if (overlayCursor) - g_pPointerManager->renderSoftwareCursorsFor(PMONITOR->self.lock(), now, fakeDamage, g_pInputManager->getMouseCoordsInternal() - pWindow->m_vRealPosition->value()); + if (PERM == PERMISSION_RULE_ALLOW_MODE_ALLOW) { + g_pHyprRenderer->m_bBlockSurfaceFeedback = g_pHyprRenderer->shouldRenderWindow(pWindow); // block the feedback to avoid spamming the surface if it's visible + g_pHyprRenderer->renderWindow(pWindow, PMONITOR, now, false, RENDER_PASS_ALL, true, true); + g_pHyprRenderer->m_bBlockSurfaceFeedback = false; + + if (overlayCursor) + g_pPointerManager->renderSoftwareCursorsFor(PMONITOR->self.lock(), now, fakeDamage, g_pInputManager->getMouseCoordsInternal() - pWindow->m_vRealPosition->value()); + } else if (PERM == PERMISSION_RULE_ALLOW_MODE_DENY) { + CBox texbox = + CBox{PMONITOR->vecTransformedSize / 2.F, g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize}.translate(-g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize / 2.F); + g_pHyprOpenGL->renderTexture(g_pHyprOpenGL->m_pScreencopyDeniedTexture, texbox, 1); + } const auto PFORMAT = NFormatUtils::getPixelFormatFromDRM(shm.format); if (!PFORMAT) { @@ -322,6 +330,7 @@ bool CToplevelExportFrame::copyShm(timespec* now) { } bool CToplevelExportFrame::copyDmabuf(timespec* now) { + const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(resource->client(), PERMISSION_TYPE_SCREENCOPY); const auto PMONITOR = pWindow->m_pMonitor.lock(); CRegion fakeDamage{0, 0, INT16_MAX, INT16_MAX}; @@ -337,13 +346,18 @@ bool CToplevelExportFrame::copyDmabuf(timespec* now) { return false; g_pHyprOpenGL->clear(CHyprColor(0, 0, 0, 1.0)); - - g_pHyprRenderer->m_bBlockSurfaceFeedback = g_pHyprRenderer->shouldRenderWindow(pWindow); // block the feedback to avoid spamming the surface if it's visible - g_pHyprRenderer->renderWindow(pWindow, PMONITOR, now, false, RENDER_PASS_ALL, true, true); - g_pHyprRenderer->m_bBlockSurfaceFeedback = false; - - if (overlayCursor) - g_pPointerManager->renderSoftwareCursorsFor(PMONITOR->self.lock(), now, fakeDamage, g_pInputManager->getMouseCoordsInternal() - pWindow->m_vRealPosition->value()); + if (PERM == PERMISSION_RULE_ALLOW_MODE_ALLOW) { + g_pHyprRenderer->m_bBlockSurfaceFeedback = g_pHyprRenderer->shouldRenderWindow(pWindow); // block the feedback to avoid spamming the surface if it's visible + g_pHyprRenderer->renderWindow(pWindow, PMONITOR, now, false, RENDER_PASS_ALL, true, true); + g_pHyprRenderer->m_bBlockSurfaceFeedback = false; + + if (overlayCursor) + g_pPointerManager->renderSoftwareCursorsFor(PMONITOR->self.lock(), now, fakeDamage, g_pInputManager->getMouseCoordsInternal() - pWindow->m_vRealPosition->value()); + } else if (PERM == PERMISSION_RULE_ALLOW_MODE_DENY) { + CBox texbox = + CBox{PMONITOR->vecTransformedSize / 2.F, g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize}.translate(-g_pHyprOpenGL->m_pScreencopyDeniedTexture->m_vSize / 2.F); + g_pHyprOpenGL->renderTexture(g_pHyprOpenGL->m_pScreencopyDeniedTexture, texbox, 1); + } g_pHyprOpenGL->m_RenderData.blockScreenShader = true; g_pHyprRenderer->endRender(); @@ -417,6 +431,12 @@ void CToplevelExportProtocol::onOutputCommit(PHLMONITOR pMonitor) { if (!f) continue; + // check permissions + const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(f->resource->client(), PERMISSION_TYPE_SCREENCOPY); + + if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) + continue; // pending an answer, don't do anything yet. + if (!validMapped(f->pWindow)) { framesToRemove.emplace_back(f); continue; |
