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

Input fade out timeout v2 #139

Closed
Closed
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
1 change: 1 addition & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void CConfigManager::init() {
m_config.addConfigValue("general:hide_cursor", Hyprlang::INT{0});
m_config.addConfigValue("general:grace", Hyprlang::INT{0});
m_config.addConfigValue("general:no_fade_in", Hyprlang::INT{0});
m_config.addConfigValue("general:input_empty_fade_timeout", Hyprlang::INT{1000});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't this in the input-field cat?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk because i used it in CHyprlock
wanted to change that anyways


m_config.addSpecialCategory("background", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
m_config.addSpecialConfigValue("background", "monitor", Hyprlang::STRING{""});
Expand Down
29 changes: 26 additions & 3 deletions src/core/hyprlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ CHyprlock::CHyprlock(const std::string& wlDisplay) {
if (!m_pXKBContext)
Debug::log(ERR, "Failed to create xkb context");

const auto GRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace");
m_tGraceEnds = **GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**GRACE) : std::chrono::system_clock::from_time_t(0);
const auto GRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace");
m_tGraceEnds = **GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**GRACE) : std::chrono::system_clock::from_time_t(0);
const auto FADETIMEOUT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:input_empty_fade_timeout");
m_iEmptyPasswordTimeoutMs = **FADETIMEOUT;
}

// wl_seat
Expand Down Expand Up @@ -654,6 +656,14 @@ static const ext_session_lock_v1_listener sessionLockListener = {

// end session_lock

static void passwordEmptyTimerCallback(std::shared_ptr<CTimer> self, void* data) {
g_pRenderer->onEmptyPasswordFade();

for (auto& o : g_pHyprlock->m_vOutputs) {
o->sessionLockSurface->render();
}
}

void CHyprlock::onPasswordCheckTimer() {
// check result
if (m_sPasswordState.result->success) {
Expand All @@ -669,6 +679,12 @@ void CHyprlock::onPasswordCheckTimer() {
}

m_sPasswordState.result.reset();

if (m_sPasswordState.emptyBufferTimer.get()) {
m_sPasswordState.emptyBufferTimer->cancel();
m_sPasswordState.emptyBufferTimer.reset();
}
m_sPasswordState.emptyBufferTimer = addTimer(std::chrono::milliseconds(m_iEmptyPasswordTimeoutMs), passwordEmptyTimerCallback, nullptr);
}

bool CHyprlock::passwordCheckWaiting() {
Expand Down Expand Up @@ -730,6 +746,13 @@ void CHyprlock::onKey(uint32_t key, bool down) {
m_sPasswordState.passBuffer += std::string{buf, len - 1};
}

if (m_sPasswordState.passBuffer.empty() && !m_sPasswordState.emptyBufferTimer.get())
m_sPasswordState.emptyBufferTimer = addTimer(std::chrono::milliseconds(m_iEmptyPasswordTimeoutMs), passwordEmptyTimerCallback, nullptr);
else if (!m_sPasswordState.passBuffer.empty() && m_sPasswordState.emptyBufferTimer.get()) {
m_sPasswordState.emptyBufferTimer->cancel();
m_sPasswordState.emptyBufferTimer.reset();
}

for (auto& o : m_vOutputs) {
o->sessionLockSurface->render();
}
Expand Down Expand Up @@ -920,4 +943,4 @@ void CHyprlock::attemptRestoreOnDeath() {

spawnSync("hyprctl keyword misc:allow_session_lock_restore true");
spawnAsync("sleep 2 && hyprlock & disown");
}
}
4 changes: 3 additions & 1 deletion src/core/hyprlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class CHyprlock {

//
std::chrono::system_clock::time_point m_tGraceEnds;
Vector2D m_vLastEnterCoords = {};
Vector2D m_vLastEnterCoords = {};
uint64_t m_iEmptyPasswordTimeoutMs = 0;

std::vector<std::unique_ptr<COutput>> m_vOutputs;

Expand Down Expand Up @@ -117,6 +118,7 @@ class CHyprlock {
std::string passBuffer = "";
std::shared_ptr<CPassword::SVerificationResult> result;
std::optional<std::string> lastFailReason;
std::shared_ptr<CTimer> emptyBufferTimer;
} m_sPasswordState;

struct {
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,11 @@ void CRenderer::popFb() {
boundFBs.pop_back();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, boundFBs.empty() ? 0 : boundFBs.back());
}

void CRenderer::onEmptyPasswordFade() {
for (auto& [surf, w] : widgets) {
for (auto& widget : w) {
widget->onEmptyPasswordTimer();
}
}
}
1 change: 1 addition & 0 deletions src/renderer/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CRenderer {
void renderRect(const CBox& box, const CColor& col, int rounding = 0);
void renderTexture(const CBox& box, const CTexture& tex, float a = 1.0, int rounding = 0, std::optional<wl_output_transform> tr = {});
void blurFB(const CFramebuffer& outfb, SBlurParams params);
void onEmptyPasswordFade();

std::unique_ptr<CAsyncResourceGatherer> asyncResourceGatherer;
std::chrono::system_clock::time_point gatheredAt;
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/widgets/IWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class IWidget {

virtual bool draw(const SRenderData& data) = 0;

virtual void onEmptyPasswordTimer(){};

virtual Vector2D posFromHVAlign(const Vector2D& viewport, const Vector2D& size, const Vector2D& offset, const std::string& halign, const std::string& valign);

struct SFormatResult {
Expand Down
22 changes: 11 additions & 11 deletions src/renderer/widgets/PasswordInputField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ CPasswordInputField::CPasswordInputField(const Vector2D& viewport_, const std::u
}
}

void CPasswordInputField::onEmptyPasswordTimer() {
fade.allowFadeOut = true;
}

void CPasswordInputField::updateFade() {
const auto PASSLEN = g_pHyprlock->getPasswordBufferLen();

Expand All @@ -45,11 +49,12 @@ void CPasswordInputField::updateFade() {
return;
}

if (PASSLEN == 0 && fade.a != 0.0 && (!fade.animated || fade.appearing)) {
fade.a = 1.0;
fade.animated = true;
fade.appearing = false;
fade.start = std::chrono::system_clock::now();
if (PASSLEN == 0 && fade.a != 0.0 && fade.allowFadeOut && (!fade.animated || fade.appearing)) {
fade.a = 1.0;
fade.animated = true;
fade.appearing = false;
fade.start = std::chrono::system_clock::now();
fade.allowFadeOut = false;
} else if (PASSLEN > 0 && fade.a != 1.0 && (!fade.animated || !fade.appearing)) {
fade.a = 0.0;
fade.animated = true;
Expand Down Expand Up @@ -79,11 +84,6 @@ void CPasswordInputField::updateDots() {
dots.lastFrame = std::chrono::system_clock::now();
}

if (PASSLEN == 0 && !placeholder.failID.empty()) {
dots.currentAmount = PASSLEN;
return;
}

const auto DELTA = std::clamp((int)std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - dots.lastFrame).count(), 0, 20000);

const float TOADD = DELTA / 1000000.0 * dots.speedPerSecond;
Expand Down Expand Up @@ -216,7 +216,7 @@ bool CPasswordInputField::draw(const SRenderData& data) {
forceReload = true;
}

return dots.currentAmount != PASSLEN || data.opacity < 1.0 || forceReload;
return dots.currentAmount != PASSLEN || fade.animated || data.opacity < 1.0 || forceReload;
}

void CPasswordInputField::updateFailTex() {
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/widgets/PasswordInputField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CPasswordInputField : public IWidget {
CPasswordInputField(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props);

virtual bool draw(const SRenderData& data);
virtual void onEmptyPasswordTimer();

private:
void updateDots();
Expand Down Expand Up @@ -45,9 +46,10 @@ class CPasswordInputField : public IWidget {

struct {
std::chrono::system_clock::time_point start;
float a = 0;
bool appearing = true;
bool animated = false;
float a = 0;
bool appearing = true;
bool animated = false;
bool allowFadeOut = false;
} fade;

struct {
Expand Down
Loading