From fc952c7fb57ad287c511bfaed1da55e990b27024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berke=20Kocao=C4=9Flu?= Date: Wed, 21 Aug 2024 08:16:19 +0300 Subject: [PATCH] blank-screens: lerp monitors to 0 before removing --- src/cpp/project/blank-screens/src/blind.cpp | 22 +++++++++++++++++---- src/cpp/project/blank-screens/src/blind.hpp | 6 +++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/cpp/project/blank-screens/src/blind.cpp b/src/cpp/project/blank-screens/src/blind.cpp index 8d114cf2..c6cf6980 100644 --- a/src/cpp/project/blank-screens/src/blind.cpp +++ b/src/cpp/project/blank-screens/src/blind.cpp @@ -2,8 +2,10 @@ #include #include +#include #include #include +#include #include @@ -64,6 +66,8 @@ bool bs::blinds::remove_monitor(const std::string& monitor_expr, bool commit_cha if (monitor_it == m_monitors.end()) return false; + lerp_alpha(0.0, monitor); + m_alphas.erase(m_alphas.begin() + (monitor_it - m_monitors.begin())); m_monitors.erase(monitor_it); if (commit_changes) @@ -94,15 +98,25 @@ void bs::blinds::commit_monitor_changes(void) std::cerr << '\n'; } -void bs::blinds::lerp_alpha(double alpha) +void bs::blinds::lerp_alpha(double alpha, std::optional monitor_expr) { const constexpr double epsilon = 0.0001; static std::vector m_lerp_idx; - m_lerp_idx.reserve(m_windows.size()); - for (std::size_t i = 0; i < m_windows.size(); ++i) - m_lerp_idx.push_back(i); + if (monitor_expr) { + const auto& monitor = eval_monitor_expr(*monitor_expr); + const auto& idx = std::find(m_monitors.begin(), m_monitors.end(), monitor); + + if (idx == m_monitors.end()) + return; + + m_lerp_idx.push_back(std::distance(m_monitors.begin(), idx)); + } else { + m_lerp_idx.reserve(m_windows.size()); + for (std::size_t i = 0; i < m_windows.size(); ++i) + m_lerp_idx.push_back(i); + } while (m_lerp_idx.size()) { for (auto it = m_lerp_idx.end() - 1; it >= m_lerp_idx.begin(); --it) { diff --git a/src/cpp/project/blank-screens/src/blind.hpp b/src/cpp/project/blank-screens/src/blind.hpp index b6a8a21c..13fbc80f 100644 --- a/src/cpp/project/blank-screens/src/blind.hpp +++ b/src/cpp/project/blank-screens/src/blind.hpp @@ -1,6 +1,10 @@ #ifndef HEADER_SCRIPTS_CXX_BS_BLIND_ #define HEADER_SCRIPTS_CXX_BS_BLIND_ +#include +#include +#include + #include #include "cli.hpp" @@ -25,7 +29,7 @@ namespace bs { bool remove_monitor(const std::string& monitor_expr, bool commit_changes = true); void toggle_monitor(const std::string& monitor_expr, bool commit_changes = true); void commit_monitor_changes(void); - void lerp_alpha(double alpha); + void lerp_alpha(double alpha, std::optional monitor = std::nullopt); private: std::string eval_monitor_expr(const std::string& monitor_expr);