Skip to content

Commit

Permalink
avoid status bar jumping when memory changes from below 10% to above 10%
Browse files Browse the repository at this point in the history
  • Loading branch information
sandsmark committed Jul 13, 2021
1 parent 2a27b48 commit d5977ba
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <systemd/sd-bus.h>
#include <sys/sysinfo.h>
#include <mntent.h>
#include <cmath>

#include "pulse.h"

Expand Down Expand Up @@ -483,8 +484,8 @@ static void print_mem()
last_used[mem_samples] = used;
memmove(last_used, last_used + 1, sizeof last_used[0] * mem_samples);

double percentage = used * 100.0 / memtotal;
printf("mem: %.0f%%", percentage);
int percentage = std::round(used * 100.0 / memtotal);
printf("mem: %3d%%", percentage);

if (percentage > 80 || used - accum > 1024 * 512) {
print_red();
Expand Down

0 comments on commit d5977ba

Please sign in to comment.