From 207e03bf6fd27086d9362a16dfce65c10c8f51ed Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sat, 28 Jan 2017 22:56:05 +0100 Subject: [PATCH] shellwindow: use time_monotonic_ms() --- src/gui/widget/shellwindow.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/gui/widget/shellwindow.cpp b/src/gui/widget/shellwindow.cpp index 78fa6d23e..ddd850351 100644 --- a/src/gui/widget/shellwindow.cpp +++ b/src/gui/widget/shellwindow.cpp @@ -7,7 +7,7 @@ Implementation: Copyright (C) 2013 martii gitorious.org/neutrino-mp/martiis-neutrino-mp - Copyright (C) 2015 Stefan Seyfried + Copyright (C) 2015-2017 Stefan Seyfried License: GPL @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -103,22 +104,19 @@ void CShellWindow::exec() fds.events = POLLIN | POLLHUP | POLLERR; fcntl(fds.fd, F_SETFL, fcntl(fds.fd, F_GETFL, 0) | O_NONBLOCK); - struct timeval tv; - gettimeofday(&tv,NULL); - uint64_t lastPaint = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); + time_t lastPaint = time_monotonic_ms(); bool ok = true, nlseen = false, dirty = false, incomplete = false; char output[1024]; std::string txt = ""; std::string line = ""; do { - uint64_t now; + time_t now; fds.revents = 0; int r = poll(&fds, 1, 300); if (r > 0) { if (!feof(f)) { - gettimeofday(&tv,NULL); - now = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); + now = time_monotonic_ms(); unsigned int lines_read = 0; while (fgets(output, sizeof(output), f)) { @@ -178,7 +176,7 @@ void CShellWindow::exec() first = false; txt += *it; } - if (((lines_read == lines_max) && (lastPaint + 100000 < now)) || (lastPaint + 250000 < now)) { + if (((lines_read >= lines_max) && (lastPaint + 100 < now)) || (lastPaint + 250 < now)) { textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); if (!textBox->isPainted()) if (mode & VERBOSE) textBox->paint(); @@ -192,9 +190,8 @@ void CShellWindow::exec() } else if (r < 0) ok = false; - gettimeofday(&tv,NULL); - now = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); - if (!ok || (r < 1 && dirty && lastPaint + 250000 < now)) { + now = time_monotonic_ms(); + if (!ok || (r < 1 && dirty && lastPaint + 250 < now)) { textBox->setText(&txt, textBox->getWindowsPos().iWidth, false); if (!textBox->isPainted()) if (mode & VERBOSE) textBox->paint();