core: fade out improvements (#194)

* core: allow fade out for grace unlock

* core: disable input once fade out started

* core: render when fade out started

* core: allow fade out for other compositors

Works fine in sway altough it fades to a black screen not to the desktop.
Still looks kinda good.

* Revert "core: allow fade out for other compositors"

This reverts commit adfeb543ad.

* misc: rename lock and unlock functions
This commit is contained in:
Maximilian Seidler 2024-03-15 19:49:07 +01:00 committed by GitHub
parent e040c56ad2
commit 7ee406bf9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 24 deletions

View file

@ -304,7 +304,7 @@ static void registerSignalAction(int sig, void (*handler)(int), int sa_flags = 0
static void handleUnlockSignal(int sig) {
if (sig == SIGUSR1) {
Debug::log(LOG, "Unlocking with a SIGUSR1");
g_pHyprlock->unlockSession();
g_pHyprlock->releaseSessionLock();
}
}
@ -377,7 +377,7 @@ void CHyprlock::run() {
}
}
lockSession();
acquireSessionLock();
registerSignalAction(SIGUSR1, handleUnlockSignal, SA_RESTART);
registerSignalAction(SIGUSR2, handleForceUpdateSignal);
@ -458,7 +458,7 @@ void CHyprlock::run() {
m_sLoopState.loopCV.wait_for(lk, std::chrono::milliseconds(5000), [this] { return m_sLoopState.event; });
if (m_bTerminate || (std::chrono::system_clock::now() > m_tFadeEnds && m_bFadeStarted)) {
unlockSession();
releaseSessionLock();
break;
}
std::lock_guard<std::mutex> lg(m_sLoopState.eventLoopMutex);
@ -507,7 +507,7 @@ void CHyprlock::run() {
passed.clear();
if (m_bTerminate || (std::chrono::system_clock::now() > m_tFadeEnds && m_bFadeStarted)) {
unlockSession();
releaseSessionLock();
break;
}
}
@ -531,6 +531,24 @@ void CHyprlock::run() {
Debug::log(LOG, "Reached the end, exiting");
}
void CHyprlock::unlock() {
static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out");
const auto CURRENTDESKTOP = getenv("XDG_CURRENT_DESKTOP");
const auto SZCURRENTD = std::string{CURRENTDESKTOP ? CURRENTDESKTOP : ""};
if (**PNOFADEOUT || SZCURRENTD != "Hyprland") {
releaseSessionLock();
return;
}
m_tFadeEnds = std::chrono::system_clock::now() + std::chrono::milliseconds(500);
m_bFadeStarted = true;
for (auto& o : m_vOutputs) {
o->sessionLockSurface->render();
}
}
// wl_seat
static void handlePointerEnter(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
@ -557,10 +575,10 @@ static void handlePointerAxis(void* data, wl_pointer* wl_pointer, uint32_t time,
static void handlePointerMotion(void* data, struct wl_pointer* wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
if (g_pHyprlock->m_vLastEnterCoords.distance({wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y)}) > 5 &&
std::chrono::system_clock::now() < g_pHyprlock->m_tGraceEnds) {
std::chrono::system_clock::now() < g_pHyprlock->m_tGraceEnds && !g_pHyprlock->m_bFadeStarted) {
Debug::log(LOG, "In grace and cursor moved more than 5px, unlocking!");
g_pHyprlock->unlockSession();
g_pHyprlock->unlock();
}
}
@ -706,16 +724,9 @@ static const ext_session_lock_v1_listener sessionLockListener = {
// end session_lock
void CHyprlock::onPasswordCheckTimer() {
static auto* const PNOFADEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:no_fade_out");
const auto CURRENTDESKTOP = getenv("XDG_CURRENT_DESKTOP");
const auto SZCURRENTD = std::string{CURRENTDESKTOP ? CURRENTDESKTOP : ""};
// check result
if (m_sPasswordState.result->success) {
if (**PNOFADEOUT || SZCURRENTD != "Hyprland")
unlockSession();
m_tFadeEnds = std::chrono::system_clock::now() + std::chrono::milliseconds(500);
m_bFadeStarted = true;
unlock();
} else {
Debug::log(LOG, "Authentication failed: {}", m_sPasswordState.result->failReason);
m_sPasswordState.lastFailReason = m_sPasswordState.result->failReason;
@ -741,10 +752,11 @@ std::optional<std::string> CHyprlock::passwordLastFailReason() {
}
void CHyprlock::onKey(uint32_t key, bool down) {
const auto SYM = xkb_state_key_get_one_sym(m_pXKBState, key + 8);
if (m_bFadeStarted)
return;
if (down && std::chrono::system_clock::now() < g_pHyprlock->m_tGraceEnds) {
unlockSession();
if (down && std::chrono::system_clock::now() < m_tGraceEnds) {
unlock();
return;
}
@ -771,6 +783,8 @@ void CHyprlock::onKey(uint32_t key, bool down) {
return;
}
const auto SYM = xkb_state_key_get_one_sym(m_pXKBState, key + 8);
m_bCapsLock = xkb_state_mod_name_is_active(g_pHyprlock->m_pXKBState, XKB_MOD_NAME_CAPS, XKB_STATE_MODS_LOCKED);
m_bNumLock = xkb_state_mod_name_is_active(g_pHyprlock->m_pXKBState, XKB_MOD_NAME_NUM, XKB_STATE_MODS_LOCKED);
@ -800,13 +814,13 @@ void CHyprlock::onKey(uint32_t key, bool down) {
}
}
void CHyprlock::lockSession() {
void CHyprlock::acquireSessionLock() {
Debug::log(LOG, "Locking session");
m_sLockState.lock = ext_session_lock_manager_v1_lock(m_sWaylandState.sessionLock);
ext_session_lock_v1_add_listener(m_sLockState.lock, &sessionLockListener, nullptr);
}
void CHyprlock::unlockSession() {
void CHyprlock::releaseSessionLock() {
Debug::log(LOG, "Unlocking session");
if (m_bTerminate && !m_sLockState.lock) {
Debug::log(ERR, "Unlock already happend?");

View file

@ -32,6 +32,8 @@ class CHyprlock {
void run();
void unlock();
void onGlobal(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version);
void onGlobalRemoved(void* data, struct wl_registry* registry, uint32_t name);
@ -41,8 +43,8 @@ class CHyprlock {
void onLockLocked();
void onLockFinished();
void lockSession();
void unlockSession();
void acquireSessionLock();
void releaseSessionLock();
void attemptRestoreOnDeath();