Skip to content

Commit

Permalink
fix interval for a single entry
Browse files Browse the repository at this point in the history
The GCD was actually calculated for at least 2 blocks. With only one
block, the interval was ignored and the default (5) was used.

Fixes #1
  • Loading branch information
vivien committed Feb 11, 2014
1 parent 1b7b2a7 commit 12dcd76
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions status_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
static void
calculate_sleeptime(struct status_line *status)
{
int time = 0;

/* The maximum sleep time is actually the GCD between all block intervals */
int gcd(int a, int b) {
while (b != 0)
Expand All @@ -40,18 +42,18 @@ calculate_sleeptime(struct status_line *status)
return a;
}

status->sleeptime = 5; /* default */

if (status->num >= 2) {
int i, d;
if (status->num > 0) {
time = status->blocks->interval; /* first block's interval */

d = status->blocks->interval; /* first block's interval */
for (i = 0; i < status->num - 1; ++i)
d = gcd(d, (status->blocks + i + 1)->interval);
if (status->num >= 2) {
int i;

if (d > 0)
status->sleeptime = d;
for (i = 1; i < status->num; ++i)
time = gcd(time, (status->blocks + i)->interval);
}
}

status->sleeptime = time > 0 ? time : 5; /* default */
}

static struct block *
Expand Down

0 comments on commit 12dcd76

Please sign in to comment.