core: don't rely on the locked event to create lock surfaces dynamically (#687)

This commit is contained in:
Maximilian Seidler 2025-02-16 06:29:52 +00:00 committed by GitHub
parent 82b63a6930
commit c4b2175822
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 21 deletions

View file

@ -18,10 +18,10 @@ COutput::COutput(SP<CCWlOutput> output_, uint32_t name_) : name(name_), output(o
output->setScale([this](CCWlOutput* r, int32_t sc) { scale = sc; });
output->setDone([this](CCWlOutput* r) {
done = true;
Debug::log(LOG, "output {} done", name);
if (g_pHyprlock->m_bLocked && !sessionLockSurface) {
// if we are already locked, create a surface dynamically
Debug::log(LOG, "Creating a surface dynamically for output as we are already locked");
if (g_pHyprlock->m_lockAquired && !sessionLockSurface) {
Debug::log(LOG, "output {} creating a new lock surface", name);
sessionLockSurface = std::make_unique<CSessionLockSurface>(this);
}
});

View file

@ -12,6 +12,7 @@ class COutput {
uint32_t name = 0;
bool focused = false;
bool done = false;
wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
Vector2D size;
int scale = 1;

View file

@ -345,10 +345,8 @@ void CHyprlock::run() {
}
}
acquireSessionLock();
// Recieved finished
if (m_bTerminate) {
// Failed to lock the session
if (!acquireSessionLock()) {
m_sLoopState.timerEvent = true;
m_sLoopState.timerCV.notify_all();
g_pRenderer->asyncResourceGatherer->notify();
@ -366,8 +364,6 @@ void CHyprlock::run() {
registerSignalAction(SIGSEGV, handleCriticalSignal);
registerSignalAction(SIGABRT, handleCriticalSignal);
createSessionLockSurfaces();
pollfd pollfds[2];
pollfds[0] = {
.fd = wl_display_get_fd(m_sWaylandState.display),
@ -433,7 +429,7 @@ void CHyprlock::run() {
float least = 10000;
for (auto& t : m_vTimers) {
const auto TIME = std::clamp(t->leftMs(), 1.f, INFINITY);
least = std::min(TIME, least);
least = std::min(TIME, least);
}
m_sLoopState.timersMutex.unlock();
@ -701,9 +697,13 @@ void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) {
}
}
void CHyprlock::acquireSessionLock() {
bool CHyprlock::acquireSessionLock() {
Debug::log(LOG, "Locking session");
m_sLockState.lock = makeShared<CCExtSessionLockV1>(m_sWaylandState.sessionLock->sendLock());
if (!m_sLockState.lock) {
Debug::log(ERR, "Failed to create a lock object!");
return false;
}
m_sLockState.lock->setLocked([this](CCExtSessionLockV1* r) { onLockLocked(); });
@ -711,6 +711,22 @@ void CHyprlock::acquireSessionLock() {
// roundtrip in case the compositor sends `finished` right away
wl_display_roundtrip(m_sWaylandState.display);
// recieved finished right away (probably already locked)
if (m_bTerminate)
return false;
m_lockAquired = true;
// create a session lock surface for exiting outputs
for (auto& o : m_vOutputs) {
if (!o->done)
continue;
o->sessionLockSurface = std::make_unique<CSessionLockSurface>(o.get());
}
return true;
}
void CHyprlock::releaseSessionLock() {
@ -743,12 +759,6 @@ void CHyprlock::releaseSessionLock() {
wl_display_roundtrip(m_sWaylandState.display);
}
void CHyprlock::createSessionLockSurfaces() {
for (auto& o : m_vOutputs) {
o->sessionLockSurface = std::make_unique<CSessionLockSurface>(o.get());
}
}
void CHyprlock::onLockLocked() {
Debug::log(LOG, "onLockLocked called");

View file

@ -48,11 +48,9 @@ class CHyprlock {
void onLockLocked();
void onLockFinished();
void acquireSessionLock();
bool acquireSessionLock();
void releaseSessionLock();
void createSessionLockSurfaces();
void attemptRestoreOnDeath();
std::string spawnSync(const std::string& cmd);
@ -88,7 +86,8 @@ class CHyprlock {
bool m_bTerminate = false;
bool m_bLocked = false;
bool m_lockAquired = false;
bool m_bLocked = false;
bool m_bCapsLock = false;
bool m_bNumLock = false;