Skip to content

Commit

Permalink
blank-screens: lerp monitors to 0 before removing
Browse files Browse the repository at this point in the history
  • Loading branch information
XPhyro committed Aug 21, 2024
1 parent 3c68cb5 commit fc952c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 18 additions & 4 deletions src/cpp/project/blank-screens/src/blind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

#include <algorithm>
#include <cassert>
#include <optional>
#include <string>
#include <thread>
#include <vector>

#include <ctype.h>

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<std::string> monitor_expr)
{
const constexpr double epsilon = 0.0001;

static std::vector<std::size_t> 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) {
Expand Down
6 changes: 5 additions & 1 deletion src/cpp/project/blank-screens/src/blind.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef HEADER_SCRIPTS_CXX_BS_BLIND_
#define HEADER_SCRIPTS_CXX_BS_BLIND_

#include <optional>
#include <string>
#include <vector>

#include <X11/extensions/Xrandr.h>

#include "cli.hpp"
Expand All @@ -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<std::string> monitor = std::nullopt);

private:
std::string eval_monitor_expr(const std::string& monitor_expr);
Expand Down

0 comments on commit fc952c7

Please sign in to comment.