Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 16, 2025
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
6 changes: 3 additions & 3 deletions src/core/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
1 change: 1 addition & 0 deletions src/core/Output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 24 additions & 14 deletions src/core/hyprlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -701,16 +697,36 @@ 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(); });

m_sLockState.lock->setFinished([this](CCExtSessionLockV1* r) { onLockFinished(); });

// 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() {
Expand Down Expand Up @@ -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");

Expand Down
7 changes: 3 additions & 4 deletions src/core/hyprlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down