mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
input-field: display utf-8 codepoint length (#164)
This commit is contained in:
parent
160fe3553f
commit
766d470308
3 changed files with 9 additions and 3 deletions
|
@ -825,6 +825,11 @@ size_t CHyprlock::getPasswordBufferLen() {
|
||||||
return m_sPasswordState.passBuffer.length();
|
return m_sPasswordState.passBuffer.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t CHyprlock::getPasswordBufferDisplayLen() {
|
||||||
|
// Counts utf-8 codepoints in the buffer. A byte is counted if it does not match 0b10xxxxxx.
|
||||||
|
return std::count_if(m_sPasswordState.passBuffer.begin(), m_sPasswordState.passBuffer.end(), [](char c) { return (c & 0xc0) != 0x80; });
|
||||||
|
}
|
||||||
|
|
||||||
size_t CHyprlock::getPasswordFailedAttempts() {
|
size_t CHyprlock::getPasswordFailedAttempts() {
|
||||||
return m_sPasswordState.failedAttempts;
|
return m_sPasswordState.failedAttempts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ class CHyprlock {
|
||||||
std::optional<std::string> passwordLastFailReason();
|
std::optional<std::string> passwordLastFailReason();
|
||||||
|
|
||||||
size_t getPasswordBufferLen();
|
size_t getPasswordBufferLen();
|
||||||
|
size_t getPasswordBufferDisplayLen();
|
||||||
size_t getPasswordFailedAttempts();
|
size_t getPasswordFailedAttempts();
|
||||||
|
|
||||||
ext_session_lock_manager_v1* getSessionLockMgr();
|
ext_session_lock_manager_v1* getSessionLockMgr();
|
||||||
|
|
|
@ -121,7 +121,7 @@ void CPasswordInputField::updateFade() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPasswordInputField::updateDots() {
|
void CPasswordInputField::updateDots() {
|
||||||
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();
|
const auto PASSLEN = g_pHyprlock->getPasswordBufferDisplayLen();
|
||||||
|
|
||||||
if (PASSLEN == dots.currentAmount)
|
if (PASSLEN == dots.currentAmount)
|
||||||
return;
|
return;
|
||||||
|
@ -320,11 +320,11 @@ void CPasswordInputField::updateFailTex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPasswordInputField::updateHiddenInputState() {
|
void CPasswordInputField::updateHiddenInputState() {
|
||||||
if (!hiddenInputState.enabled || (size_t)hiddenInputState.lastPasswordLength == g_pHyprlock->getPasswordBufferLen())
|
if (!hiddenInputState.enabled || (size_t)hiddenInputState.lastPasswordLength == g_pHyprlock->getPasswordBufferDisplayLen())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// randomize new thang
|
// randomize new thang
|
||||||
hiddenInputState.lastPasswordLength = g_pHyprlock->getPasswordBufferLen();
|
hiddenInputState.lastPasswordLength = g_pHyprlock->getPasswordBufferDisplayLen();
|
||||||
|
|
||||||
srand(std::chrono::system_clock::now().time_since_epoch().count());
|
srand(std::chrono::system_clock::now().time_since_epoch().count());
|
||||||
float r1 = (rand() % 100) / 255.0;
|
float r1 = (rand() % 100) / 255.0;
|
||||||
|
|
Loading…
Reference in a new issue