mirror of
https://github.com/hyprwm/hyprlock.git
synced 2026-05-14 08:48:03 +02:00
store show variable now in CPasswordInputField instead of CHyprlock
This commit is contained in:
parent
653663e31c
commit
fb5a70f898
4 changed files with 30 additions and 16 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include "../helpers/Log.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "../renderer/Renderer.hpp"
|
||||
#include "../renderer/widgets/PasswordInputField.hpp"
|
||||
#include "../auth/Auth.hpp"
|
||||
#include "../auth/Fingerprint.hpp"
|
||||
#include "Egl.hpp"
|
||||
|
|
@ -687,7 +688,16 @@ void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) {
|
|||
m_sPasswordState.passBuffer = m_sPasswordState.passBuffer.substr(0, m_sPasswordState.passBuffer.length() - 1);
|
||||
}
|
||||
} else if (SYM == XKB_KEY_Tab) {
|
||||
m_sPasswordState.show = !m_sPasswordState.show;
|
||||
for (auto& o : m_vOutputs) {
|
||||
const auto widgets = g_pRenderer->getOrCreateWidgetsFor(*o->m_sessionLockSurface);
|
||||
|
||||
for (auto& w : widgets) {
|
||||
if (w->type == "password-input") {
|
||||
auto password_field = reinterpret_cast<CPasswordInputField*>(w.get());
|
||||
password_field->togglePassword();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (SYM == XKB_KEY_Caps_Lock) {
|
||||
m_bCapsLock = !m_bCapsLock;
|
||||
} else if (SYM == XKB_KEY_Num_Lock) {
|
||||
|
|
@ -877,14 +887,6 @@ std::string CHyprlock::getPasswordBuffer() {
|
|||
return m_sPasswordState.passBuffer;
|
||||
}
|
||||
|
||||
bool CHyprlock::getPasswordShow() {
|
||||
return m_sPasswordState.show;
|
||||
}
|
||||
|
||||
void CHyprlock::togglePasswordShow() {
|
||||
m_sPasswordState.show = !m_sPasswordState.show;
|
||||
}
|
||||
|
||||
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; });
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ class IWidget {
|
|||
void setHover(bool hover);
|
||||
bool isHovered() const;
|
||||
|
||||
std::string type;
|
||||
|
||||
private:
|
||||
bool hovered = false;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ CPasswordInputField::~CPasswordInputField() {
|
|||
|
||||
void CPasswordInputField::registerSelf(const ASP<CPasswordInputField>& self) {
|
||||
m_self = self;
|
||||
|
||||
type = "password-input";
|
||||
}
|
||||
|
||||
void CPasswordInputField::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
|
|
@ -262,10 +264,9 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
|
||||
bool forceReload = false;
|
||||
|
||||
bool showPassword = g_pHyprlock->getPasswordShow();
|
||||
passwordLength = g_pHyprlock->getPasswordBufferDisplayLen();
|
||||
checkWaiting = g_pAuth->checkWaiting();
|
||||
displayFail = g_pAuth->m_bDisplayFailText;
|
||||
passwordLength = g_pHyprlock->getPasswordBufferDisplayLen();
|
||||
checkWaiting = g_pAuth->checkWaiting();
|
||||
displayFail = g_pAuth->m_bDisplayFailText;
|
||||
|
||||
updateFade();
|
||||
updateDots();
|
||||
|
|
@ -325,14 +326,14 @@ bool CPasswordInputField::draw(const SRenderData& data) {
|
|||
password.eye.closedAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(password.eye.closedRescourceID);
|
||||
|
||||
int eyeOffset = 0;
|
||||
auto eyeAsset = showPassword ? password.eye.closedAsset : password.eye.openAsset;
|
||||
auto eyeAsset = password.show ? password.eye.closedAsset : password.eye.openAsset;
|
||||
double eyeHeight = (int)(std::nearbyint(configSize.y * password.eye.size * 0.5f) * 2.f);
|
||||
auto eyeSize = Vector2D{eyeHeight, eyeHeight};
|
||||
if (password.allowToggle && !password.eye.hide) {
|
||||
eyeOffset = eyeSize.x + password.eye.margin;
|
||||
}
|
||||
|
||||
if (!showPassword || !password.allowToggle) {
|
||||
if (!password.show || !password.allowToggle) {
|
||||
const int RECTPASSSIZE = std::nearbyint(inputFieldBox.h * password.size * 0.5f) * 2.f;
|
||||
Vector2D passSize{RECTPASSSIZE, RECTPASSSIZE};
|
||||
int passSpacing = std::floor(passSize.x * password.dots.spacing);
|
||||
|
|
@ -610,6 +611,12 @@ void CPasswordInputField::updateColors() {
|
|||
colorState.font = fontTarget;
|
||||
}
|
||||
|
||||
void CPasswordInputField::togglePassword() {
|
||||
password.show = !password.show;
|
||||
|
||||
g_pHyprlock->renderOutput(outputStringPort);
|
||||
}
|
||||
|
||||
CBox CPasswordInputField::getBoundingBoxWl() const {
|
||||
return {
|
||||
Vector2D{pos.x, viewport.y - pos.y - size->value().y},
|
||||
|
|
@ -649,7 +656,7 @@ void CPasswordInputField::onClick(uint32_t button, bool down, const Vector2D& po
|
|||
CBox eyeBox = getEyeBox();
|
||||
|
||||
if (eyeBox.containsPoint(pos)) {
|
||||
g_pHyprlock->togglePasswordShow();
|
||||
togglePassword();
|
||||
|
||||
g_pHyprlock->renderOutput(outputStringPort);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ class CPasswordInputField : public IWidget {
|
|||
|
||||
void renderPasswordUpdate();
|
||||
|
||||
void togglePassword();
|
||||
|
||||
private:
|
||||
AWP<CPasswordInputField> m_self;
|
||||
|
||||
|
|
@ -70,6 +72,7 @@ class CPasswordInputField : public IWidget {
|
|||
bool allowToggle = false;
|
||||
bool center = false;
|
||||
float size = 0.25;
|
||||
bool show = false;
|
||||
|
||||
struct {
|
||||
std::string content = "";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue