Skip to content

Commit

Permalink
core: create surface on monitor connect
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Feb 26, 2024
1 parent a7cffd0 commit 1f268e0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/core/Output.cpp
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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<CSessionLockSurface>(POUTPUT);
g_pRenderer->asyncResourceGatherer->recheckDMAFramesFor(POUTPUT);
}
}

static void handleScale(void* data, wl_output* output, int32_t factor) {
Expand Down
3 changes: 3 additions & 0 deletions src/core/hyprlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ void CHyprlock::unlockSession() {
Debug::log(LOG, "Unlocked, exiting!");

m_bTerminate = true;
m_bLocked = false;

wl_display_roundtrip(m_sWaylandState.display);
}
Expand All @@ -723,6 +724,8 @@ void CHyprlock::onLockLocked() {
for (auto& o : m_vOutputs) {
o->sessionLockSurface = std::make_unique<CSessionLockSurface>(o.get());
}

m_bLocked = true;
}

void CHyprlock::onLockFinished() {
Expand Down
2 changes: 2 additions & 0 deletions src/core/hyprlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
24 changes: 24 additions & 0 deletions src/renderer/AsyncResourceGatherer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Hyprlang::STRING>(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<CDMAFrame>(output));
}

SPreloadedAsset* CAsyncResourceGatherer::getAssetByID(const std::string& id) {
if (asyncLoopState.busy)
return nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/AsyncResourceGatherer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CAsyncResourceGatherer {
void unloadAsset(SPreloadedAsset* asset);
void notify();
void await();
void recheckDMAFramesFor(COutput* output);

private:
std::thread initThread;
Expand Down

0 comments on commit 1f268e0

Please sign in to comment.