Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pkg_check_modules(
gbm
hyprutils>=0.8.0
sdbus-c++>=2.0.0
hyprgraphics)
hyprgraphics>=0.1.6)
find_library(PAM_FOUND pam)
if(PAM_FOUND)
message(STATUS "Found pam")
Expand Down
35 changes: 17 additions & 18 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 38 additions & 85 deletions src/core/hyprlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#include "../helpers/Log.hpp"
#include "../config/ConfigManager.hpp"
#include "../renderer/Renderer.hpp"
#include "../renderer/AsyncResourceGatherer.hpp"
#include "../renderer/AsyncResourceManager.hpp"
#include "../auth/Auth.hpp"
#include "../auth/Fingerprint.hpp"
#include "Egl.hpp"
#include "./Egl.hpp"
#include "./Seat.hpp"
#include <chrono>
#include <hyprutils/memory/UniquePtr.hpp>
#include <sys/wait.h>
Expand Down Expand Up @@ -305,19 +306,6 @@ void CHyprlock::run() {
g_pRenderer->removeWidgetsFor((*outputIt)->m_ID);
m_vOutputs.erase(outputIt);
}

// TODO: Recreating the rendering context like this fixes an issue with nvidia graphics when reconnecting monitors.
// It only happens when there are no monitors left.
// This is either an nvidia bug (probably egl-wayland) or it is a hyprlock bug. In any case, the goal is to remove this at some point!
if (g_pEGL->m_isNvidia && m_vOutputs.empty()) {
Debug::log(LOG, "NVIDIA Workaround: destroying rendering context to avoid crash on reconnect!");

g_pRenderer.reset();
g_pEGL.reset();
g_pEGL = makeUnique<CEGL>(m_sWaylandState.display);
g_pRenderer = makeUnique<CRenderer>();
g_pRenderer->warpOpacity(1.0);
}
});

wl_display_roundtrip(m_sWaylandState.display);
Expand All @@ -330,60 +318,21 @@ void CHyprlock::run() {
// gather info about monitors
wl_display_roundtrip(m_sWaylandState.display);

g_pRenderer = makeUnique<CRenderer>();
g_pAsyncResourceGatherer = makeUnique<CAsyncResourceGatherer>();
g_pAuth = makeUnique<CAuth>();
g_pRenderer = makeUnique<CRenderer>();
g_asyncResourceManager = makeUnique<CAsyncResourceManager>();
g_pAuth = makeUnique<CAuth>();
g_pAuth->start();

Debug::log(LOG, "Running on {}", m_sCurrentDesktop);

if (!g_pHyprlock->m_bImmediateRender) {
g_asyncResourceManager->enqueueStaticAssets();
g_asyncResourceManager->enqueueScreencopyFrames();

if (!g_pHyprlock->m_bImmediateRender)
// Gather background resources and screencopy frames before locking the screen.
// We need to do this because as soon as we lock the screen, workspaces frames can no longer be captured. It either won't work at all, or we will capture hyprlock itself.
// Bypass with --immediate-render (can cause the background first rendering a solid color and missing or inaccurate screencopy frames)
const auto MAXDELAYMS = 2000; // 2 Seconds
const auto STARTGATHERTP = std::chrono::system_clock::now();

int fdcount = 1;
pollfd pollfds[2];
pollfds[0] = {
.fd = wl_display_get_fd(m_sWaylandState.display),
.events = POLLIN,
};

if (g_pAsyncResourceGatherer->gatheredEventfd.isValid()) {
pollfds[1] = {
.fd = g_pAsyncResourceGatherer->gatheredEventfd.get(),
.events = POLLIN,
};

fdcount++;
}

while (!g_pAsyncResourceGatherer->gathered) {
wl_display_flush(m_sWaylandState.display);
if (wl_display_prepare_read(m_sWaylandState.display) == 0) {
if (poll(pollfds, fdcount, /* 100ms timeout */ 100) < 0) {
RASSERT(errno == EINTR, "[core] Polling fds failed with {}", errno);
wl_display_cancel_read(m_sWaylandState.display);
continue;
}
wl_display_read_events(m_sWaylandState.display);
wl_display_dispatch_pending(m_sWaylandState.display);
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
wl_display_dispatch(m_sWaylandState.display);
}

if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - STARTGATHERTP).count() > MAXDELAYMS) {
Debug::log(WARN, "Gathering resources timed out after {} milliseconds. Backgrounds may be delayed and render `background:color` at first.", MAXDELAYMS);
break;
}
}

Debug::log(LOG, "Resources gathered after {} milliseconds",
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - STARTGATHERTP).count());
}
g_asyncResourceManager->gatherInitialResources(m_sWaylandState.display);

// Failed to lock the session
if (!acquireSessionLock()) {
Expand Down Expand Up @@ -498,28 +447,7 @@ void CHyprlock::run() {
}
}

// do timers
m_sLoopState.timersMutex.lock();
auto timerscpy = m_vTimers;
m_sLoopState.timersMutex.unlock();

std::vector<ASP<CTimer>> passed;

for (auto& t : timerscpy) {
if (t->passed() && !t->cancelled()) {
t->call(t);
passed.push_back(t);
}

if (t->cancelled())
passed.push_back(t);
}

m_sLoopState.timersMutex.lock();
std::erase_if(m_vTimers, [passed](const auto& timer) { return std::find(passed.begin(), passed.end(), timer) != passed.end(); });
m_sLoopState.timersMutex.unlock();

passed.clear();
processTimers();
}

const auto DPY = m_sWaylandState.display;
Expand All @@ -531,7 +459,7 @@ void CHyprlock::run() {

m_vOutputs.clear();
g_pSeatManager.reset();
g_pAsyncResourceGatherer.reset();
g_asyncResourceManager.reset();
g_pRenderer.reset();
g_pEGL.reset();

Expand Down Expand Up @@ -908,6 +836,31 @@ ASP<CTimer> CHyprlock::addTimer(const std::chrono::system_clock::duration& timeo
return T;
}

void CHyprlock::processTimers() {
// do timers
m_sLoopState.timersMutex.lock();
auto timerscpy = m_vTimers;
m_sLoopState.timersMutex.unlock();

std::vector<ASP<CTimer>> passed;

for (auto& t : timerscpy) {
if (t->passed() && !t->cancelled()) {
t->call(t);
passed.push_back(t);
}

if (t->cancelled())
passed.push_back(t);
}

m_sLoopState.timersMutex.lock();
std::erase_if(m_vTimers, [passed](const auto& timer) { return std::find(passed.begin(), passed.end(), timer) != passed.end(); });
m_sLoopState.timersMutex.unlock();

passed.clear();
}

std::vector<ASP<CTimer>> CHyprlock::getTimers() {
return m_vTimers;
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/hyprlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
#include "linux-dmabuf-v1.hpp"
#include "viewporter.hpp"
#include "Output.hpp"
#include "Seat.hpp"
#include "CursorShape.hpp"
#include "Timer.hpp"
#include <memory>
#include <vector>
#include <condition_variable>
#include <optional>
Expand All @@ -38,6 +35,7 @@ class CHyprlock {
bool isUnlocked();

ASP<CTimer> addTimer(const std::chrono::system_clock::duration& timeout, std::function<void(ASP<CTimer> self, void* data)> cb_, void* data, bool force = false);
void processTimers();

void enqueueForceUpdateTimers();

Expand Down
3 changes: 3 additions & 0 deletions src/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

using namespace Hyprutils::Memory;
using namespace Hyprgraphics;

using ResourceID = size_t;

#define SP CSharedPointer
#define WP CWeakPointer
#define UP CUniquePointer
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ namespace Debug {
std::println("[{}] {}", logLevelString(level), std::vformat(fmt, std::make_format_args(args...)));
}
}
};
};
Loading