From 006e91063c9c13517fb96e0bd99993069c8c257b Mon Sep 17 00:00:00 2001 From: Inqiyad Sabr Date: Wed, 19 Nov 2025 11:52:55 +0600 Subject: [Feature] To only show CPU usage if > 50% --- cpu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'cpu.c') diff --git a/cpu.c b/cpu.c index dff7693..0576457 100644 --- a/cpu.c +++ b/cpu.c @@ -5,13 +5,15 @@ #define BG0 "#acae3299" #define BG1 "#ea544399" FILE *proc_stat; -int cpu_delay = 6, cpu_stat[8]; +int cpu_delay_val = 15, + cpu_delay = 15, + cpu_stat[8]; char cpu_str[12]; int total, idle; double cpu_usage_p; void cpu(void) { - if (cpu_delay++ < 6) goto show_stat; + if (cpu_delay++ < cpu_delay_val) goto show_stat; else cpu_delay = 0; int prev_idle, prev_total; char buf[64]; @@ -33,8 +35,9 @@ void cpu(void) cpu_usage_p = total - prev_total; cpu_usage_p *= 100; cpu_usage_p /= ((float)idle + total) - (prev_idle + prev_total); + if (cpu_usage_p > 40) cpu_delay_val = 1; + else cpu_delay_val = 15; snprintf(cpu_str,12,ICON_CPU"%02.02f%%",cpu_usage_p); show_stat: - if (cpu_usage_p < 60) block(cpu_str,FG,BG0,BG0); - else block(cpu_str,FG,BG1,BG1); + if (cpu_delay_val == 1) block(cpu_str,FG,BG1,BG1); } -- cgit v1.2.3