demo: handle_input() deadline check #377

This commit is contained in:
nick black 2020-02-23 05:34:45 -05:00
parent 58b67a56af
commit 339185dd6f
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 8 additions and 3 deletions

View File

@ -352,8 +352,8 @@ summary_table(struct ncdirect* nc, const char* spec){
qprefix(nsdelta, GIG, timebuf, 0);
bprefix(totalbytes, 1, totalbuf, 0);
qprefix(totalrenderns, GIG, rtimebuf, 0);
table_segment(nc, "", "══╧═════════════════╪═══════╪═════════╪═════════╪═══╪═══════╪═══════╝\n");
table_printf(nc, "", " %*ss", PREFIXSTRLEN, timebuf);
table_segment(nc, "", "══╧═════════════════╪═══════╪═════════╪═════════╪═══╪═══════╪═══════╝\n");
table_printf(nc, "", " %*ss", PREFIXSTRLEN, timebuf);
table_printf(nc, "", "%7lu", totalframes);
table_printf(nc, "", "%*s", BPREFIXSTRLEN, totalbuf);
table_printf(nc, "", " %*ss", PREFIXSTRLEN, rtimebuf);

View File

@ -223,10 +223,15 @@ handle_input(struct notcurses* nc, struct ncreel* pr, int efd,
wchar_t key = -1;
int pret;
DEMO_RENDER(nc);
int64_t deadlinens = timespec_to_ns(deadline);
do{
struct timespec pollspec, cur;
clock_gettime(CLOCK_MONOTONIC, &cur);
timespec_subtract(&pollspec, deadline, &cur);
int64_t curns = timespec_to_ns(&cur);
if(curns > deadlinens){
return 0;
}
ns_to_timespec(curns - deadlinens, &pollspec);
pret = ppoll(fds, sizeof(fds) / sizeof(*fds), &pollspec, &sset);
if(pret == 0){
return 0;