From 1f268e0a39fb7dbe9ce1fd83d1b3d4c2165bf892 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 26 Feb 2024 17:58:50 +0000 Subject: [PATCH] core: create surface on monitor connect --- src/core/Output.cpp | 16 +++++++++++++--- src/core/hyprlock.cpp | 3 +++ src/core/hyprlock.hpp | 2 ++ src/renderer/AsyncResourceGatherer.cpp | 24 ++++++++++++++++++++++++ src/renderer/AsyncResourceGatherer.hpp | 1 + 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/core/Output.cpp b/src/core/Output.cpp index 1622ef0..0369baf 100644 --- a/src/core/Output.cpp +++ b/src/core/Output.cpp @@ -1,5 +1,7 @@ #include "Output.hpp" #include "../helpers/Log.hpp" +#include "hyprlock.hpp" +#include "../renderer/Renderer.hpp" static void handleGeometry(void* data, wl_output* output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform) { @@ -13,15 +15,23 @@ static void handleMode(void* data, wl_output* output, uint32_t flags, int32_t wi const auto POUTPUT = (COutput*)data; // handle portrait mode and flipped cases - if (POUTPUT->transform == WL_OUTPUT_TRANSFORM_270 || POUTPUT->transform == WL_OUTPUT_TRANSFORM_90 || - POUTPUT->transform == WL_OUTPUT_TRANSFORM_FLIPPED_270 || POUTPUT->transform == WL_OUTPUT_TRANSFORM_FLIPPED_90) + if (POUTPUT->transform == WL_OUTPUT_TRANSFORM_270 || POUTPUT->transform == WL_OUTPUT_TRANSFORM_90 || POUTPUT->transform == WL_OUTPUT_TRANSFORM_FLIPPED_270 || + POUTPUT->transform == WL_OUTPUT_TRANSFORM_FLIPPED_90) POUTPUT->size = {height, width}; else POUTPUT->size = {width, height}; } static void handleDone(void* data, wl_output* output) { - ; + const auto POUTPUT = (COutput*)data; + Debug::log(LOG, "output {} done", POUTPUT->name); + if (g_pHyprlock->m_bLocked && !POUTPUT->sessionLockSurface) { + // if we are already locked, create a surface dynamically after a small timeout + // we also need to request a dma frame for screenshots + Debug::log(LOG, "Creating a surface dynamically for output as we are already locked"); + POUTPUT->sessionLockSurface = std::make_unique(POUTPUT); + g_pRenderer->asyncResourceGatherer->recheckDMAFramesFor(POUTPUT); + } } static void handleScale(void* data, wl_output* output, int32_t factor) { diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index f9019d6..5d2f336 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -713,6 +713,7 @@ void CHyprlock::unlockSession() { Debug::log(LOG, "Unlocked, exiting!"); m_bTerminate = true; + m_bLocked = false; wl_display_roundtrip(m_sWaylandState.display); } @@ -723,6 +724,8 @@ void CHyprlock::onLockLocked() { for (auto& o : m_vOutputs) { o->sessionLockSurface = std::make_unique(o.get()); } + + m_bLocked = true; } void CHyprlock::onLockFinished() { diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index 46eca86..64a659d 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -72,6 +72,8 @@ class CHyprlock { bool m_bTerminate = false; + bool m_bLocked = false; + // std::chrono::system_clock::time_point m_tGraceEnds; Vector2D m_vLastEnterCoords = {}; diff --git a/src/renderer/AsyncResourceGatherer.cpp b/src/renderer/AsyncResourceGatherer.cpp index 81bf029..7c97efd 100644 --- a/src/renderer/AsyncResourceGatherer.cpp +++ b/src/renderer/AsyncResourceGatherer.cpp @@ -53,6 +53,30 @@ CAsyncResourceGatherer::CAsyncResourceGatherer() { } } +void CAsyncResourceGatherer::recheckDMAFramesFor(COutput* output) { + const auto CWIDGETS = g_pConfigManager->getWidgetConfigs(); + + bool shouldMake = false; + + for (auto& c : CWIDGETS) { + if (c.type != "background") + continue; + + if (std::string{std::any_cast(c.values.at("path"))} != "screenshot") + continue; + + if (c.monitor.empty() || c.monitor == output->stringPort) { + shouldMake = true; + break; + } + } + + if (!shouldMake) + return; + + dmas.emplace_back(std::make_unique(output)); +} + SPreloadedAsset* CAsyncResourceGatherer::getAssetByID(const std::string& id) { if (asyncLoopState.busy) return nullptr; diff --git a/src/renderer/AsyncResourceGatherer.hpp b/src/renderer/AsyncResourceGatherer.hpp index 64a81e4..24a5e56 100644 --- a/src/renderer/AsyncResourceGatherer.hpp +++ b/src/renderer/AsyncResourceGatherer.hpp @@ -43,6 +43,7 @@ class CAsyncResourceGatherer { void unloadAsset(SPreloadedAsset* asset); void notify(); void await(); + void recheckDMAFramesFor(COutput* output); private: std::thread initThread;