From 5ba33f846129f3e6c0505b19f94634b24505e828 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 26 Apr 2026 15:16:36 +0100 Subject: config/lua: init lua config manager, use lua if available (#13817) Adds a new lua config manager, which will automatically be used if there is a lua config present. --- src/notification/Notification.cpp | 90 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/notification/Notification.cpp (limited to 'src/notification/Notification.cpp') diff --git a/src/notification/Notification.cpp b/src/notification/Notification.cpp new file mode 100644 index 00000000..be5b3ca4 --- /dev/null +++ b/src/notification/Notification.cpp @@ -0,0 +1,90 @@ +#include "Notification.hpp" +#include "../debug/log/Logger.hpp" + +using namespace Notification; + +CNotification::CNotification(std::string&& text, float timeout, CHyprColor color, eIcons icon, float fontSize) : + m_createdAt(Time::steadyNow()), m_text(std::move(text)), m_color(color == CHyprColor(0) ? ICONS_COLORS[icon] : color), m_icon(icon), m_fontSize(fontSize), + m_timeMs(std::max(timeout, 1.F)) { + ; +} + +void CNotification::setText(std::string&& text) { + m_cache.textTex.reset(); + m_text = std::move(text); +} + +void CNotification::setColor(CHyprColor color) { + m_color = color; +} + +void CNotification::setIcon(eIcons icon) { + m_cache.iconTex.reset(); + m_icon = icon; +} + +void CNotification::setFontSize(float fontSize) { + m_cache = {}; + m_fontSize = fontSize; +} + +void CNotification::resetTimeout(float timeMs) { + m_timeMs = timeMs; + m_startedAt = Time::steadyNow(); +} + +const std::string& CNotification::text() const { + return m_text; +} + +const CHyprColor& CNotification::color() const { + return m_color; +} + +eIcons CNotification::icon() const { + return m_icon; +} + +float CNotification::fontSize() const { + return m_fontSize; +} + +float CNotification::timeMs() const { + return m_timeMs; +} + +float CNotification::timeElapsedSinceCreationMs() const { + return std::chrono::duration_cast(Time::steadyNow() - m_createdAt).count(); +} + +float CNotification::timeElapsedMs() const { + if (isLocked()) + return m_lastPauseElapsed; + return std::chrono::duration_cast(Time::steadyNow() - m_startedAt).count(); +} + +bool CNotification::isLocked() const { + return m_pauseLocks > 0; +} + +void CNotification::lock() { + m_pauseLocks++; + if (m_pauseLocks == 1) + m_lastPauseElapsed = timeElapsedMs(); +} + +void CNotification::unlock() { + if (m_pauseLocks == 0) { + Log::logger->log(Log::ERR, "CNotification: BUG THIS: unlock on 0 locks??"); + return; + } + + m_pauseLocks--; + + if (m_pauseLocks == 0) + m_startedAt = Time::steadyNow() - std::chrono::milliseconds(sc(m_lastPauseElapsed)); +} + +bool CNotification::gone() const { + return !isLocked() && Time::steadyNow() > m_startedAt + std::chrono::milliseconds(sc(m_timeMs)); +} -- cgit v1.2.3