Skip to content

Commit 7a5b097

Browse files
committed
fix(display): fix bug where sync prevents pane flip
The issue was that tv_nsec represents the fractional component of the duration so if we hit the next second, the delta was negative and/or weird.
1 parent bc2470d commit 7a5b097

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

display/threads/ui.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <unistd.h>
1818

1919
#define MAX_PANES 1024
20+
#define PANE_DELAY 1000
2021

2122
struct pane {
2223
char *name;
@@ -165,7 +166,7 @@ static void *rotate_panes(void *arg)
165166
fds[1].fd = ctx->sync_fd_rx;
166167
fds[1].events = POLLIN;
167168

168-
int sleep_time = 1000;
169+
int sleep_time = PANE_DELAY;
169170

170171
size_t idx_increment = 1;
171172

@@ -203,14 +204,18 @@ static void *rotate_panes(void *arg)
203204
}
204205

205206
clock_gettime(CLOCK_MONOTONIC_RAW, &b);
206-
int delta = (b.tv_nsec / 1000 / 1000) -
207+
int delta = (b.tv_sec - a.tv_sec) * 1000 +
208+
(b.tv_nsec / 1000 / 1000) -
207209
(a.tv_nsec / 1000 / 1000);
208210

209211
sleep_time -= delta;
210-
continue;
212+
if (sleep_time < 0) {
213+
sleep_time = PANE_DELAY;
214+
idx_increment = 1;
215+
}
211216
} else {
212217
idx_increment = 1;
213-
sleep_time = 1000;
218+
sleep_time = PANE_DELAY;
214219
}
215220
}
216221

0 commit comments

Comments
 (0)