From 7b4b5e55a27ffbb748c63f2ebecab7d1629f7250 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Mon, 23 Aug 2021 07:30:07 +0200 Subject: [PATCH] support format-icon for cpu und memory --- man/waybar-cpu.5.scd | 5 +++++ man/waybar-memory.5.scd | 5 +++++ src/modules/cpu/common.cpp | 2 ++ src/modules/memory/common.cpp | 2 ++ 4 files changed, 14 insertions(+) diff --git a/man/waybar-cpu.5.scd b/man/waybar-cpu.5.scd index fbf6206f..679ca2ce 100644 --- a/man/waybar-cpu.5.scd +++ b/man/waybar-cpu.5.scd @@ -20,6 +20,11 @@ The *cpu* module displays the current cpu utilization. default: {usage}% ++ The format, how information should be displayed. On {} data gets inserted. +*format-icons*: ++ + typeof: array/object ++ + Based on the current usage, the corresponding icon gets selected. ++ + The order is *low* to *high*. Or by the state if it is an object. + *max-length*: ++ typeof: integer ++ The maximum length in character the module should display. diff --git a/man/waybar-memory.5.scd b/man/waybar-memory.5.scd index 3ff4c35b..0639c07c 100644 --- a/man/waybar-memory.5.scd +++ b/man/waybar-memory.5.scd @@ -22,6 +22,11 @@ Addressed by *memory* default: {percentage}% ++ The format, how information should be displayed. +*format-icons*: ++ + typeof: array/object ++ + Based on the current percentage, the corresponding icon gets selected. ++ + The order is *low* to *high*. Or by the state if it is an object. + *rotate*: ++ typeof: integer ++ Positive value to rotate the text label. diff --git a/src/modules/cpu/common.cpp b/src/modules/cpu/common.cpp index 2ca74212..767cde92 100644 --- a/src/modules/cpu/common.cpp +++ b/src/modules/cpu/common.cpp @@ -26,9 +26,11 @@ auto waybar::modules::Cpu::update() -> void { event_box_.hide(); } else { event_box_.show(); + auto icons = std::vector{state}; label_.set_markup(fmt::format(format, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage), + fmt::arg("icon", getIcon(cpu_usage, icons)), fmt::arg("max_frequency", max_frequency), fmt::arg("min_frequency", min_frequency), fmt::arg("avg_frequency", avg_frequency))); diff --git a/src/modules/memory/common.cpp b/src/modules/memory/common.cpp index 09ce8e83..31219ed6 100644 --- a/src/modules/memory/common.cpp +++ b/src/modules/memory/common.cpp @@ -38,8 +38,10 @@ auto waybar::modules::Memory::update() -> void { event_box_.hide(); } else { event_box_.show(); + auto icons = std::vector{state}; label_.set_markup(fmt::format(format, used_ram_percentage, + fmt::arg("icon", getIcon(used_ram_percentage, icons)), fmt::arg("total", total_ram_gigabytes), fmt::arg("percentage", used_ram_percentage), fmt::arg("used", used_ram_gigabytes),