From 39c73a82347d3a269f9d554a3d66fe2ea3d3acff Mon Sep 17 00:00:00 2001 From: Quan Date: Wed, 2 Dec 2020 21:55:13 +0700 Subject: [PATCH] feat: Warn state for cpu, memory, fs, battery modules (#2199) * [Temperature, Ramp] fix wrong icon for temperatures near base and warn temps * [Temperature, Ramp] fix wrong icon for temperatures near base and warn temps * Fix minor error * Added WARN state for cpu module * Implement WARN state for CPU, Memory modules, working on fs module * Implement WARN state for fs module * Simplify WARN state implementation for cpu and memory * explicitly check percentage in get_by_percentage_with_borders * Fixed silly error * implement warn state on battery module, standardize the implementation on other modules * minor fixes * fix annoying error * use more intuitive param name * Fix percentage with borders bug * Make requested changes Hide the effect of warn states when unused * Backward Compat: use no format instead of fallback label * Reformat * Refactor * Reformat * Reformat: convert tabs to spaces * Reformat --- include/components/bar.hpp | 2 +- include/drawtypes/ramp.hpp | 3 +- include/modules/battery.hpp | 7 +++ include/modules/cpu.hpp | 9 +++- include/modules/fs.hpp | 4 ++ include/modules/memory.hpp | 7 ++- include/modules/meta/base.hpp | 4 ++ include/modules/temperature.hpp | 2 - src/drawtypes/ramp.cpp | 11 +++-- src/modules/battery.cpp | 54 ++++++++++++++------- src/modules/cpu.cpp | 48 ++++++++++++++----- src/modules/fs.cpp | 56 +++++++++++++++------- src/modules/memory.cpp | 73 +++++++++++++++++++---------- src/modules/meta/base.cpp | 24 +++++++--- src/modules/temperature.cpp | 3 +- tests/CMakeLists.txt | 1 + tests/unit_tests/drawtypes/ramp.cpp | 25 ++++++++++ 17 files changed, 245 insertions(+), 88 deletions(-) create mode 100644 tests/unit_tests/drawtypes/ramp.cpp diff --git a/include/components/bar.hpp b/include/components/bar.hpp index 1851bde2..e8c3aafa 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -55,7 +55,7 @@ class bar : public xpp::event::sink { + > { public: using make_type = unique_ptr; static make_type make(bool only_initialize_values = false); diff --git a/include/drawtypes/ramp.hpp b/include/drawtypes/ramp.hpp index fb94c190..f2ba0974 100644 --- a/include/drawtypes/ramp.hpp +++ b/include/drawtypes/ramp.hpp @@ -16,7 +16,8 @@ namespace drawtypes { void add(label_t&& icon); label_t get(size_t index); label_t get_by_percentage(float percentage); - label_t get_by_percentage_with_borders(float percentage); + label_t get_by_percentage_with_borders(float percentage, float min, float max); + label_t get_by_percentage_with_borders(int percentage, int min, int max); operator bool(); protected: diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index 07fba087..583a6de1 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -12,6 +12,7 @@ namespace modules { NONE = 0, CHARGING, DISCHARGING, + LOW, FULL, }; @@ -68,14 +69,17 @@ namespace modules { static constexpr const char* FORMAT_CHARGING{"format-charging"}; static constexpr const char* FORMAT_DISCHARGING{"format-discharging"}; static constexpr const char* FORMAT_FULL{"format-full"}; + static constexpr const char* FORMAT_LOW{"format-low"}; static constexpr const char* TAG_ANIMATION_CHARGING{""}; static constexpr const char* TAG_ANIMATION_DISCHARGING{""}; + static constexpr const char* TAG_ANIMATION_LOW{""}; static constexpr const char* TAG_BAR_CAPACITY{""}; static constexpr const char* TAG_RAMP_CAPACITY{""}; static constexpr const char* TAG_LABEL_CHARGING{""}; static constexpr const char* TAG_LABEL_DISCHARGING{""}; static constexpr const char* TAG_LABEL_FULL{""}; + static constexpr const char* TAG_LABEL_LOW{""}; static const size_t SKIP_N_UNCHANGED{3_z}; @@ -87,8 +91,10 @@ namespace modules { label_t m_label_charging; label_t m_label_discharging; label_t m_label_full; + label_t m_label_low; animation_t m_animation_charging; animation_t m_animation_discharging; + animation_t m_animation_low; progressbar_t m_bar_capacity; ramp_t m_ramp_capacity; @@ -102,6 +108,7 @@ namespace modules { int m_percentage{0}; int m_fullat{100}; + int m_lowat{10}; string m_timeformat; size_t m_unchanged{SKIP_N_UNCHANGED}; chrono::duration m_interval{}; diff --git a/include/modules/cpu.hpp b/include/modules/cpu.hpp index 003c9fb2..26d7e165 100644 --- a/include/modules/cpu.hpp +++ b/include/modules/cpu.hpp @@ -6,6 +6,7 @@ POLYBAR_NS namespace modules { + enum class cpu_state { NORMAL = 0, WARN }; struct cpu_time { unsigned long long user; unsigned long long nice; @@ -22,6 +23,7 @@ namespace modules { explicit cpu_module(const bar_settings&, string); bool update(); + string get_format() const; bool build(builder* builder, const string& tag) const; static constexpr auto TYPE = "internal/cpu"; @@ -32,19 +34,24 @@ namespace modules { private: static constexpr auto TAG_LABEL = "